]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/targa.c
DV: check coded_width/height instead of width/height.
[ffmpeg] / libavcodec / targa.c
index 57a4fee22bacdd92a257d14a2809efdefececf58..5ddd21bfef58f5ecb7037640b2436208d4afded5 100644 (file)
@@ -55,7 +55,7 @@ static int targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_
         type = *src++;
         count = (type & 0x7F) + 1;
         type &= 0x80;
-        if((x + count > w) && (x + count + 1 > (h - y) * w)){
+        if(x + count > (h - y) * w){
             av_log(avctx, AV_LOG_ERROR, "Packet went out of bounds: position (%i,%i) size %i\n", x, y, count);
             return -1;
         }
@@ -70,7 +70,7 @@ static int targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_
                 *dst = *src;
                 break;
             case 2:
-                *((uint16_t*)dst) = AV_RL16(src);
+                AV_WN16A(dst, AV_RN16A(src));
                 break;
             case 3:
                 dst[0] = src[0];
@@ -78,7 +78,7 @@ static int targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_
                 dst[2] = src[2];
                 break;
             case 4:
-                *((uint32_t*)dst) = AV_RL32(src);
+                AV_WN32A(dst, AV_RN32A(src));
                 break;
             }
             dst += depth;
@@ -106,7 +106,7 @@ static int decode_frame(AVCodecContext *avctx,
     const uint8_t *buf_end = avpkt->data + avpkt->size;
     TargaContext * const s = avctx->priv_data;
     AVFrame *picture = data;
-    AVFrame * const p= (AVFrame*)&s->picture;
+    AVFrame * const p = &s->picture;
     uint8_t *dst;
     int stride;
     int idlen, pal, compr, y, w, h, bpp, flags;
@@ -142,16 +142,14 @@ static int decode_frame(AVCodecContext *avctx,
         avctx->pix_fmt = ((compr & (~TGA_RLE)) == TGA_BW) ? PIX_FMT_GRAY8 : PIX_FMT_PAL8;
         break;
     case 15:
-        avctx->pix_fmt = PIX_FMT_RGB555;
-        break;
     case 16:
-        avctx->pix_fmt = PIX_FMT_RGB555;
+        avctx->pix_fmt = PIX_FMT_RGB555LE;
         break;
     case 24:
         avctx->pix_fmt = PIX_FMT_BGR24;
         break;
     case 32:
-        avctx->pix_fmt = PIX_FMT_RGB32;
+        avctx->pix_fmt = PIX_FMT_BGRA;
         break;
     default:
         av_log(avctx, AV_LOG_ERROR, "Bit depth %i is not supported\n", s->bpp);
@@ -233,18 +231,6 @@ static int decode_frame(AVCodecContext *avctx,
             size_t img_size = s->width * ((s->bpp + 1) >> 3);
             CHECK_BUFFER_SIZE(buf, buf_end, img_size, "image data");
             for(y = 0; y < s->height; y++){
-#if HAVE_BIGENDIAN
-                int x;
-                if((s->bpp + 1) >> 3 == 2){
-                    uint16_t *dst16 = (uint16_t*)dst;
-                    for(x = 0; x < s->width; x++)
-                        dst16[x] = AV_RL16(buf + x * 2);
-                }else if((s->bpp + 1) >> 3 == 4){
-                    uint32_t *dst32 = (uint32_t*)dst;
-                    for(x = 0; x < s->width; x++)
-                        dst32[x] = AV_RL32(buf + x * 4);
-                }else
-#endif
                     memcpy(dst, buf, img_size);
 
                 dst += stride;
@@ -276,7 +262,7 @@ static int decode_frame(AVCodecContext *avctx,
         }
     }
 
-    *picture= *(AVFrame*)&s->picture;
+    *picture   = s->picture;
     *data_size = sizeof(AVPicture);
 
     return avpkt->size;
@@ -285,8 +271,8 @@ static int decode_frame(AVCodecContext *avctx,
 static av_cold int targa_init(AVCodecContext *avctx){
     TargaContext *s = avctx->priv_data;
 
-    avcodec_get_frame_defaults((AVFrame*)&s->picture);
-    avctx->coded_frame= (AVFrame*)&s->picture;
+    avcodec_get_frame_defaults(&s->picture);
+    avctx->coded_frame = &s->picture;
 
     return 0;
 }