00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include "pixfmt.h"
00025 #include "pixdesc.h"
00026
00027 #include "intreadwrite.h"
00028
00029 void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
00030 const AVPixFmtDescriptor *desc, int x, int y, int c, int w,
00031 int read_pal_component)
00032 {
00033 AVComponentDescriptor comp = desc->comp[c];
00034 int plane = comp.plane;
00035 int depth = comp.depth_minus1 + 1;
00036 int mask = (1 << depth) - 1;
00037 int shift = comp.shift;
00038 int step = comp.step_minus1 + 1;
00039 int flags = desc->flags;
00040
00041 if (flags & PIX_FMT_BITSTREAM) {
00042 int skip = x * step + comp.offset_plus1 - 1;
00043 const uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3);
00044 int shift = 8 - depth - (skip & 7);
00045
00046 while (w--) {
00047 int val = (*p >> shift) & mask;
00048 if (read_pal_component)
00049 val = data[1][4*val + c];
00050 shift -= step;
00051 p -= shift >> 3;
00052 shift &= 7;
00053 *dst++ = val;
00054 }
00055 } else {
00056 const uint8_t *p = data[plane] + y * linesize[plane] + x * step + comp.offset_plus1 - 1;
00057 int is_8bit = shift + depth <= 8;
00058
00059 if (is_8bit)
00060 p += !!(flags & PIX_FMT_BE);
00061
00062 while (w--) {
00063 int val = is_8bit ? *p :
00064 flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
00065 val = (val >> shift) & mask;
00066 if (read_pal_component)
00067 val = data[1][4 * val + c];
00068 p += step;
00069 *dst++ = val;
00070 }
00071 }
00072 }
00073
00074 void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
00075 const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
00076 {
00077 AVComponentDescriptor comp = desc->comp[c];
00078 int plane = comp.plane;
00079 int depth = comp.depth_minus1 + 1;
00080 int step = comp.step_minus1 + 1;
00081 int flags = desc->flags;
00082
00083 if (flags & PIX_FMT_BITSTREAM) {
00084 int skip = x * step + comp.offset_plus1 - 1;
00085 uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3);
00086 int shift = 8 - depth - (skip & 7);
00087
00088 while (w--) {
00089 *p |= *src++ << shift;
00090 shift -= step;
00091 p -= shift >> 3;
00092 shift &= 7;
00093 }
00094 } else {
00095 int shift = comp.shift;
00096 uint8_t *p = data[plane] + y * linesize[plane] + x * step + comp.offset_plus1 - 1;
00097
00098 if (shift + depth <= 8) {
00099 p += !!(flags & PIX_FMT_BE);
00100 while (w--) {
00101 *p |= (*src++ << shift);
00102 p += step;
00103 }
00104 } else {
00105 while (w--) {
00106 if (flags & PIX_FMT_BE) {
00107 uint16_t val = AV_RB16(p) | (*src++ << shift);
00108 AV_WB16(p, val);
00109 } else {
00110 uint16_t val = AV_RL16(p) | (*src++ << shift);
00111 AV_WL16(p, val);
00112 }
00113 p += step;
00114 }
00115 }
00116 }
00117 }
00118
00119 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
00120 [PIX_FMT_YUV420P] = {
00121 .name = "yuv420p",
00122 .nb_components = 3,
00123 .log2_chroma_w = 1,
00124 .log2_chroma_h = 1,
00125 .comp = {
00126 { 0, 0, 1, 0, 7 },
00127 { 1, 0, 1, 0, 7 },
00128 { 2, 0, 1, 0, 7 },
00129 },
00130 .flags = PIX_FMT_PLANAR,
00131 },
00132 [PIX_FMT_YUYV422] = {
00133 .name = "yuyv422",
00134 .nb_components = 3,
00135 .log2_chroma_w = 1,
00136 .log2_chroma_h = 0,
00137 .comp = {
00138 { 0, 1, 1, 0, 7 },
00139 { 0, 3, 2, 0, 7 },
00140 { 0, 3, 4, 0, 7 },
00141 },
00142 },
00143 [PIX_FMT_RGB24] = {
00144 .name = "rgb24",
00145 .nb_components = 3,
00146 .log2_chroma_w = 0,
00147 .log2_chroma_h = 0,
00148 .comp = {
00149 { 0, 2, 1, 0, 7 },
00150 { 0, 2, 2, 0, 7 },
00151 { 0, 2, 3, 0, 7 },
00152 },
00153 .flags = PIX_FMT_RGB,
00154 },
00155 [PIX_FMT_BGR24] = {
00156 .name = "bgr24",
00157 .nb_components = 3,
00158 .log2_chroma_w = 0,
00159 .log2_chroma_h = 0,
00160 .comp = {
00161 { 0, 2, 1, 0, 7 },
00162 { 0, 2, 2, 0, 7 },
00163 { 0, 2, 3, 0, 7 },
00164 },
00165 .flags = PIX_FMT_RGB,
00166 },
00167 [PIX_FMT_YUV422P] = {
00168 .name = "yuv422p",
00169 .nb_components = 3,
00170 .log2_chroma_w = 1,
00171 .log2_chroma_h = 0,
00172 .comp = {
00173 { 0, 0, 1, 0, 7 },
00174 { 1, 0, 1, 0, 7 },
00175 { 2, 0, 1, 0, 7 },
00176 },
00177 .flags = PIX_FMT_PLANAR,
00178 },
00179 [PIX_FMT_YUV444P] = {
00180 .name = "yuv444p",
00181 .nb_components = 3,
00182 .log2_chroma_w = 0,
00183 .log2_chroma_h = 0,
00184 .comp = {
00185 { 0, 0, 1, 0, 7 },
00186 { 1, 0, 1, 0, 7 },
00187 { 2, 0, 1, 0, 7 },
00188 },
00189 .flags = PIX_FMT_PLANAR,
00190 },
00191 [PIX_FMT_YUV410P] = {
00192 .name = "yuv410p",
00193 .nb_components = 3,
00194 .log2_chroma_w = 2,
00195 .log2_chroma_h = 2,
00196 .comp = {
00197 { 0, 0, 1, 0, 7 },
00198 { 1, 0, 1, 0, 7 },
00199 { 2, 0, 1, 0, 7 },
00200 },
00201 .flags = PIX_FMT_PLANAR,
00202 },
00203 [PIX_FMT_YUV411P] = {
00204 .name = "yuv411p",
00205 .nb_components = 3,
00206 .log2_chroma_w = 2,
00207 .log2_chroma_h = 0,
00208 .comp = {
00209 { 0, 0, 1, 0, 7 },
00210 { 1, 0, 1, 0, 7 },
00211 { 2, 0, 1, 0, 7 },
00212 },
00213 .flags = PIX_FMT_PLANAR,
00214 },
00215 [PIX_FMT_GRAY8] = {
00216 .name = "gray",
00217 .nb_components = 1,
00218 .log2_chroma_w = 0,
00219 .log2_chroma_h = 0,
00220 .comp = {
00221 { 0, 0, 1, 0, 7 },
00222 },
00223 },
00224 [PIX_FMT_MONOWHITE] = {
00225 .name = "monow",
00226 .nb_components = 1,
00227 .log2_chroma_w = 0,
00228 .log2_chroma_h = 0,
00229 .comp = {
00230 { 0, 0, 1, 0, 0 },
00231 },
00232 .flags = PIX_FMT_BITSTREAM,
00233 },
00234 [PIX_FMT_MONOBLACK] = {
00235 .name = "monob",
00236 .nb_components = 1,
00237 .log2_chroma_w = 0,
00238 .log2_chroma_h = 0,
00239 .comp = {
00240 { 0, 0, 1, 7, 0 },
00241 },
00242 .flags = PIX_FMT_BITSTREAM,
00243 },
00244 [PIX_FMT_PAL8] = {
00245 .name = "pal8",
00246 .nb_components = 1,
00247 .log2_chroma_w = 0,
00248 .log2_chroma_h = 0,
00249 .comp = {
00250 { 0, 0, 1, 0, 7 },
00251 },
00252 .flags = PIX_FMT_PAL,
00253 },
00254 [PIX_FMT_YUVJ420P] = {
00255 .name = "yuvj420p",
00256 .nb_components = 3,
00257 .log2_chroma_w = 1,
00258 .log2_chroma_h = 1,
00259 .comp = {
00260 { 0, 0, 1, 0, 7 },
00261 { 1, 0, 1, 0, 7 },
00262 { 2, 0, 1, 0, 7 },
00263 },
00264 .flags = PIX_FMT_PLANAR,
00265 },
00266 [PIX_FMT_YUVJ422P] = {
00267 .name = "yuvj422p",
00268 .nb_components = 3,
00269 .log2_chroma_w = 1,
00270 .log2_chroma_h = 0,
00271 .comp = {
00272 { 0, 0, 1, 0, 7 },
00273 { 1, 0, 1, 0, 7 },
00274 { 2, 0, 1, 0, 7 },
00275 },
00276 .flags = PIX_FMT_PLANAR,
00277 },
00278 [PIX_FMT_YUVJ444P] = {
00279 .name = "yuvj444p",
00280 .nb_components = 3,
00281 .log2_chroma_w = 0,
00282 .log2_chroma_h = 0,
00283 .comp = {
00284 { 0, 0, 1, 0, 7 },
00285 { 1, 0, 1, 0, 7 },
00286 { 2, 0, 1, 0, 7 },
00287 },
00288 .flags = PIX_FMT_PLANAR,
00289 },
00290 [PIX_FMT_XVMC_MPEG2_MC] = {
00291 .name = "xvmcmc",
00292 .flags = PIX_FMT_HWACCEL,
00293 },
00294 [PIX_FMT_XVMC_MPEG2_IDCT] = {
00295 .name = "xvmcidct",
00296 .flags = PIX_FMT_HWACCEL,
00297 },
00298 [PIX_FMT_UYVY422] = {
00299 .name = "uyvy422",
00300 .nb_components = 3,
00301 .log2_chroma_w = 1,
00302 .log2_chroma_h = 0,
00303 .comp = {
00304 { 0, 1, 2, 0, 7 },
00305 { 0, 3, 1, 0, 7 },
00306 { 0, 3, 3, 0, 7 },
00307 },
00308 },
00309 [PIX_FMT_UYYVYY411] = {
00310 .name = "uyyvyy411",
00311 .nb_components = 3,
00312 .log2_chroma_w = 2,
00313 .log2_chroma_h = 0,
00314 .comp = {
00315 { 0, 3, 2, 0, 7 },
00316 { 0, 5, 1, 0, 7 },
00317 { 0, 5, 4, 0, 7 },
00318 },
00319 },
00320 [PIX_FMT_BGR8] = {
00321 .name = "bgr8",
00322 .nb_components = 3,
00323 .log2_chroma_w = 0,
00324 .log2_chroma_h = 0,
00325 .comp = {
00326 { 0, 0, 1, 6, 1 },
00327 { 0, 0, 1, 3, 2 },
00328 { 0, 0, 1, 0, 2 },
00329 },
00330 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
00331 },
00332 [PIX_FMT_BGR4] = {
00333 .name = "bgr4",
00334 .nb_components = 3,
00335 .log2_chroma_w = 0,
00336 .log2_chroma_h = 0,
00337 .comp = {
00338 { 0, 3, 1, 0, 0 },
00339 { 0, 3, 2, 0, 1 },
00340 { 0, 3, 4, 0, 0 },
00341 },
00342 .flags = PIX_FMT_BITSTREAM | PIX_FMT_RGB,
00343 },
00344 [PIX_FMT_BGR4_BYTE] = {
00345 .name = "bgr4_byte",
00346 .nb_components = 3,
00347 .log2_chroma_w = 0,
00348 .log2_chroma_h = 0,
00349 .comp = {
00350 { 0, 0, 1, 3, 0 },
00351 { 0, 0, 1, 1, 1 },
00352 { 0, 0, 1, 0, 0 },
00353 },
00354 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
00355 },
00356 [PIX_FMT_RGB8] = {
00357 .name = "rgb8",
00358 .nb_components = 3,
00359 .log2_chroma_w = 0,
00360 .log2_chroma_h = 0,
00361 .comp = {
00362 { 0, 0, 1, 6, 1 },
00363 { 0, 0, 1, 3, 2 },
00364 { 0, 0, 1, 0, 2 },
00365 },
00366 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
00367 },
00368 [PIX_FMT_RGB4] = {
00369 .name = "rgb4",
00370 .nb_components = 3,
00371 .log2_chroma_w = 0,
00372 .log2_chroma_h = 0,
00373 .comp = {
00374 { 0, 3, 1, 0, 0 },
00375 { 0, 3, 2, 0, 1 },
00376 { 0, 3, 4, 0, 0 },
00377 },
00378 .flags = PIX_FMT_BITSTREAM | PIX_FMT_RGB,
00379 },
00380 [PIX_FMT_RGB4_BYTE] = {
00381 .name = "rgb4_byte",
00382 .nb_components = 3,
00383 .log2_chroma_w = 0,
00384 .log2_chroma_h = 0,
00385 .comp = {
00386 { 0, 0, 1, 3, 0 },
00387 { 0, 0, 1, 1, 1 },
00388 { 0, 0, 1, 0, 0 },
00389 },
00390 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
00391 },
00392 [PIX_FMT_NV12] = {
00393 .name = "nv12",
00394 .nb_components = 3,
00395 .log2_chroma_w = 1,
00396 .log2_chroma_h = 1,
00397 .comp = {
00398 { 0, 0, 1, 0, 7 },
00399 { 1, 1, 1, 0, 7 },
00400 { 1, 1, 2, 0, 7 },
00401 },
00402 .flags = PIX_FMT_PLANAR,
00403 },
00404 [PIX_FMT_NV21] = {
00405 .name = "nv21",
00406 .nb_components = 3,
00407 .log2_chroma_w = 1,
00408 .log2_chroma_h = 1,
00409 .comp = {
00410 { 0, 0, 1, 0, 7 },
00411 { 1, 1, 1, 0, 7 },
00412 { 1, 1, 2, 0, 7 },
00413 },
00414 .flags = PIX_FMT_PLANAR,
00415 },
00416 [PIX_FMT_ARGB] = {
00417 .name = "argb",
00418 .nb_components = 4,
00419 .log2_chroma_w = 0,
00420 .log2_chroma_h = 0,
00421 .comp = {
00422 { 0, 3, 1, 0, 7 },
00423 { 0, 3, 2, 0, 7 },
00424 { 0, 3, 3, 0, 7 },
00425 { 0, 3, 4, 0, 7 },
00426 },
00427 .flags = PIX_FMT_RGB,
00428 },
00429 [PIX_FMT_RGBA] = {
00430 .name = "rgba",
00431 .nb_components = 4,
00432 .log2_chroma_w = 0,
00433 .log2_chroma_h = 0,
00434 .comp = {
00435 { 0, 3, 1, 0, 7 },
00436 { 0, 3, 2, 0, 7 },
00437 { 0, 3, 3, 0, 7 },
00438 { 0, 3, 4, 0, 7 },
00439 },
00440 .flags = PIX_FMT_RGB,
00441 },
00442 [PIX_FMT_ABGR] = {
00443 .name = "abgr",
00444 .nb_components = 4,
00445 .log2_chroma_w = 0,
00446 .log2_chroma_h = 0,
00447 .comp = {
00448 { 0, 3, 1, 0, 7 },
00449 { 0, 3, 2, 0, 7 },
00450 { 0, 3, 3, 0, 7 },
00451 { 0, 3, 4, 0, 7 },
00452 },
00453 .flags = PIX_FMT_RGB,
00454 },
00455 [PIX_FMT_BGRA] = {
00456 .name = "bgra",
00457 .nb_components = 4,
00458 .log2_chroma_w = 0,
00459 .log2_chroma_h = 0,
00460 .comp = {
00461 { 0, 3, 1, 0, 7 },
00462 { 0, 3, 2, 0, 7 },
00463 { 0, 3, 3, 0, 7 },
00464 { 0, 3, 4, 0, 7 },
00465 },
00466 .flags = PIX_FMT_RGB,
00467 },
00468 [PIX_FMT_0RGB] = {
00469 .name = "0rgb",
00470 .nb_components= 3,
00471 .log2_chroma_w= 0,
00472 .log2_chroma_h= 0,
00473 .comp = {
00474 { 0, 3, 2, 0, 7 },
00475 { 0, 3, 3, 0, 7 },
00476 { 0, 3, 4, 0, 7 },
00477 },
00478 .flags = PIX_FMT_RGB,
00479 },
00480 [PIX_FMT_RGB0] = {
00481 .name = "rgb0",
00482 .nb_components= 3,
00483 .log2_chroma_w= 0,
00484 .log2_chroma_h= 0,
00485 .comp = {
00486 { 0, 3, 1, 0, 7 },
00487 { 0, 3, 2, 0, 7 },
00488 { 0, 3, 3, 0, 7 },
00489 { 0, 3, 4, 0, 7 },
00490 },
00491 .flags = PIX_FMT_RGB,
00492 },
00493 [PIX_FMT_0BGR] = {
00494 .name = "0bgr",
00495 .nb_components= 3,
00496 .log2_chroma_w= 0,
00497 .log2_chroma_h= 0,
00498 .comp = {
00499 { 0, 3, 2, 0, 7 },
00500 { 0, 3, 3, 0, 7 },
00501 { 0, 3, 4, 0, 7 },
00502 },
00503 .flags = PIX_FMT_RGB,
00504 },
00505 [PIX_FMT_BGR0] = {
00506 .name = "bgr0",
00507 .nb_components= 3,
00508 .log2_chroma_w= 0,
00509 .log2_chroma_h= 0,
00510 .comp = {
00511 { 0, 3, 1, 0, 7 },
00512 { 0, 3, 2, 0, 7 },
00513 { 0, 3, 3, 0, 7 },
00514 { 0, 3, 4, 0, 7 },
00515 },
00516 .flags = PIX_FMT_RGB,
00517 },
00518 [PIX_FMT_GRAY16BE] = {
00519 .name = "gray16be",
00520 .nb_components = 1,
00521 .log2_chroma_w = 0,
00522 .log2_chroma_h = 0,
00523 .comp = {
00524 { 0, 1, 1, 0, 15 },
00525 },
00526 .flags = PIX_FMT_BE,
00527 },
00528 [PIX_FMT_GRAY16LE] = {
00529 .name = "gray16le",
00530 .nb_components = 1,
00531 .log2_chroma_w = 0,
00532 .log2_chroma_h = 0,
00533 .comp = {
00534 { 0, 1, 1, 0, 15 },
00535 },
00536 },
00537 [PIX_FMT_YUV440P] = {
00538 .name = "yuv440p",
00539 .nb_components = 3,
00540 .log2_chroma_w = 0,
00541 .log2_chroma_h = 1,
00542 .comp = {
00543 { 0, 0, 1, 0, 7 },
00544 { 1, 0, 1, 0, 7 },
00545 { 2, 0, 1, 0, 7 },
00546 },
00547 .flags = PIX_FMT_PLANAR,
00548 },
00549 [PIX_FMT_YUVJ440P] = {
00550 .name = "yuvj440p",
00551 .nb_components = 3,
00552 .log2_chroma_w = 0,
00553 .log2_chroma_h = 1,
00554 .comp = {
00555 { 0, 0, 1, 0, 7 },
00556 { 1, 0, 1, 0, 7 },
00557 { 2, 0, 1, 0, 7 },
00558 },
00559 .flags = PIX_FMT_PLANAR,
00560 },
00561 [PIX_FMT_YUVA420P] = {
00562 .name = "yuva420p",
00563 .nb_components = 4,
00564 .log2_chroma_w = 1,
00565 .log2_chroma_h = 1,
00566 .comp = {
00567 { 0, 0, 1, 0, 7 },
00568 { 1, 0, 1, 0, 7 },
00569 { 2, 0, 1, 0, 7 },
00570 { 3, 0, 1, 0, 7 },
00571 },
00572 .flags = PIX_FMT_PLANAR,
00573 },
00574 [PIX_FMT_VDPAU_H264] = {
00575 .name = "vdpau_h264",
00576 .log2_chroma_w = 1,
00577 .log2_chroma_h = 1,
00578 .flags = PIX_FMT_HWACCEL,
00579 },
00580 [PIX_FMT_VDPAU_MPEG1] = {
00581 .name = "vdpau_mpeg1",
00582 .log2_chroma_w = 1,
00583 .log2_chroma_h = 1,
00584 .flags = PIX_FMT_HWACCEL,
00585 },
00586 [PIX_FMT_VDPAU_MPEG2] = {
00587 .name = "vdpau_mpeg2",
00588 .log2_chroma_w = 1,
00589 .log2_chroma_h = 1,
00590 .flags = PIX_FMT_HWACCEL,
00591 },
00592 [PIX_FMT_VDPAU_WMV3] = {
00593 .name = "vdpau_wmv3",
00594 .log2_chroma_w = 1,
00595 .log2_chroma_h = 1,
00596 .flags = PIX_FMT_HWACCEL,
00597 },
00598 [PIX_FMT_VDPAU_VC1] = {
00599 .name = "vdpau_vc1",
00600 .log2_chroma_w = 1,
00601 .log2_chroma_h = 1,
00602 .flags = PIX_FMT_HWACCEL,
00603 },
00604 [PIX_FMT_VDPAU_MPEG4] = {
00605 .name = "vdpau_mpeg4",
00606 .log2_chroma_w = 1,
00607 .log2_chroma_h = 1,
00608 .flags = PIX_FMT_HWACCEL,
00609 },
00610 [PIX_FMT_RGB48BE] = {
00611 .name = "rgb48be",
00612 .nb_components = 3,
00613 .log2_chroma_w = 0,
00614 .log2_chroma_h = 0,
00615 .comp = {
00616 { 0, 5, 1, 0, 15 },
00617 { 0, 5, 3, 0, 15 },
00618 { 0, 5, 5, 0, 15 },
00619 },
00620 .flags = PIX_FMT_RGB | PIX_FMT_BE,
00621 },
00622 [PIX_FMT_RGB48LE] = {
00623 .name = "rgb48le",
00624 .nb_components = 3,
00625 .log2_chroma_w = 0,
00626 .log2_chroma_h = 0,
00627 .comp = {
00628 { 0, 5, 1, 0, 15 },
00629 { 0, 5, 3, 0, 15 },
00630 { 0, 5, 5, 0, 15 },
00631 },
00632 .flags = PIX_FMT_RGB,
00633 },
00634 [PIX_FMT_RGBA64BE] = {
00635 .name = "rgba64be",
00636 .nb_components= 4,
00637 .log2_chroma_w= 0,
00638 .log2_chroma_h= 0,
00639 .comp = {
00640 { 0, 7, 1, 0, 15 },
00641 { 0, 7, 3, 0, 15 },
00642 { 0, 7, 5, 0, 15 },
00643 { 0, 7, 7, 0, 15 },
00644 },
00645 .flags = PIX_FMT_RGB | PIX_FMT_BE,
00646 },
00647 [PIX_FMT_RGBA64LE] = {
00648 .name = "rgba64le",
00649 .nb_components= 4,
00650 .log2_chroma_w= 0,
00651 .log2_chroma_h= 0,
00652 .comp = {
00653 { 0, 7, 1, 0, 15 },
00654 { 0, 7, 3, 0, 15 },
00655 { 0, 7, 5, 0, 15 },
00656 { 0, 7, 7, 0, 15 },
00657 },
00658 .flags = PIX_FMT_RGB,
00659 },
00660 [PIX_FMT_RGB565BE] = {
00661 .name = "rgb565be",
00662 .nb_components = 3,
00663 .log2_chroma_w = 0,
00664 .log2_chroma_h = 0,
00665 .comp = {
00666 { 0, 1, 0, 3, 4 },
00667 { 0, 1, 1, 5, 5 },
00668 { 0, 1, 1, 0, 4 },
00669 },
00670 .flags = PIX_FMT_BE | PIX_FMT_RGB,
00671 },
00672 [PIX_FMT_RGB565LE] = {
00673 .name = "rgb565le",
00674 .nb_components = 3,
00675 .log2_chroma_w = 0,
00676 .log2_chroma_h = 0,
00677 .comp = {
00678 { 0, 1, 2, 3, 4 },
00679 { 0, 1, 1, 5, 5 },
00680 { 0, 1, 1, 0, 4 },
00681 },
00682 .flags = PIX_FMT_RGB,
00683 },
00684 [PIX_FMT_RGB555BE] = {
00685 .name = "rgb555be",
00686 .nb_components = 3,
00687 .log2_chroma_w = 0,
00688 .log2_chroma_h = 0,
00689 .comp = {
00690 { 0, 1, 0, 2, 4 },
00691 { 0, 1, 1, 5, 4 },
00692 { 0, 1, 1, 0, 4 },
00693 },
00694 .flags = PIX_FMT_BE | PIX_FMT_RGB,
00695 },
00696 [PIX_FMT_RGB555LE] = {
00697 .name = "rgb555le",
00698 .nb_components = 3,
00699 .log2_chroma_w = 0,
00700 .log2_chroma_h = 0,
00701 .comp = {
00702 { 0, 1, 2, 2, 4 },
00703 { 0, 1, 1, 5, 4 },
00704 { 0, 1, 1, 0, 4 },
00705 },
00706 .flags = PIX_FMT_RGB,
00707 },
00708 [PIX_FMT_RGB444BE] = {
00709 .name = "rgb444be",
00710 .nb_components = 3,
00711 .log2_chroma_w = 0,
00712 .log2_chroma_h = 0,
00713 .comp = {
00714 { 0, 1, 0, 0, 3 },
00715 { 0, 1, 1, 4, 3 },
00716 { 0, 1, 1, 0, 3 },
00717 },
00718 .flags = PIX_FMT_BE | PIX_FMT_RGB,
00719 },
00720 [PIX_FMT_RGB444LE] = {
00721 .name = "rgb444le",
00722 .nb_components = 3,
00723 .log2_chroma_w = 0,
00724 .log2_chroma_h = 0,
00725 .comp = {
00726 { 0, 1, 2, 0, 3 },
00727 { 0, 1, 1, 4, 3 },
00728 { 0, 1, 1, 0, 3 },
00729 },
00730 .flags = PIX_FMT_RGB,
00731 },
00732 [PIX_FMT_BGR48BE] = {
00733 .name = "bgr48be",
00734 .nb_components = 3,
00735 .log2_chroma_w = 0,
00736 .log2_chroma_h = 0,
00737 .comp = {
00738 { 0, 5, 1, 0, 15 },
00739 { 0, 5, 3, 0, 15 },
00740 { 0, 5, 5, 0, 15 },
00741 },
00742 .flags = PIX_FMT_BE | PIX_FMT_RGB,
00743 },
00744 [PIX_FMT_BGR48LE] = {
00745 .name = "bgr48le",
00746 .nb_components = 3,
00747 .log2_chroma_w = 0,
00748 .log2_chroma_h = 0,
00749 .comp = {
00750 { 0, 5, 1, 0, 15 },
00751 { 0, 5, 3, 0, 15 },
00752 { 0, 5, 5, 0, 15 },
00753 },
00754 .flags = PIX_FMT_RGB,
00755 },
00756 [PIX_FMT_BGRA64BE] = {
00757 .name = "bgra64be",
00758 .nb_components= 4,
00759 .log2_chroma_w= 0,
00760 .log2_chroma_h= 0,
00761 .comp = {
00762 { 0, 7, 1, 0, 15 },
00763 { 0, 7, 3, 0, 15 },
00764 { 0, 7, 5, 0, 15 },
00765 { 0, 7, 7, 0, 15 },
00766 },
00767 .flags = PIX_FMT_BE,
00768 },
00769 [PIX_FMT_BGRA64LE] = {
00770 .name = "bgra64le",
00771 .nb_components= 4,
00772 .log2_chroma_w= 0,
00773 .log2_chroma_h= 0,
00774 .comp = {
00775 { 0, 7, 1, 0, 15 },
00776 { 0, 7, 3, 0, 15 },
00777 { 0, 7, 5, 0, 15 },
00778 { 0, 7, 7, 0, 15 },
00779 },
00780 },
00781 [PIX_FMT_BGR565BE] = {
00782 .name = "bgr565be",
00783 .nb_components = 3,
00784 .log2_chroma_w = 0,
00785 .log2_chroma_h = 0,
00786 .comp = {
00787 { 0, 1, 0, 3, 4 },
00788 { 0, 1, 1, 5, 5 },
00789 { 0, 1, 1, 0, 4 },
00790 },
00791 .flags = PIX_FMT_BE | PIX_FMT_RGB,
00792 },
00793 [PIX_FMT_BGR565LE] = {
00794 .name = "bgr565le",
00795 .nb_components = 3,
00796 .log2_chroma_w = 0,
00797 .log2_chroma_h = 0,
00798 .comp = {
00799 { 0, 1, 2, 3, 4 },
00800 { 0, 1, 1, 5, 5 },
00801 { 0, 1, 1, 0, 4 },
00802 },
00803 .flags = PIX_FMT_RGB,
00804 },
00805 [PIX_FMT_BGR555BE] = {
00806 .name = "bgr555be",
00807 .nb_components = 3,
00808 .log2_chroma_w = 0,
00809 .log2_chroma_h = 0,
00810 .comp = {
00811 { 0, 1, 0, 2, 4 },
00812 { 0, 1, 1, 5, 4 },
00813 { 0, 1, 1, 0, 4 },
00814 },
00815 .flags = PIX_FMT_BE | PIX_FMT_RGB,
00816 },
00817 [PIX_FMT_BGR555LE] = {
00818 .name = "bgr555le",
00819 .nb_components = 3,
00820 .log2_chroma_w = 0,
00821 .log2_chroma_h = 0,
00822 .comp = {
00823 { 0, 1, 2, 2, 4 },
00824 { 0, 1, 1, 5, 4 },
00825 { 0, 1, 1, 0, 4 },
00826 },
00827 .flags = PIX_FMT_RGB,
00828 },
00829 [PIX_FMT_BGR444BE] = {
00830 .name = "bgr444be",
00831 .nb_components = 3,
00832 .log2_chroma_w = 0,
00833 .log2_chroma_h = 0,
00834 .comp = {
00835 { 0, 1, 0, 0, 3 },
00836 { 0, 1, 1, 4, 3 },
00837 { 0, 1, 1, 0, 3 },
00838 },
00839 .flags = PIX_FMT_BE | PIX_FMT_RGB,
00840 },
00841 [PIX_FMT_BGR444LE] = {
00842 .name = "bgr444le",
00843 .nb_components = 3,
00844 .log2_chroma_w = 0,
00845 .log2_chroma_h = 0,
00846 .comp = {
00847 { 0, 1, 2, 0, 3 },
00848 { 0, 1, 1, 4, 3 },
00849 { 0, 1, 1, 0, 3 },
00850 },
00851 .flags = PIX_FMT_RGB,
00852 },
00853 [PIX_FMT_VAAPI_MOCO] = {
00854 .name = "vaapi_moco",
00855 .log2_chroma_w = 1,
00856 .log2_chroma_h = 1,
00857 .flags = PIX_FMT_HWACCEL,
00858 },
00859 [PIX_FMT_VAAPI_IDCT] = {
00860 .name = "vaapi_idct",
00861 .log2_chroma_w = 1,
00862 .log2_chroma_h = 1,
00863 .flags = PIX_FMT_HWACCEL,
00864 },
00865 [PIX_FMT_VAAPI_VLD] = {
00866 .name = "vaapi_vld",
00867 .log2_chroma_w = 1,
00868 .log2_chroma_h = 1,
00869 .flags = PIX_FMT_HWACCEL,
00870 },
00871 [PIX_FMT_VDA_VLD] = {
00872 .name = "vda_vld",
00873 .log2_chroma_w = 1,
00874 .log2_chroma_h = 1,
00875 .flags = PIX_FMT_HWACCEL,
00876 },
00877 [PIX_FMT_YUV420P9LE] = {
00878 .name = "yuv420p9le",
00879 .nb_components = 3,
00880 .log2_chroma_w = 1,
00881 .log2_chroma_h = 1,
00882 .comp = {
00883 { 0, 1, 1, 0, 8 },
00884 { 1, 1, 1, 0, 8 },
00885 { 2, 1, 1, 0, 8 },
00886 },
00887 .flags = PIX_FMT_PLANAR,
00888 },
00889 [PIX_FMT_YUV420P9BE] = {
00890 .name = "yuv420p9be",
00891 .nb_components = 3,
00892 .log2_chroma_w = 1,
00893 .log2_chroma_h = 1,
00894 .comp = {
00895 { 0, 1, 1, 0, 8 },
00896 { 1, 1, 1, 0, 8 },
00897 { 2, 1, 1, 0, 8 },
00898 },
00899 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
00900 },
00901 [PIX_FMT_YUV420P10LE] = {
00902 .name = "yuv420p10le",
00903 .nb_components = 3,
00904 .log2_chroma_w = 1,
00905 .log2_chroma_h = 1,
00906 .comp = {
00907 { 0, 1, 1, 0, 9 },
00908 { 1, 1, 1, 0, 9 },
00909 { 2, 1, 1, 0, 9 },
00910 },
00911 .flags = PIX_FMT_PLANAR,
00912 },
00913 [PIX_FMT_YUV420P10BE] = {
00914 .name = "yuv420p10be",
00915 .nb_components = 3,
00916 .log2_chroma_w = 1,
00917 .log2_chroma_h = 1,
00918 .comp = {
00919 { 0, 1, 1, 0, 9 },
00920 { 1, 1, 1, 0, 9 },
00921 { 2, 1, 1, 0, 9 },
00922 },
00923 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
00924 },
00925 [PIX_FMT_YUV420P16LE] = {
00926 .name = "yuv420p16le",
00927 .nb_components = 3,
00928 .log2_chroma_w = 1,
00929 .log2_chroma_h = 1,
00930 .comp = {
00931 { 0, 1, 1, 0, 15 },
00932 { 1, 1, 1, 0, 15 },
00933 { 2, 1, 1, 0, 15 },
00934 },
00935 .flags = PIX_FMT_PLANAR,
00936 },
00937 [PIX_FMT_YUV420P16BE] = {
00938 .name = "yuv420p16be",
00939 .nb_components = 3,
00940 .log2_chroma_w = 1,
00941 .log2_chroma_h = 1,
00942 .comp = {
00943 { 0, 1, 1, 0, 15 },
00944 { 1, 1, 1, 0, 15 },
00945 { 2, 1, 1, 0, 15 },
00946 },
00947 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
00948 },
00949 [PIX_FMT_YUV422P9LE] = {
00950 .name = "yuv422p9le",
00951 .nb_components = 3,
00952 .log2_chroma_w = 1,
00953 .log2_chroma_h = 0,
00954 .comp = {
00955 { 0, 1, 1, 0, 8 },
00956 { 1, 1, 1, 0, 8 },
00957 { 2, 1, 1, 0, 8 },
00958 },
00959 .flags = PIX_FMT_PLANAR,
00960 },
00961 [PIX_FMT_YUV422P9BE] = {
00962 .name = "yuv422p9be",
00963 .nb_components = 3,
00964 .log2_chroma_w = 1,
00965 .log2_chroma_h = 0,
00966 .comp = {
00967 { 0, 1, 1, 0, 8 },
00968 { 1, 1, 1, 0, 8 },
00969 { 2, 1, 1, 0, 8 },
00970 },
00971 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
00972 },
00973 [PIX_FMT_YUV422P10LE] = {
00974 .name = "yuv422p10le",
00975 .nb_components = 3,
00976 .log2_chroma_w = 1,
00977 .log2_chroma_h = 0,
00978 .comp = {
00979 { 0, 1, 1, 0, 9 },
00980 { 1, 1, 1, 0, 9 },
00981 { 2, 1, 1, 0, 9 },
00982 },
00983 .flags = PIX_FMT_PLANAR,
00984 },
00985 [PIX_FMT_YUV422P10BE] = {
00986 .name = "yuv422p10be",
00987 .nb_components = 3,
00988 .log2_chroma_w = 1,
00989 .log2_chroma_h = 0,
00990 .comp = {
00991 { 0, 1, 1, 0, 9 },
00992 { 1, 1, 1, 0, 9 },
00993 { 2, 1, 1, 0, 9 },
00994 },
00995 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
00996 },
00997 [PIX_FMT_YUV422P16LE] = {
00998 .name = "yuv422p16le",
00999 .nb_components = 3,
01000 .log2_chroma_w = 1,
01001 .log2_chroma_h = 0,
01002 .comp = {
01003 { 0, 1, 1, 0, 15 },
01004 { 1, 1, 1, 0, 15 },
01005 { 2, 1, 1, 0, 15 },
01006 },
01007 .flags = PIX_FMT_PLANAR,
01008 },
01009 [PIX_FMT_YUV422P16BE] = {
01010 .name = "yuv422p16be",
01011 .nb_components = 3,
01012 .log2_chroma_w = 1,
01013 .log2_chroma_h = 0,
01014 .comp = {
01015 { 0, 1, 1, 0, 15 },
01016 { 1, 1, 1, 0, 15 },
01017 { 2, 1, 1, 0, 15 },
01018 },
01019 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
01020 },
01021 [PIX_FMT_YUV444P16LE] = {
01022 .name = "yuv444p16le",
01023 .nb_components = 3,
01024 .log2_chroma_w = 0,
01025 .log2_chroma_h = 0,
01026 .comp = {
01027 { 0, 1, 1, 0, 15 },
01028 { 1, 1, 1, 0, 15 },
01029 { 2, 1, 1, 0, 15 },
01030 },
01031 .flags = PIX_FMT_PLANAR,
01032 },
01033 [PIX_FMT_YUV444P16BE] = {
01034 .name = "yuv444p16be",
01035 .nb_components = 3,
01036 .log2_chroma_w = 0,
01037 .log2_chroma_h = 0,
01038 .comp = {
01039 { 0, 1, 1, 0, 15 },
01040 { 1, 1, 1, 0, 15 },
01041 { 2, 1, 1, 0, 15 },
01042 },
01043 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
01044 },
01045 [PIX_FMT_YUV444P10LE] = {
01046 .name = "yuv444p10le",
01047 .nb_components = 3,
01048 .log2_chroma_w = 0,
01049 .log2_chroma_h = 0,
01050 .comp = {
01051 { 0, 1, 1, 0, 9 },
01052 { 1, 1, 1, 0, 9 },
01053 { 2, 1, 1, 0, 9 },
01054 },
01055 .flags = PIX_FMT_PLANAR,
01056 },
01057 [PIX_FMT_YUV444P10BE] = {
01058 .name = "yuv444p10be",
01059 .nb_components = 3,
01060 .log2_chroma_w = 0,
01061 .log2_chroma_h = 0,
01062 .comp = {
01063 { 0, 1, 1, 0, 9 },
01064 { 1, 1, 1, 0, 9 },
01065 { 2, 1, 1, 0, 9 },
01066 },
01067 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
01068 },
01069 [PIX_FMT_YUV444P9LE] = {
01070 .name = "yuv444p9le",
01071 .nb_components = 3,
01072 .log2_chroma_w = 0,
01073 .log2_chroma_h = 0,
01074 .comp = {
01075 { 0, 1, 1, 0, 8 },
01076 { 1, 1, 1, 0, 8 },
01077 { 2, 1, 1, 0, 8 },
01078 },
01079 .flags = PIX_FMT_PLANAR,
01080 },
01081 [PIX_FMT_YUV444P9BE] = {
01082 .name = "yuv444p9be",
01083 .nb_components = 3,
01084 .log2_chroma_w = 0,
01085 .log2_chroma_h = 0,
01086 .comp = {
01087 { 0, 1, 1, 0, 8 },
01088 { 1, 1, 1, 0, 8 },
01089 { 2, 1, 1, 0, 8 },
01090 },
01091 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
01092 },
01093 [PIX_FMT_DXVA2_VLD] = {
01094 .name = "dxva2_vld",
01095 .log2_chroma_w = 1,
01096 .log2_chroma_h = 1,
01097 .flags = PIX_FMT_HWACCEL,
01098 },
01099 [PIX_FMT_VDA_VLD] = {
01100 .name = "vda_vld",
01101 .log2_chroma_w = 1,
01102 .log2_chroma_h = 1,
01103 .flags = PIX_FMT_HWACCEL,
01104 },
01105 [PIX_FMT_GRAY8A] = {
01106 .name = "gray8a",
01107 .nb_components = 2,
01108 .comp = {
01109 { 0, 1, 1, 0, 7 },
01110 { 0, 1, 2, 0, 7 },
01111 },
01112 },
01113 [PIX_FMT_GBR24P] = {
01114 .name = "gbr24p",
01115 .nb_components= 3,
01116 .comp = {
01117 { 1, 0, 1, 0, 7 },
01118 { 0, 0, 1, 0, 7 },
01119 { 2, 0, 1, 0, 7 },
01120 },
01121 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
01122 },
01123 [PIX_FMT_GBRP] = {
01124 .name = "gbrp",
01125 .nb_components = 3,
01126 .log2_chroma_w = 0,
01127 .log2_chroma_h = 0,
01128 .comp = {
01129 { 0, 0, 1, 0, 7 },
01130 { 1, 0, 1, 0, 7 },
01131 { 2, 0, 1, 0, 7 },
01132 },
01133 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
01134 },
01135 [PIX_FMT_GBRP9LE] = {
01136 .name = "gbrp9le",
01137 .nb_components = 3,
01138 .log2_chroma_w = 0,
01139 .log2_chroma_h = 0,
01140 .comp = {
01141 { 0, 1, 1, 0, 8 },
01142 { 1, 1, 1, 0, 8 },
01143 { 2, 1, 1, 0, 8 },
01144 },
01145 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
01146 },
01147 [PIX_FMT_GBRP9BE] = {
01148 .name = "gbrp9be",
01149 .nb_components = 3,
01150 .log2_chroma_w = 0,
01151 .log2_chroma_h = 0,
01152 .comp = {
01153 { 0, 1, 1, 0, 8 },
01154 { 1, 1, 1, 0, 8 },
01155 { 2, 1, 1, 0, 8 },
01156 },
01157 .flags = PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_RGB,
01158 },
01159 [PIX_FMT_GBRP10LE] = {
01160 .name = "gbrp10le",
01161 .nb_components = 3,
01162 .log2_chroma_w = 0,
01163 .log2_chroma_h = 0,
01164 .comp = {
01165 { 0, 1, 1, 0, 9 },
01166 { 1, 1, 1, 0, 9 },
01167 { 2, 1, 1, 0, 9 },
01168 },
01169 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
01170 },
01171 [PIX_FMT_GBRP10BE] = {
01172 .name = "gbrp10be",
01173 .nb_components = 3,
01174 .log2_chroma_w = 0,
01175 .log2_chroma_h = 0,
01176 .comp = {
01177 { 0, 1, 1, 0, 9 },
01178 { 1, 1, 1, 0, 9 },
01179 { 2, 1, 1, 0, 9 },
01180 },
01181 .flags = PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_RGB,
01182 },
01183 [PIX_FMT_GBRP16LE] = {
01184 .name = "gbrp16le",
01185 .nb_components = 3,
01186 .log2_chroma_w = 0,
01187 .log2_chroma_h = 0,
01188 .comp = {
01189 { 0, 1, 1, 0, 15 },
01190 { 1, 1, 1, 0, 15 },
01191 { 2, 1, 1, 0, 15 },
01192 },
01193 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
01194 },
01195 [PIX_FMT_GBRP16BE] = {
01196 .name = "gbrp16be",
01197 .nb_components = 3,
01198 .log2_chroma_w = 0,
01199 .log2_chroma_h = 0,
01200 .comp = {
01201 { 0, 1, 1, 0, 15 },
01202 { 1, 1, 1, 0, 15 },
01203 { 2, 1, 1, 0, 15 },
01204 },
01205 .flags = PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_RGB,
01206 },
01207 };
01208
01209 static enum PixelFormat get_pix_fmt_internal(const char *name)
01210 {
01211 enum PixelFormat pix_fmt;
01212
01213 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
01214 if (av_pix_fmt_descriptors[pix_fmt].name &&
01215 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
01216 return pix_fmt;
01217
01218 return PIX_FMT_NONE;
01219 }
01220
01221 const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
01222 {
01223 return (unsigned)pix_fmt < PIX_FMT_NB ?
01224 av_pix_fmt_descriptors[pix_fmt].name : NULL;
01225 }
01226
01227 #if HAVE_BIGENDIAN
01228 # define X_NE(be, le) be
01229 #else
01230 # define X_NE(be, le) le
01231 #endif
01232
01233 enum PixelFormat av_get_pix_fmt(const char *name)
01234 {
01235 enum PixelFormat pix_fmt;
01236
01237 if (!strcmp(name, "rgb32"))
01238 name = X_NE("argb", "bgra");
01239 else if (!strcmp(name, "bgr32"))
01240 name = X_NE("abgr", "rgba");
01241
01242 pix_fmt = get_pix_fmt_internal(name);
01243 if (pix_fmt == PIX_FMT_NONE) {
01244 char name2[32];
01245
01246 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
01247 pix_fmt = get_pix_fmt_internal(name2);
01248 }
01249 return pix_fmt;
01250 }
01251
01252 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
01253 {
01254 int c, bits = 0;
01255 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
01256
01257 for (c = 0; c < pixdesc->nb_components; c++) {
01258 int s = c == 1 || c == 2 ? 0 : log2_pixels;
01259 bits += (pixdesc->comp[c].depth_minus1 + 1) << s;
01260 }
01261
01262 return bits >> log2_pixels;
01263 }
01264
01265 char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
01266 {
01267
01268 if (pix_fmt < 0) {
01269 snprintf (buf, buf_size, "name" " nb_components" " nb_bits");
01270 } else {
01271 const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
01272 snprintf(buf, buf_size, "%-11s %7d %10d", pixdesc->name,
01273 pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));
01274 }
01275
01276 return buf;
01277 }