]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/smc.c
Clarify comment: although still hacky, it is correct for existing libtheora
[ffmpeg] / libavcodec / smc.c
index 349e5f81cb383359470559485a1500e10b1627d1..f63dc1e6ac91304321c6bcbddca69e5b59908838 100644 (file)
  * 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
- *
  */
 
 /**
- * @file smc.c
+ * @file libavcodec/smc.c
  * QT SMC Video Decoder by Mike Melanson (melanson@pcisys.net)
  * For more information about the SMC format, visit:
  *   http://www.pcisys.net/~melanson/codecs/
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 
-#include "common.h"
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
-#include "dsputil.h"
 
 #define CPAIR 2
 #define CQUAD 4
 typedef struct SmcContext {
 
     AVCodecContext *avctx;
-    DSPContext dsp;
     AVFrame frame;
 
-    unsigned char *buf;
+    const unsigned char *buf;
     int size;
 
     /* SMC color tables */
@@ -370,16 +366,11 @@ static void smc_decode_stream(SmcContext *s)
                     flags_a = xx012456, flags_b = xx89A37B
                 */
                 /* build the color flags */
-                color_flags_a = color_flags_b = 0;
                 color_flags_a =
-                    (s->buf[stream_ptr + 0] << 16) |
-                    ((s->buf[stream_ptr + 1] & 0xF0) << 8) |
-                    ((s->buf[stream_ptr + 2] & 0xF0) << 4) |
-                    ((s->buf[stream_ptr + 2] & 0x0F) << 4) |
-                    ((s->buf[stream_ptr + 3] & 0xF0) >> 4);
+                    ((AV_RB16(s->buf + stream_ptr    ) & 0xFFF0) << 8) |
+                     (AV_RB16(s->buf + stream_ptr + 2) >> 4);
                 color_flags_b =
-                    (s->buf[stream_ptr + 4] << 16) |
-                    ((s->buf[stream_ptr + 5] & 0xF0) << 8) |
+                    ((AV_RB16(s->buf + stream_ptr + 4) & 0xFFF0) << 8) |
                     ((s->buf[stream_ptr + 1] & 0x0F) << 8) |
                     ((s->buf[stream_ptr + 3] & 0x0F) << 4) |
                     (s->buf[stream_ptr + 5] & 0x0F);
@@ -430,14 +421,12 @@ static void smc_decode_stream(SmcContext *s)
     }
 }
 
-static int smc_decode_init(AVCodecContext *avctx)
+static av_cold int smc_decode_init(AVCodecContext *avctx)
 {
-    SmcContext *s = (SmcContext *)avctx->priv_data;
+    SmcContext *s = avctx->priv_data;
 
     s->avctx = avctx;
     avctx->pix_fmt = PIX_FMT_PAL8;
-    avctx->has_b_frames = 0;
-    dsputil_init(&s->dsp, avctx);
 
     s->frame.data[0] = NULL;
 
@@ -446,9 +435,11 @@ static int smc_decode_init(AVCodecContext *avctx)
 
 static int smc_decode_frame(AVCodecContext *avctx,
                              void *data, int *data_size,
-                             uint8_t *buf, int buf_size)
+                             AVPacket *avpkt)
 {
-    SmcContext *s = (SmcContext *)avctx->priv_data;
+    const uint8_t *buf = avpkt->data;
+    int buf_size = avpkt->size;
+    SmcContext *s = avctx->priv_data;
 
     s->buf = buf;
     s->size = buf_size;
@@ -470,9 +461,9 @@ static int smc_decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
-static int smc_decode_end(AVCodecContext *avctx)
+static av_cold int smc_decode_end(AVCodecContext *avctx)
 {
-    SmcContext *s = (SmcContext *)avctx->priv_data;
+    SmcContext *s = avctx->priv_data;
 
     if (s->frame.data[0])
         avctx->release_buffer(avctx, &s->frame);
@@ -490,4 +481,5 @@ AVCodec smc_decoder = {
     smc_decode_end,
     smc_decode_frame,
     CODEC_CAP_DR1,
+    .long_name = NULL_IF_CONFIG_SMALL("QuickTime Graphics (SMC)"),
 };