]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/targa.c
Alpha: move dsputil prototypes to a header file
[ffmpeg] / libavcodec / targa.c
index c3d6010d246a3aebbbbe71141a7815a8a7a555c4..b6fe5dfed593ec3b37e2bd587434db2856fb971d 100644 (file)
@@ -17,8 +17,9 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
  */
+
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 enum TargaCompr{
@@ -38,7 +39,7 @@ typedef struct TargaContext {
     int compression_type;
 } TargaContext;
 
-static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp)
+static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp)
 {
     int i, x, y;
     int depth = (bpp + 1) >> 3;
@@ -61,13 +62,16 @@ static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *sr
                 *dst = *src;
                 break;
             case 2:
-                *((uint16_t*)dst) = LE_16(src);
+                *((uint16_t*)dst) = AV_RL16(src);
                 break;
             case 3:
                 dst[0] = src[0];
                 dst[1] = src[1];
                 dst[2] = src[2];
                 break;
+            case 4:
+                *((uint32_t*)dst) = AV_RL32(src);
+                break;
             }
             dst += depth;
             if(!type)
@@ -87,8 +91,10 @@ static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *sr
 
 static int decode_frame(AVCodecContext *avctx,
                         void *data, int *data_size,
-                        uint8_t *buf, int buf_size)
+                        AVPacket *avpkt)
 {
+    const uint8_t *buf = avpkt->data;
+    int buf_size = avpkt->size;
     TargaContext * const s = avctx->priv_data;
     AVFrame *picture = data;
     AVFrame * const p= (AVFrame*)&s->picture;
@@ -101,13 +107,13 @@ static int decode_frame(AVCodecContext *avctx,
     idlen = *buf++;
     pal = *buf++;
     compr = *buf++;
-    first_clr = LE_16(buf); buf += 2;
-    colors = LE_16(buf); buf += 2;
+    first_clr = AV_RL16(buf); buf += 2;
+    colors = AV_RL16(buf); buf += 2;
     csize = *buf++;
-    x = LE_16(buf); buf += 2;
-    y = LE_16(buf); buf += 2;
-    w = LE_16(buf); buf += 2;
-    h = LE_16(buf); buf += 2;
+    x = AV_RL16(buf); buf += 2;
+    y = AV_RL16(buf); buf += 2;
+    w = AV_RL16(buf); buf += 2;
+    h = AV_RL16(buf); buf += 2;
     bpp = *buf++;
     flags = *buf++;
     //skip identifier if any
@@ -128,6 +134,9 @@ static int decode_frame(AVCodecContext *avctx,
     case 24:
         avctx->pix_fmt = PIX_FMT_BGR24;
         break;
+    case 32:
+        avctx->pix_fmt = PIX_FMT_RGB32;
+        break;
     default:
         av_log(avctx, AV_LOG_ERROR, "Bit depth %i is not supported\n", s->bpp);
         return -1;
@@ -180,7 +189,6 @@ static int decode_frame(AVCodecContext *avctx,
                 *pal++ = (b << 16) | (g << 8) | r;
             }
             p->palette_has_changed = 1;
-            avctx->palctrl->palette_changed = 0;
         }
     }
     if((compr & (~TGA_RLE)) == TGA_NODATA)
@@ -190,11 +198,15 @@ static int decode_frame(AVCodecContext *avctx,
             targa_decode_rle(avctx, s, buf, dst, avctx->width, avctx->height, stride, bpp);
         else{
             for(y = 0; y < s->height; y++){
-#ifdef WORDS_BIGENDIAN
+#if HAVE_BIGENDIAN
                 if((s->bpp + 1) >> 3 == 2){
                     uint16_t *dst16 = (uint16_t*)dst;
                     for(x = 0; x < s->width; x++)
-                        dst16[x] = LE_16(buf + x * 2);
+                        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, s->width * ((s->bpp + 1) >> 3));
@@ -211,17 +223,16 @@ static int decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
-static int targa_init(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;
-    s->picture.data[0] = NULL;
 
     return 0;
 }
 
-static int targa_end(AVCodecContext *avctx){
+static av_cold int targa_end(AVCodecContext *avctx){
     TargaContext *s = avctx->priv_data;
 
     if(s->picture.data[0])
@@ -239,6 +250,7 @@ AVCodec targa_decoder = {
     NULL,
     targa_end,
     decode_frame,
-    0,
-    NULL
+    CODEC_CAP_DR1,
+    NULL,
+    .long_name = NULL_IF_CONFIG_SMALL("Truevision Targa image"),
 };