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;
38 int ret;
39
42
46 }
47
54 buf += 32;
55
59 }
63 }
67 }
71 }
72
75 return -1;
76 }
77
78 switch (depth) {
79 case 1:
81 break;
82 case 4:
84 break;
85 case 8:
87 break;
88 case 24:
90 break;
91 case 32:
93 break;
94 default:
97 }
98
100 if (ret < 0)
101 return ret;
102
104 return ret;
105
107
108 if (buf_end - buf < maplength)
110
111 if (depth > 8 && maplength) {
112 av_log(avctx,
AV_LOG_WARNING,
"useless colormap found or file is corrupted, trying to recover\n");
113
114 } else if (maplength) {
115 unsigned int len = maplength / 3;
116
117 if (maplength % 3 || maplength > 768) {
120 }
121
123 for (x = 0; x <
len; x++, ptr += 4)
124 *(uint32_t *)ptr = (0xFF
U<<24) + (buf[x]<<16) + (buf[len+x]<<8) + buf[len+len+x];
125 }
126
127 buf += maplength;
128
129 if (maplength && depth < 8) {
131 if (!ptr)
133 stride = (w + 15 >> 3) * depth;
134 } else {
137 }
138
139 /* scanlines are aligned on 16 bit boundaries */
140 len = (depth * w + 7) >> 3;
141 alen = len + (len & 1);
142
146
147 x = 0;
148 while (ptr != end && buf < buf_end) {
149 run = 1;
150 if (buf_end - buf < 1)
152
154 run = *buf++ + 1;
155 if (run != 1)
156 value = *buf++;
157 }
158 while (run--) {
159 if (x < len)
161 if (++x >= alen) {
162 x = 0;
164 if (ptr == end)
165 break;
166 }
167 }
168 }
169 } else {
170 for (y = 0; y <
h; y++) {
171 if (buf_end - buf < alen)
172 break;
173 memcpy(ptr, buf, len);
175 buf += alen;
176 }
177 }
181 for (y=0; y<
h; y++) {
182 for (x = 0; x < (w + 7 >> 3) * depth; x++) {
183 if (depth == 1) {
184 ptr[8*x] = ptr2[x] >> 7;
185 ptr[8*x+1] = ptr2[x] >> 6 & 1;
186 ptr[8*x+2] = ptr2[x] >> 5 & 1;
187 ptr[8*x+3] = ptr2[x] >> 4 & 1;
188 ptr[8*x+4] = ptr2[x] >> 3 & 1;
189 ptr[8*x+5] = ptr2[x] >> 2 & 1;
190 ptr[8*x+6] = ptr2[x] >> 1 & 1;
191 ptr[8*x+7] = ptr2[x] & 1;
192 } else {
193 ptr[2*x] = ptr2[x] >> 4;
194 ptr[2*x+1] = ptr2[x] & 0xF;
195 }
196 }
198 ptr2 += (w + 15 >> 3) * depth;
199 }
201 }
202
203 *got_frame = 1;
204
205 return buf - bufstart;
206 }
207
215 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
#define RMT_RAW
the data layout of this map type is unknown
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
8 bits with AV_PIX_FMT_RGB32 palette
static av_cold int end(AVCodecContext *avctx)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
enum AVPictureType pict_type
Picture type of the frame.
GLsizei GLboolean const GLfloat * value
AVCodec ff_sunrast_decoder
packed RGB 8:8:8, 24bpp, BGRBGR...
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static int sunrast_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
common internal and external API header
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
#define av_malloc_array(a, b)
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.