OLD | NEW |
1 /* | 1 /* |
2 * pixel format descriptor | 2 * pixel format descriptor |
3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at> | 3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at> |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * FFmpeg is distributed in the hope that it will be useful, | 12 * FFmpeg is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | 15 * Lesser General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Lesser General Public | 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 | 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 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | 20 */ |
21 | 21 |
22 #include "pixfmt.h" | 22 #include "pixfmt.h" |
23 #include "pixdesc.h" | 23 #include "pixdesc.h" |
24 | 24 |
| 25 #include "intreadwrite.h" |
| 26 |
| 27 void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], |
| 28 const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int r
ead_pal_component) |
| 29 { |
| 30 AVComponentDescriptor comp= desc->comp[c]; |
| 31 int plane= comp.plane; |
| 32 int depth= comp.depth_minus1+1; |
| 33 int mask = (1<<depth)-1; |
| 34 int shift= comp.shift; |
| 35 int step = comp.step_minus1+1; |
| 36 int flags= desc->flags; |
| 37 |
| 38 if (flags & PIX_FMT_BITSTREAM){ |
| 39 int skip = x*step + comp.offset_plus1-1; |
| 40 const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); |
| 41 int shift = 8 - depth - (skip&7); |
| 42 |
| 43 while(w--){ |
| 44 int val = (*p >> shift) & mask; |
| 45 if(read_pal_component) |
| 46 val= data[1][4*val + c]; |
| 47 shift -= step; |
| 48 p -= shift>>3; |
| 49 shift &= 7; |
| 50 *dst++= val; |
| 51 } |
| 52 } else { |
| 53 const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset
_plus1-1; |
| 54 |
| 55 while(w--){ |
| 56 int val; |
| 57 if(flags & PIX_FMT_BE) val= AV_RB16(p); |
| 58 else val= AV_RL16(p); |
| 59 val = (val>>shift) & mask; |
| 60 if(read_pal_component) |
| 61 val= data[1][4*val + c]; |
| 62 p+= step; |
| 63 *dst++= val; |
| 64 } |
| 65 } |
| 66 } |
| 67 |
| 68 void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], |
| 69 const AVPixFmtDescriptor *desc, int x, int y, int c, int w) |
| 70 { |
| 71 AVComponentDescriptor comp = desc->comp[c]; |
| 72 int plane = comp.plane; |
| 73 int depth = comp.depth_minus1+1; |
| 74 int step = comp.step_minus1+1; |
| 75 int flags = desc->flags; |
| 76 |
| 77 if (flags & PIX_FMT_BITSTREAM) { |
| 78 int skip = x*step + comp.offset_plus1-1; |
| 79 uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); |
| 80 int shift = 8 - depth - (skip&7); |
| 81 |
| 82 while (w--) { |
| 83 *p |= *src++ << shift; |
| 84 shift -= step; |
| 85 p -= shift>>3; |
| 86 shift &= 7; |
| 87 } |
| 88 } else { |
| 89 int shift = comp.shift; |
| 90 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1
-1; |
| 91 |
| 92 while (w--) { |
| 93 if (flags & PIX_FMT_BE) { |
| 94 uint16_t val = AV_RB16(p) | (*src++<<shift); |
| 95 AV_WB16(p, val); |
| 96 } else { |
| 97 uint16_t val = AV_RL16(p) | (*src++<<shift); |
| 98 AV_WL16(p, val); |
| 99 } |
| 100 p+= step; |
| 101 } |
| 102 } |
| 103 } |
| 104 |
25 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = { | 105 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = { |
26 [PIX_FMT_YUV420P] = { | 106 [PIX_FMT_YUV420P] = { |
27 .name = "yuv420p", | 107 .name = "yuv420p", |
28 .nb_components= 3, | 108 .nb_components= 3, |
29 .log2_chroma_w= 1, | 109 .log2_chroma_w= 1, |
30 .log2_chroma_h= 1, | 110 .log2_chroma_h= 1, |
31 .comp = { | 111 .comp = { |
32 {0,0,1,0,7}, /* Y */ | 112 {0,0,1,0,7}, /* Y */ |
33 {1,0,1,0,7}, /* U */ | 113 {1,0,1,0,7}, /* U */ |
34 {2,0,1,0,7}, /* V */ | 114 {2,0,1,0,7}, /* V */ |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 }, | 192 }, |
113 }, | 193 }, |
114 [PIX_FMT_GRAY8] = { | 194 [PIX_FMT_GRAY8] = { |
115 .name = "gray", | 195 .name = "gray", |
116 .nb_components= 1, | 196 .nb_components= 1, |
117 .log2_chroma_w= 0, | 197 .log2_chroma_w= 0, |
118 .log2_chroma_h= 0, | 198 .log2_chroma_h= 0, |
119 .comp = { | 199 .comp = { |
120 {0,0,1,0,7}, /* Y */ | 200 {0,0,1,0,7}, /* Y */ |
121 }, | 201 }, |
| 202 .flags = PIX_FMT_PAL, |
122 }, | 203 }, |
123 [PIX_FMT_MONOWHITE] = { | 204 [PIX_FMT_MONOWHITE] = { |
124 .name = "monow", | 205 .name = "monow", |
125 .nb_components= 1, | 206 .nb_components= 1, |
126 .log2_chroma_w= 0, | 207 .log2_chroma_w= 0, |
127 .log2_chroma_h= 0, | 208 .log2_chroma_h= 0, |
128 .comp = { | 209 .comp = { |
129 {0,0,1,0,0}, /* Y */ | 210 {0,0,1,0,0}, /* Y */ |
130 }, | 211 }, |
131 .flags = PIX_FMT_BITSTREAM, | 212 .flags = PIX_FMT_BITSTREAM, |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 .name = "rgb555le", | 587 .name = "rgb555le", |
507 .nb_components= 3, | 588 .nb_components= 3, |
508 .log2_chroma_w= 0, | 589 .log2_chroma_w= 0, |
509 .log2_chroma_h= 0, | 590 .log2_chroma_h= 0, |
510 .comp = { | 591 .comp = { |
511 {0,1,2,2,4}, /* R */ | 592 {0,1,2,2,4}, /* R */ |
512 {0,1,1,5,4}, /* G */ | 593 {0,1,1,5,4}, /* G */ |
513 {0,1,1,0,4}, /* B */ | 594 {0,1,1,0,4}, /* B */ |
514 }, | 595 }, |
515 }, | 596 }, |
| 597 [PIX_FMT_RGB444BE] = { |
| 598 .name = "rgb444be", |
| 599 .nb_components= 3, |
| 600 .log2_chroma_w= 0, |
| 601 .log2_chroma_h= 0, |
| 602 .comp = { |
| 603 {0,1,0,0,3}, /* R */ |
| 604 {0,1,1,4,3}, /* G */ |
| 605 {0,1,1,0,3}, /* B */ |
| 606 }, |
| 607 .flags = PIX_FMT_BE, |
| 608 }, |
| 609 [PIX_FMT_RGB444LE] = { |
| 610 .name = "rgb444le", |
| 611 .nb_components= 3, |
| 612 .log2_chroma_w= 0, |
| 613 .log2_chroma_h= 0, |
| 614 .comp = { |
| 615 {0,1,2,0,3}, /* R */ |
| 616 {0,1,1,4,3}, /* G */ |
| 617 {0,1,1,0,3}, /* B */ |
| 618 }, |
| 619 }, |
516 [PIX_FMT_BGR565BE] = { | 620 [PIX_FMT_BGR565BE] = { |
517 .name = "bgr565be", | 621 .name = "bgr565be", |
518 .nb_components= 3, | 622 .nb_components= 3, |
519 .log2_chroma_w= 0, | 623 .log2_chroma_w= 0, |
520 .log2_chroma_h= 0, | 624 .log2_chroma_h= 0, |
521 .comp = { | 625 .comp = { |
522 {0,1,0,3,4}, /* B */ | 626 {0,1,0,3,4}, /* B */ |
523 {0,1,1,5,5}, /* G */ | 627 {0,1,1,5,5}, /* G */ |
524 {0,1,1,0,4}, /* R */ | 628 {0,1,1,0,4}, /* R */ |
525 }, | 629 }, |
(...skipping 26 matching lines...) Expand all Loading... |
552 .name = "bgr555le", | 656 .name = "bgr555le", |
553 .nb_components= 3, | 657 .nb_components= 3, |
554 .log2_chroma_w= 0, | 658 .log2_chroma_w= 0, |
555 .log2_chroma_h= 0, | 659 .log2_chroma_h= 0, |
556 .comp = { | 660 .comp = { |
557 {0,1,2,2,4}, /* B */ | 661 {0,1,2,2,4}, /* B */ |
558 {0,1,1,5,4}, /* G */ | 662 {0,1,1,5,4}, /* G */ |
559 {0,1,1,0,4}, /* R */ | 663 {0,1,1,0,4}, /* R */ |
560 }, | 664 }, |
561 }, | 665 }, |
| 666 [PIX_FMT_BGR444BE] = { |
| 667 .name = "bgr444be", |
| 668 .nb_components= 3, |
| 669 .log2_chroma_w= 0, |
| 670 .log2_chroma_h= 0, |
| 671 .comp = { |
| 672 {0,1,0,0,3}, /* B */ |
| 673 {0,1,1,4,3}, /* G */ |
| 674 {0,1,1,0,3}, /* R */ |
| 675 }, |
| 676 .flags = PIX_FMT_BE, |
| 677 }, |
| 678 [PIX_FMT_BGR444LE] = { |
| 679 .name = "bgr444le", |
| 680 .nb_components= 3, |
| 681 .log2_chroma_w= 0, |
| 682 .log2_chroma_h= 0, |
| 683 .comp = { |
| 684 {0,1,2,0,3}, /* B */ |
| 685 {0,1,1,4,3}, /* G */ |
| 686 {0,1,1,0,3}, /* R */ |
| 687 }, |
| 688 }, |
562 [PIX_FMT_VAAPI_MOCO] = { | 689 [PIX_FMT_VAAPI_MOCO] = { |
563 .name = "vaapi_moco", | 690 .name = "vaapi_moco", |
564 .log2_chroma_w = 1, | 691 .log2_chroma_w = 1, |
565 .log2_chroma_h = 1, | 692 .log2_chroma_h = 1, |
566 .flags = PIX_FMT_HWACCEL, | 693 .flags = PIX_FMT_HWACCEL, |
567 }, | 694 }, |
568 [PIX_FMT_VAAPI_IDCT] = { | 695 [PIX_FMT_VAAPI_IDCT] = { |
569 .name = "vaapi_idct", | 696 .name = "vaapi_idct", |
570 .log2_chroma_w = 1, | 697 .log2_chroma_w = 1, |
571 .log2_chroma_h = 1, | 698 .log2_chroma_h = 1, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 int c, bits = 0; | 823 int c, bits = 0; |
697 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h; | 824 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h; |
698 | 825 |
699 for (c = 0; c < pixdesc->nb_components; c++) { | 826 for (c = 0; c < pixdesc->nb_components; c++) { |
700 int s = c==1 || c==2 ? 0 : log2_pixels; | 827 int s = c==1 || c==2 ? 0 : log2_pixels; |
701 bits += (pixdesc->comp[c].depth_minus1+1) << s; | 828 bits += (pixdesc->comp[c].depth_minus1+1) << s; |
702 } | 829 } |
703 | 830 |
704 return bits >> log2_pixels; | 831 return bits >> log2_pixels; |
705 } | 832 } |
OLD | NEW |