FFmpeg  2.1.1
qdrw.c
Go to the documentation of this file.
1 /*
2  * QuickDraw (qdrw) codec
3  * Copyright (c) 2004 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Apple QuickDraw codec.
25  */
26 
27 #include "libavutil/common.h"
28 #include "libavutil/intreadwrite.h"
29 #include "avcodec.h"
30 #include "internal.h"
31 
32 static int decode_frame(AVCodecContext *avctx,
33  void *data, int *got_frame,
34  AVPacket *avpkt)
35 {
36  const uint8_t *buf = avpkt->data;
37  const uint8_t *buf_end = avpkt->data + avpkt->size;
38  int buf_size = avpkt->size;
39  AVFrame * const p = data;
40  uint8_t* outdata;
41  int colors;
42  int i, ret;
43  uint32_t *pal;
44  int r, g, b;
45 
46  if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
47  return ret;
49  p->key_frame = 1;
50 
51  outdata = p->data[0];
52 
53  if (buf_end - buf < 0x68 + 4)
54  return AVERROR_INVALIDDATA;
55  buf += 0x68; /* jump to palette */
56  colors = AV_RB32(buf);
57  buf += 4;
58 
59  if (colors < 0 || colors > 256) {
60  av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors);
61  return AVERROR_INVALIDDATA;
62  }
63  if (buf_end - buf < (colors + 1) * 8)
64  return AVERROR_INVALIDDATA;
65 
66  pal = (uint32_t*)p->data[1];
67  for (i = 0; i <= colors; i++) {
68  unsigned int idx;
69  idx = AV_RB16(buf); /* color index */
70  buf += 2;
71 
72  if (idx > 255) {
73  av_log(avctx, AV_LOG_ERROR, "Palette index out of range: %u\n", idx);
74  buf += 6;
75  continue;
76  }
77  r = *buf++;
78  buf++;
79  g = *buf++;
80  buf++;
81  b = *buf++;
82  buf++;
83  pal[idx] = 0xFFU << 24 | r << 16 | g << 8 | b;
84  }
85  p->palette_has_changed = 1;
86 
87  if (buf_end - buf < 18)
88  return AVERROR_INVALIDDATA;
89  buf += 18; /* skip unneeded data */
90  for (i = 0; i < avctx->height; i++) {
91  int size, left, code, pix;
92  const uint8_t *next;
93  uint8_t *out;
94  int tsize = 0;
95 
96  /* decode line */
97  out = outdata;
98  size = AV_RB16(buf); /* size of packed line */
99  buf += 2;
100  if (buf_end - buf < size)
101  return AVERROR_INVALIDDATA;
102 
103  left = size;
104  next = buf + size;
105  while (left > 0) {
106  code = *buf++;
107  if (code & 0x80 ) { /* run */
108  pix = *buf++;
109  if ((out + (257 - code)) > (outdata + p->linesize[0]))
110  break;
111  memset(out, pix, 257 - code);
112  out += 257 - code;
113  tsize += 257 - code;
114  left -= 2;
115  } else { /* copy */
116  if ((out + code) > (outdata + p->linesize[0]))
117  break;
118  if (buf_end - buf < code + 1)
119  return AVERROR_INVALIDDATA;
120  memcpy(out, buf, code + 1);
121  out += code + 1;
122  buf += code + 1;
123  left -= 2 + code;
124  tsize += code + 1;
125  }
126  }
127  buf = next;
128  outdata += p->linesize[0];
129  }
130 
131  *got_frame = 1;
132 
133  return buf_size;
134 }
135 
137 {
138  avctx->pix_fmt= AV_PIX_FMT_PAL8;
139 
140  return 0;
141 }
142 
144  .name = "qdraw",
145  .long_name = NULL_IF_CONFIG_SMALL("Apple QuickDraw"),
146  .type = AVMEDIA_TYPE_VIDEO,
147  .id = AV_CODEC_ID_QDRAW,
148  .init = decode_init,
149  .decode = decode_frame,
150  .capabilities = CODEC_CAP_DR1,
151 };
int size
static av_cold int decode_init(AVCodecContext *avctx)
Definition: qdrw.c:136
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
const char * g
Definition: vf_curves.c:104
int size
Definition: avcodec.h:1064
const char * b
Definition: vf_curves.c:105
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1342
AVCodec.
Definition: avcodec.h:2922
#define av_cold
Definition: avcodec.h:653
#define AV_RB16(x)
Definition: intreadwrite.h:232
uint8_t
AVCodec ff_qdraw_decoder
Definition: qdrw.c:143
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:742
const char data[16]
Definition: mxf.c:68
#define U(x)
Definition: vp56_arith.h:37
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
const char * r
Definition: vf_curves.c:103
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: qdrw.c:32
Libavcodec external API header.
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:167
ret
Definition: avfilter.c:961
main external API structure.
Definition: avcodec.h:1146
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:941
void * buf
Definition: avisynth_c.h:594
uint8_t * data
Definition: avcodec.h:1063
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:303
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
common internal api header.
#define AV_RB32(x)
Definition: intreadwrite.h:258
#define AVERROR_INVALIDDATA
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int key_frame
1 -&gt; keyframe, 0-&gt; not
Definition: frame.h:162
8 bit with PIX_FMT_RGB32 palette
Definition: avcodec.h:4545
This structure stores compressed data.
Definition: avcodec.h:1040
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
for(j=16;j >0;--j)