* Quicktime Graphics (SMC) Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ * 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
* 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 */
s->avctx->palctrl->palette_changed = 0;
}
- chunk_size = BE_32(&s->buf[stream_ptr]) & 0x00FFFFFF;
+ chunk_size = AV_RB32(&s->buf[stream_ptr]) & 0x00FFFFFF;
stream_ptr += 4;
if (chunk_size != s->size)
av_log(s->avctx, AV_LOG_INFO, "warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
/* sanity check */
if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) {
- av_log(s->avctx, AV_LOG_INFO, "encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
+ av_log(s->avctx, AV_LOG_INFO, "encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
opcode & 0xF0);
break;
}
color_table_index = CPAIR * s->buf[stream_ptr++];
while (n_blocks--) {
- color_flags = BE_16(&s->buf[stream_ptr]);
+ color_flags = AV_RB16(&s->buf[stream_ptr]);
stream_ptr += 2;
flag_mask = 0x8000;
block_ptr = row_ptr + pixel_ptr;
color_table_index = CQUAD * s->buf[stream_ptr++];
while (n_blocks--) {
- color_flags = BE_32(&s->buf[stream_ptr]);
+ color_flags = AV_RB32(&s->buf[stream_ptr]);
stream_ptr += 4;
/* flag mask actually acts as a bit shift count here */
flag_mask = 30;
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);
}
}
-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;
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;
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);
AVCodec smc_decoder = {
"smc",
- CODEC_TYPE_VIDEO,
+ AVMEDIA_TYPE_VIDEO,
CODEC_ID_SMC,
sizeof(SmcContext),
smc_decode_init,
smc_decode_end,
smc_decode_frame,
CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("QuickTime Graphics (SMC)"),
};