Mercurial > libavcodec.hg
comparison indeo2.c @ 2621:0a55e35d3e5e libavcodec
simplify
author | michael |
---|---|
date | Wed, 20 Apr 2005 10:16:19 +0000 |
parents | c39756a516a5 |
children | f20c1cdfce76 |
comparison
equal
deleted
inserted
replaced
2620:08cce4785567 | 2621:0a55e35d3e5e |
---|---|
38 static VLC ir2_vlc; | 38 static VLC ir2_vlc; |
39 | 39 |
40 /* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */ | 40 /* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */ |
41 static inline int ir2_get_code(GetBitContext *gb) | 41 static inline int ir2_get_code(GetBitContext *gb) |
42 { | 42 { |
43 int code; | 43 return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1; |
44 | 44 } |
45 code = get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1; | |
46 if (code >= 0x80) | |
47 return (code + 1); | |
48 return code; | |
49 } | |
50 #define CLAMP_TO_BYTE(value) \ | |
51 if (value > 255) \ | |
52 value = 255; \ | |
53 else if (value < 0) \ | |
54 value = 0; \ | |
55 | 45 |
56 static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride, | 46 static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride, |
57 const uint8_t *table) | 47 const uint8_t *table) |
58 { | 48 { |
59 int i; | 49 int i; |
66 return -1; | 56 return -1; |
67 | 57 |
68 /* first line contain absolute values, other lines contain deltas */ | 58 /* first line contain absolute values, other lines contain deltas */ |
69 while (out < width){ | 59 while (out < width){ |
70 c = ir2_get_code(&ctx->gb); | 60 c = ir2_get_code(&ctx->gb); |
71 if(c > 0x80) { /* we have a run */ | 61 if(c >= 0x80) { /* we have a run */ |
72 c -= 0x80; | 62 c -= 0x7F; |
73 if(out + c*2 > width) | 63 if(out + c*2 > width) |
74 return -1; | 64 return -1; |
75 for (i = 0; i < c * 2; i++) | 65 for (i = 0; i < c * 2; i++) |
76 dst[out++] = 0x80; | 66 dst[out++] = 0x80; |
77 } else { /* copy two values from table */ | 67 } else { /* copy two values from table */ |
83 | 73 |
84 for (j = 1; j < height; j++){ | 74 for (j = 1; j < height; j++){ |
85 out = 0; | 75 out = 0; |
86 while (out < width){ | 76 while (out < width){ |
87 c = ir2_get_code(&ctx->gb); | 77 c = ir2_get_code(&ctx->gb); |
88 if(c > 0x80) { /* we have a skip */ | 78 if(c >= 0x80) { /* we have a skip */ |
89 c -= 0x80; | 79 c -= 0x7F; |
90 if(out + c*2 > width) | 80 if(out + c*2 > width) |
91 return -1; | 81 return -1; |
92 for (i = 0; i < c * 2; i++) { | 82 for (i = 0; i < c * 2; i++) { |
93 dst[out] = dst[out - stride]; | 83 dst[out] = dst[out - stride]; |
94 out++; | 84 out++; |
95 } | 85 } |
96 } else { /* add two deltas from table */ | 86 } else { /* add two deltas from table */ |
97 t = dst[out - stride] + (table[c * 2] - 128); | 87 t = dst[out - stride] + (table[c * 2] - 128); |
98 CLAMP_TO_BYTE(t); | 88 t= clip_uint8(t); |
99 dst[out] = t; | 89 dst[out] = t; |
100 out++; | 90 out++; |
101 t = dst[out - stride] + (table[(c * 2) + 1] - 128); | 91 t = dst[out - stride] + (table[(c * 2) + 1] - 128); |
102 CLAMP_TO_BYTE(t); | 92 t= clip_uint8(t); |
103 dst[out] = t; | 93 dst[out] = t; |
104 out++; | 94 out++; |
105 } | 95 } |
106 } | 96 } |
107 dst += stride; | 97 dst += stride; |
122 | 112 |
123 for (j = 0; j < height; j++){ | 113 for (j = 0; j < height; j++){ |
124 out = 0; | 114 out = 0; |
125 while (out < width){ | 115 while (out < width){ |
126 c = ir2_get_code(&ctx->gb); | 116 c = ir2_get_code(&ctx->gb); |
127 if(c > 0x80) { /* we have a skip */ | 117 if(c >= 0x80) { /* we have a skip */ |
128 c -= 0x80; | 118 c -= 0x7F; |
129 out += c * 2; | 119 out += c * 2; |
130 } else { /* add two deltas from table */ | 120 } else { /* add two deltas from table */ |
131 t = dst[out] + (table[c * 2] - 128); | 121 t = dst[out] + (table[c * 2] - 128); |
132 CLAMP_TO_BYTE(t); | 122 t= clip_uint8(t); |
133 dst[out] = t; | 123 dst[out] = t; |
134 out++; | 124 out++; |
135 t = dst[out] + (table[(c * 2) + 1] - 128); | 125 t = dst[out] + (table[(c * 2) + 1] - 128); |
136 CLAMP_TO_BYTE(t); | 126 t= clip_uint8(t); |
137 dst[out] = t; | 127 dst[out] = t; |
138 out++; | 128 out++; |
139 } | 129 } |
140 } | 130 } |
141 dst += stride; | 131 dst += stride; |