1 /*
2 * Sun Rasterfile (.sun/.ras/im{1,8,24}/.sunras) image decoder
3 * Copyright (c) 2007, 2008 Ivo van Poorten
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
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
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
28
31 {
35 unsigned int w, h,
depth,
type, maptype, maplength,
stride, x,
y,
len, alen;
39
42
46 }
47
54 buf += 32;
55
59 }
63 }
67 }
71 }
75 }
76
79 return -1;
80 }
81
82 switch (depth) {
83 case 1:
85 break;
86 case 4:
88 break;
89 case 8:
91 break;
92 case 24:
94 break;
95 case 32:
97 break;
98 default:
101 }
102
107
109
110 if (buf_end - buf < maplength)
112
113 if (depth > 8 && maplength) {
114 av_log(avctx,
AV_LOG_WARNING,
"useless colormap found or file is corrupted, trying to recover\n");
115
116 } else if (maplength) {
117 unsigned int len = maplength / 3;
118
119 if (maplength % 3 || maplength > 768) {
122 }
123
125 for (x = 0; x <
len; x++, ptr += 4)
126 *(uint32_t *)ptr = (0xFF
U<<24) + (buf[x]<<16) + (buf[len+x]<<8) + buf[len+len+x];
127 }
128
129 buf += maplength;
130
131 if (maplength && depth < 8) {
133 if (!ptr)
135 stride = (w + 15 >> 3) * depth;
136 } else {
139 }
140
141 /* scanlines are aligned on 16 bit boundaries */
142 len = (depth * w + 7) >> 3;
143 alen = len + (len & 1);
144
148
149 x = 0;
150 while (ptr != end && buf < buf_end) {
151 run = 1;
152 if (buf_end - buf < 1)
154
156 run = *buf++ + 1;
157 if (run != 1)
158 value = *buf++;
159 }
160 while (run--) {
161 if (x < len)
163 if (++x >= alen) {
164 x = 0;
166 if (ptr == end)
167 break;
168 }
169 }
170 }
171 } else {
172 for (y = 0; y < h; y++) {
173 if (buf_end - buf < len)
174 break;
175 memcpy(ptr, buf, len);
177 buf += alen;
178 }
179 }
183 for (y=0; y<h; y++) {
184 for (x = 0; x < (w + 7 >> 3) * depth; x++) {
185 if (depth == 1) {
186 ptr[8*x] = ptr2[x] >> 7;
187 ptr[8*x+1] = ptr2[x] >> 6 & 1;
188 ptr[8*x+2] = ptr2[x] >> 5 & 1;
189 ptr[8*x+3] = ptr2[x] >> 4 & 1;
190 ptr[8*x+4] = ptr2[x] >> 3 & 1;
191 ptr[8*x+5] = ptr2[x] >> 2 & 1;
192 ptr[8*x+6] = ptr2[x] >> 1 & 1;
193 ptr[8*x+7] = ptr2[x] & 1;
194 } else {
195 ptr[2*x] = ptr2[x] >> 4;
196 ptr[2*x+1] = ptr2[x] & 0xF;
197 }
198 }
200 ptr2 += (w + 15 >> 3) * depth;
201 }
203 }
204
205 *got_frame = 1;
206
207 return buf - bufstart;
208 }
209
217 };