FFmpeg  4.0
mpegutils.c
Go to the documentation of this file.
1 /*
2  * Mpeg video formats-related defines and utility functions
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdint.h>
22 
23 #include "libavutil/common.h"
24 #include "libavutil/frame.h"
25 #include "libavutil/pixdesc.h"
27 #include "libavutil/avassert.h"
28 
29 #include "avcodec.h"
30 #include "mpegutils.h"
31 
32 static int add_mb(AVMotionVector *mb, uint32_t mb_type,
33  int dst_x, int dst_y,
34  int motion_x, int motion_y, int motion_scale,
35  int direction)
36 {
37  mb->w = IS_8X8(mb_type) || IS_8X16(mb_type) ? 8 : 16;
38  mb->h = IS_8X8(mb_type) || IS_16X8(mb_type) ? 8 : 16;
39  mb->motion_x = motion_x;
40  mb->motion_y = motion_y;
41  mb->motion_scale = motion_scale;
42  mb->dst_x = dst_x;
43  mb->dst_y = dst_y;
44  mb->src_x = dst_x + motion_x / motion_scale;
45  mb->src_y = dst_y + motion_y / motion_scale;
46  mb->source = direction ? 1 : -1;
47  mb->flags = 0; // XXX: does mb_type contain extra information that could be exported here?
48  return 1;
49 }
50 
52  AVFrame *cur, AVFrame *last,
53  int y, int h, int picture_structure,
54  int first_field, int low_delay)
55 {
57  int vshift = desc->log2_chroma_h;
58  const int field_pic = picture_structure != PICT_FRAME;
59  if (field_pic) {
60  h <<= 1;
61  y <<= 1;
62  }
63 
64  h = FFMIN(h, avctx->height - y);
65 
66  if (field_pic && first_field &&
68  return;
69 
70  if (avctx->draw_horiz_band) {
71  AVFrame *src;
73  int i;
74 
75  if (cur->pict_type == AV_PICTURE_TYPE_B || low_delay ||
77  src = cur;
78  else if (last)
79  src = last;
80  else
81  return;
82 
83  if (cur->pict_type == AV_PICTURE_TYPE_B &&
84  picture_structure == PICT_FRAME &&
85  avctx->codec_id != AV_CODEC_ID_SVQ3) {
86  for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
87  offset[i] = 0;
88  } else {
89  offset[0]= y * src->linesize[0];
90  offset[1]=
91  offset[2]= (y >> vshift) * src->linesize[1];
92  for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
93  offset[i] = 0;
94  }
95 
96  emms_c();
97 
98  avctx->draw_horiz_band(avctx, src, offset,
99  y, picture_structure, h);
100  }
101 }
102 
103 void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table,
104  uint32_t *mbtype_table, int8_t *qscale_table, int16_t (*motion_val[2])[2],
105  int *low_delay,
106  int mb_width, int mb_height, int mb_stride, int quarter_sample)
107 {
108  if ((avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) && mbtype_table && motion_val[0]) {
109  const int shift = 1 + quarter_sample;
110  const int scale = 1 << shift;
111  const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_SVQ3 ? 2 : 1;
112  const int mv_stride = (mb_width << mv_sample_log2) +
113  (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
114  int mb_x, mb_y, mbcount = 0;
115 
116  /* size is width * height * 2 * 4 where 2 is for directions and 4 is
117  * for the maximum number of MB (4 MB in case of IS_8x8) */
118  AVMotionVector *mvs = av_malloc_array(mb_width * mb_height, 2 * 4 * sizeof(AVMotionVector));
119  if (!mvs)
120  return;
121 
122  for (mb_y = 0; mb_y < mb_height; mb_y++) {
123  for (mb_x = 0; mb_x < mb_width; mb_x++) {
124  int i, direction, mb_type = mbtype_table[mb_x + mb_y * mb_stride];
125  for (direction = 0; direction < 2; direction++) {
126  if (!USES_LIST(mb_type, direction))
127  continue;
128  if (IS_8X8(mb_type)) {
129  for (i = 0; i < 4; i++) {
130  int sx = mb_x * 16 + 4 + 8 * (i & 1);
131  int sy = mb_y * 16 + 4 + 8 * (i >> 1);
132  int xy = (mb_x * 2 + (i & 1) +
133  (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
134  int mx = motion_val[direction][xy][0];
135  int my = motion_val[direction][xy][1];
136  mbcount += add_mb(mvs + mbcount, mb_type, sx, sy, mx, my, scale, direction);
137  }
138  } else if (IS_16X8(mb_type)) {
139  for (i = 0; i < 2; i++) {
140  int sx = mb_x * 16 + 8;
141  int sy = mb_y * 16 + 4 + 8 * i;
142  int xy = (mb_x * 2 + (mb_y * 2 + i) * mv_stride) << (mv_sample_log2 - 1);
143  int mx = motion_val[direction][xy][0];
144  int my = motion_val[direction][xy][1];
145 
146  if (IS_INTERLACED(mb_type))
147  my *= 2;
148 
149  mbcount += add_mb(mvs + mbcount, mb_type, sx, sy, mx, my, scale, direction);
150  }
151  } else if (IS_8X16(mb_type)) {
152  for (i = 0; i < 2; i++) {
153  int sx = mb_x * 16 + 4 + 8 * i;
154  int sy = mb_y * 16 + 8;
155  int xy = (mb_x * 2 + i + mb_y * 2 * mv_stride) << (mv_sample_log2 - 1);
156  int mx = motion_val[direction][xy][0];
157  int my = motion_val[direction][xy][1];
158 
159  if (IS_INTERLACED(mb_type))
160  my *= 2;
161 
162  mbcount += add_mb(mvs + mbcount, mb_type, sx, sy, mx, my, scale, direction);
163  }
164  } else {
165  int sx = mb_x * 16 + 8;
166  int sy = mb_y * 16 + 8;
167  int xy = (mb_x + mb_y * mv_stride) << mv_sample_log2;
168  int mx = motion_val[direction][xy][0];
169  int my = motion_val[direction][xy][1];
170  mbcount += add_mb(mvs + mbcount, mb_type, sx, sy, mx, my, scale, direction);
171  }
172  }
173  }
174  }
175 
176  if (mbcount) {
177  AVFrameSideData *sd;
178 
179  av_log(avctx, AV_LOG_DEBUG, "Adding %d MVs info to frame %d\n", mbcount, avctx->frame_number);
181  if (!sd) {
182  av_freep(&mvs);
183  return;
184  }
185  memcpy(sd->data, mvs, mbcount * sizeof(AVMotionVector));
186  }
187 
188  av_freep(&mvs);
189  }
190 
191  /* TODO: export all the following to make them accessible for users (and filters) */
192  if (avctx->hwaccel || !mbtype_table)
193  return;
194 
195 
196  if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
197  int x,y;
198 
199  av_log(avctx, AV_LOG_DEBUG, "New frame, type: %c\n",
201  for (y = 0; y < mb_height; y++) {
202  for (x = 0; x < mb_width; x++) {
203  if (avctx->debug & FF_DEBUG_SKIP) {
204  int count = mbskip_table ? mbskip_table[x + y * mb_stride] : 0;
205  if (count > 9)
206  count = 9;
207  av_log(avctx, AV_LOG_DEBUG, "%1d", count);
208  }
209  if (avctx->debug & FF_DEBUG_QP) {
210  av_log(avctx, AV_LOG_DEBUG, "%2d",
211  qscale_table[x + y * mb_stride]);
212  }
213  if (avctx->debug & FF_DEBUG_MB_TYPE) {
214  int mb_type = mbtype_table[x + y * mb_stride];
215  // Type & MV direction
216  if (IS_PCM(mb_type))
217  av_log(avctx, AV_LOG_DEBUG, "P");
218  else if (IS_INTRA(mb_type) && IS_ACPRED(mb_type))
219  av_log(avctx, AV_LOG_DEBUG, "A");
220  else if (IS_INTRA4x4(mb_type))
221  av_log(avctx, AV_LOG_DEBUG, "i");
222  else if (IS_INTRA16x16(mb_type))
223  av_log(avctx, AV_LOG_DEBUG, "I");
224  else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type))
225  av_log(avctx, AV_LOG_DEBUG, "d");
226  else if (IS_DIRECT(mb_type))
227  av_log(avctx, AV_LOG_DEBUG, "D");
228  else if (IS_GMC(mb_type) && IS_SKIP(mb_type))
229  av_log(avctx, AV_LOG_DEBUG, "g");
230  else if (IS_GMC(mb_type))
231  av_log(avctx, AV_LOG_DEBUG, "G");
232  else if (IS_SKIP(mb_type))
233  av_log(avctx, AV_LOG_DEBUG, "S");
234  else if (!USES_LIST(mb_type, 1))
235  av_log(avctx, AV_LOG_DEBUG, ">");
236  else if (!USES_LIST(mb_type, 0))
237  av_log(avctx, AV_LOG_DEBUG, "<");
238  else {
239  av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
240  av_log(avctx, AV_LOG_DEBUG, "X");
241  }
242 
243  // segmentation
244  if (IS_8X8(mb_type))
245  av_log(avctx, AV_LOG_DEBUG, "+");
246  else if (IS_16X8(mb_type))
247  av_log(avctx, AV_LOG_DEBUG, "-");
248  else if (IS_8X16(mb_type))
249  av_log(avctx, AV_LOG_DEBUG, "|");
250  else if (IS_INTRA(mb_type) || IS_16X16(mb_type))
251  av_log(avctx, AV_LOG_DEBUG, " ");
252  else
253  av_log(avctx, AV_LOG_DEBUG, "?");
254 
255 
256  if (IS_INTERLACED(mb_type))
257  av_log(avctx, AV_LOG_DEBUG, "=");
258  else
259  av_log(avctx, AV_LOG_DEBUG, " ");
260  }
261  }
262  av_log(avctx, AV_LOG_DEBUG, "\n");
263  }
264  }
265 
266 #if FF_API_DEBUG_MV
267  if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) ||
268  (avctx->debug_mv)) {
269  int mb_y;
270  int i, ret;
271  int h_chroma_shift, v_chroma_shift, block_height;
272  const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_SVQ3 ? 2 : 1;
273  const int mv_stride = (mb_width << mv_sample_log2) +
274  (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
275 
276  if (low_delay)
277  *low_delay = 0; // needed to see the vectors without trashing the buffers
278 
279  ret = av_pix_fmt_get_chroma_sub_sample (avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
280  if (ret)
281  return ret;
282 
284 
285  pict->opaque = NULL;
286  block_height = 16 >> v_chroma_shift;
287 
288  for (mb_y = 0; mb_y < mb_height; mb_y++) {
289  int mb_x;
290  for (mb_x = 0; mb_x < mb_width; mb_x++) {
291  const int mb_index = mb_x + mb_y * mb_stride;
292  if ((avctx->debug & FF_DEBUG_VIS_QP)) {
293  uint64_t c = (qscale_table[mb_index] * 128 / 31) *
294  0x0101010101010101ULL;
295  int y;
296  for (y = 0; y < block_height; y++) {
297  *(uint64_t *)(pict->data[1] + 8 * mb_x +
298  (block_height * mb_y + y) *
299  pict->linesize[1]) = c;
300  *(uint64_t *)(pict->data[2] + 8 * mb_x +
301  (block_height * mb_y + y) *
302  pict->linesize[2]) = c;
303  }
304  }
305  if ((avctx->debug & FF_DEBUG_VIS_MB_TYPE) &&
306  motion_val[0]) {
307  int mb_type = mbtype_table[mb_index];
308  uint64_t u,v;
309  int y;
310 #define COLOR(theta, r) \
311  u = (int)(128 + r * cos(theta * M_PI / 180)); \
312  v = (int)(128 + r * sin(theta * M_PI / 180));
313 
314 
315  u = v = 128;
316  if (IS_PCM(mb_type)) {
317  COLOR(120, 48)
318  } else if ((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) ||
319  IS_INTRA16x16(mb_type)) {
320  COLOR(30, 48)
321  } else if (IS_INTRA4x4(mb_type)) {
322  COLOR(90, 48)
323  } else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type)) {
324  // COLOR(120, 48)
325  } else if (IS_DIRECT(mb_type)) {
326  COLOR(150, 48)
327  } else if (IS_GMC(mb_type) && IS_SKIP(mb_type)) {
328  COLOR(170, 48)
329  } else if (IS_GMC(mb_type)) {
330  COLOR(190, 48)
331  } else if (IS_SKIP(mb_type)) {
332  // COLOR(180, 48)
333  } else if (!USES_LIST(mb_type, 1)) {
334  COLOR(240, 48)
335  } else if (!USES_LIST(mb_type, 0)) {
336  COLOR(0, 48)
337  } else {
338  av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
339  COLOR(300,48)
340  }
341 
342  u *= 0x0101010101010101ULL;
343  v *= 0x0101010101010101ULL;
344  for (y = 0; y < block_height; y++) {
345  *(uint64_t *)(pict->data[1] + 8 * mb_x +
346  (block_height * mb_y + y) * pict->linesize[1]) = u;
347  *(uint64_t *)(pict->data[2] + 8 * mb_x +
348  (block_height * mb_y + y) * pict->linesize[2]) = v;
349  }
350 
351  // segmentation
352  if (IS_8X8(mb_type) || IS_16X8(mb_type)) {
353  *(uint64_t *)(pict->data[0] + 16 * mb_x + 0 +
354  (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
355  *(uint64_t *)(pict->data[0] + 16 * mb_x + 8 +
356  (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
357  }
358  if (IS_8X8(mb_type) || IS_8X16(mb_type)) {
359  for (y = 0; y < 16; y++)
360  pict->data[0][16 * mb_x + 8 + (16 * mb_y + y) *
361  pict->linesize[0]] ^= 0x80;
362  }
363  if (IS_8X8(mb_type) && mv_sample_log2 >= 2) {
364  int dm = 1 << (mv_sample_log2 - 2);
365  for (i = 0; i < 4; i++) {
366  int sx = mb_x * 16 + 8 * (i & 1);
367  int sy = mb_y * 16 + 8 * (i >> 1);
368  int xy = (mb_x * 2 + (i & 1) +
369  (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
370  // FIXME bidir
371  int32_t *mv = (int32_t *) &motion_val[0][xy];
372  if (mv[0] != mv[dm] ||
373  mv[dm * mv_stride] != mv[dm * (mv_stride + 1)])
374  for (y = 0; y < 8; y++)
375  pict->data[0][sx + 4 + (sy + y) * pict->linesize[0]] ^= 0x80;
376  if (mv[0] != mv[dm * mv_stride] || mv[dm] != mv[dm * (mv_stride + 1)])
377  *(uint64_t *)(pict->data[0] + sx + (sy + 4) *
378  pict->linesize[0]) ^= 0x8080808080808080ULL;
379  }
380  }
381 
382  if (IS_INTERLACED(mb_type) &&
383  avctx->codec->id == AV_CODEC_ID_H264) {
384  // hmm
385  }
386  }
387  if (mbskip_table)
388  mbskip_table[mb_index] = 0;
389  }
390  }
391  }
392 #endif
393 }
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1527
#define AV_NUM_DATA_POINTERS
Definition: frame.h:219
#define SLICE_FLAG_ALLOW_FIELD
allow draw_horiz_band() with field slices (MPEG-2 field pics)
Definition: avcodec.h:1997
static int shift(int a, int b)
Definition: sonic.c:82
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2363
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
#define IS_GMC(a)
Definition: mpegutils.h:85
int16_t src_x
Absolute source position.
Definition: motion_vector.h:38
const char * desc
Definition: nvenc.c:65
void * opaque
for some private data of the user
Definition: frame.h:346
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1727
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2674
#define src
Definition: vp8dsp.c:254
void ff_draw_horiz_band(AVCodecContext *avctx, AVFrame *cur, AVFrame *last, int y, int h, int picture_structure, int first_field, int low_delay)
Draw a horizontal band if supported.
Definition: mpegutils.c:51
attribute_deprecated int8_t * qscale_table
QP table.
Definition: frame.h:539
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, &#39;draw_horiz_band&#39; is called by the libavcodec decoder to draw a horizontal band...
Definition: avcodec.h:1752
#define USES_LIST(a, list)
Definition: mpegutils.h:99
uint8_t
#define mb
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
int16_t dst_x
Absolute destination position.
Definition: motion_vector.h:42
#define emms_c()
Definition: internal.h:55
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:344
Structure to hold side data for an AVFrame.
Definition: frame.h:180
int32_t source
Where the current macroblock comes from; negative value when it comes from the past, positive value when it comes from the future.
Definition: motion_vector.h:30
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:88
#define FF_DEBUG_MB_TYPE
Definition: avcodec.h:2602
#define av_log(a,...)
static int first_field(const struct video_data *s)
Definition: v4l2.c:230
enum AVCodecID id
Definition: avcodec.h:3422
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2391
uint8_t w
Width and height of the block.
Definition: motion_vector.h:34
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
simple assert() macros that are a bit more flexible than ISO C assert().
#define IS_SKIP(a)
Definition: mpegutils.h:81
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
reference-counted frame API
#define IS_16X8(a)
Definition: mpegutils.h:87
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:301
static int add_mb(AVMotionVector *mb, uint32_t mb_type, int dst_x, int dst_y, int motion_x, int motion_y, int motion_scale, int direction)
Definition: mpegutils.c:32
#define FFMIN(a, b)
Definition: common.h:96
#define IS_DIRECT(a)
Definition: mpegutils.h:84
int32_t motion_x
Motion vector src_x = dst_x + motion_x / motion_scale src_y = dst_y + motion_y / motion_scale.
Definition: motion_vector.h:53
int32_t
Motion vectors exported by some codecs (on demand through the export_mvs flag set in the libavcodec A...
Definition: frame.h:96
#define FF_DEBUG_SKIP
Definition: avcodec.h:2611
void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table, uint32_t *mbtype_table, int8_t *qscale_table, int16_t(*motion_val[2])[2], int *low_delay, int mb_width, int mb_height, int mb_stride, int quarter_sample)
Print debugging info for the given picture.
Definition: mpegutils.c:103
#define IS_INTRA16x16(a)
Definition: mpegutils.h:76
static const int8_t mv[256][2]
Definition: 4xm.c:77
#define IS_INTERLACED(a)
Definition: mpegutils.h:83
Libavcodec external API header.
enum AVCodecID codec_id
Definition: avcodec.h:1528
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:249
int debug
debug
Definition: avcodec.h:2598
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
main external API structure.
Definition: avcodec.h:1518
uint8_t * data
Definition: frame.h:182
int slice_flags
slice flags
Definition: avcodec.h:1995
#define IS_16X16(a)
Definition: mpegutils.h:86
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:720
#define IS_8X16(a)
Definition: mpegutils.h:88
int32_t motion_y
Definition: motion_vector.h:53
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:609
#define IS_PCM(a)
Definition: mpegutils.h:77
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
uint16_t motion_scale
Definition: motion_vector.h:54
uint64_t flags
Extra flag information.
Definition: motion_vector.h:47
common internal and external API header
static double c[64]
#define FF_DEBUG_QP
Definition: avcodec.h:2603
Bi-dir predicted.
Definition: avutil.h:276
#define IS_INTRA(x, y)
#define PICT_FRAME
Definition: mpegutils.h:39
#define IS_INTRA4x4(a)
Definition: mpegutils.h:75
#define IS_8X8(a)
Definition: mpegutils.h:89
#define IS_ACPRED(a)
Definition: mpegutils.h:94
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:1605
#define SLICE_FLAG_CODED_ORDER
draw_horiz_band() is called in coded order instead of display
Definition: avcodec.h:1996
#define AV_CODEC_FLAG2_EXPORT_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:933
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2204
#define av_freep(p)
void INT64 INT64 count
Definition: avisynth_c.h:690
#define av_malloc_array(a, b)
int debug_mv
debug motion vectors
Definition: avcodec.h:3128
for(j=16;j >0;--j)
#define COLOR(x)