[FFmpeg-devel] [PATCH]Simplify some palette calculations

Carl Eugen Hoyos cehoyos at ag.or.at
Sun Nov 13 20:11:57 CET 2011


Hi!

As suggested by Reimar.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/avs.c b/libavcodec/avs.c
index 3ba781c..f4c6baf 100644
--- a/libavcodec/avs.c
+++ b/libavcodec/avs.c
@@ -86,7 +86,7 @@ avs_decode_frame(AVCodecContext * avctx,
             return AVERROR_INVALIDDATA;
         buf += 4;
         for (i=first; i<last; i++, buf+=3) {
-            pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2);
+            pal[i] = AV_RB24(&buf[0]) << 2;
             pal[i] |= 0xFF << 24 | (pal[i] >> 6) & 0x30303;
         }
 
diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c
index 9111d17..b9bc22b 100644
--- a/libavcodec/flicvideo.c
+++ b/libavcodec/flicvideo.c
@@ -150,7 +150,6 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
     int color_packets;
     int color_changes;
     int color_shift;
-    unsigned char r, g, b;
 
     int lines;
     int compressed_lines;
@@ -235,10 +234,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
                     if ((unsigned)palette_ptr >= 256)
                         palette_ptr = 0;
 
-                    r = buf[stream_ptr++] << color_shift;
-                    g = buf[stream_ptr++] << color_shift;
-                    b = buf[stream_ptr++] << color_shift;
-                    entry = 0xFF << 24 | r << 16 | g << 8 | b;
+                    entry = 0xFF << 24 | AV_RB24(&buf[stream_ptr]) << color_shift;
+                    stream_ptr += 3;
                     if (color_shift == 2)
                         entry |= entry >> 6 & 0x30303;
                     if (s->palette[palette_ptr] != entry)
diff --git a/libavcodec/yop.c b/libavcodec/yop.c
index e5333db..ebc9e22 100644
--- a/libavcodec/yop.c
+++ b/libavcodec/yop.c
@@ -218,9 +218,7 @@ static int yop_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     palette      = (uint32_t *)s->frame.data[1];
 
     for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3) {
-        palette[i + firstcolor] = (s->srcptr[0] << 18) |
-                                  (s->srcptr[1] << 10) |
-                                  (s->srcptr[2] << 2);
+        palette[i + firstcolor] = AV_RB24(&s->srcptr[0]) << 2;
         palette[i + firstcolor] |= 0xFF << 24 |
                                    (palette[i + firstcolor] >> 6) & 0x30303;
     }


More information about the ffmpeg-devel mailing list