comparison pixdesc.c @ 1014:3728a7291737 libavutil

pixdesc: use 8-bit accesses when possible in av_read/write_image_line() This fixes out of bounds accesses for big endian formats and should be a little faster.
author mru
date Sun, 12 Sep 2010 21:39:54 +0000
parents 83021885b234
children f332df5d8da5
comparison
equal deleted inserted replaced
1013:83021885b234 1014:3728a7291737
51 shift &= 7; 51 shift &= 7;
52 *dst++= val; 52 *dst++= val;
53 } 53 }
54 } else { 54 } else {
55 const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; 55 const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
56 56 int is_8bit = 0;
57
58 if (shift + depth <= 8) {
59 p += !!(flags & PIX_FMT_BE);
60 is_8bit = 1;
61 }
57 while(w--){ 62 while(w--){
58 int val = flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p); 63 int val = is_8bit ? *p :
64 flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
59 val = (val>>shift) & mask; 65 val = (val>>shift) & mask;
60 if(read_pal_component) 66 if(read_pal_component)
61 val= data[1][4*val + c]; 67 val= data[1][4*val + c];
62 p+= step; 68 p+= step;
63 *dst++= val; 69 *dst++= val;
87 } 93 }
88 } else { 94 } else {
89 int shift = comp.shift; 95 int shift = comp.shift;
90 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; 96 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
91 97
98 if (shift + depth <= 8) {
99 p += !!(flags & PIX_FMT_BE);
100 while (w--) {
101 *p |= (*src++<<shift);
102 p += step;
103 }
104 } else {
92 while (w--) { 105 while (w--) {
93 if (flags & PIX_FMT_BE) { 106 if (flags & PIX_FMT_BE) {
94 uint16_t val = AV_RB16(p) | (*src++<<shift); 107 uint16_t val = AV_RB16(p) | (*src++<<shift);
95 AV_WB16(p, val); 108 AV_WB16(p, val);
96 } else { 109 } else {
97 uint16_t val = AV_RL16(p) | (*src++<<shift); 110 uint16_t val = AV_RL16(p) | (*src++<<shift);
98 AV_WL16(p, val); 111 AV_WL16(p, val);
99 } 112 }
100 p+= step; 113 p+= step;
101 } 114 }
115 }
102 } 116 }
103 } 117 }
104 118
105 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = { 119 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
106 [PIX_FMT_YUV420P] = { 120 [PIX_FMT_YUV420P] = {