1 /*
2 * Sun Rasterfile (.sun/.ras/im{1,8,24}/.sunras) image encoder
3 * Copyright (c) 2012 Aneesh Dogra (lionaneesh) <lionaneesh@gmail.com>
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
26
30 int length;
///< length (bytes) of image
31 int type;
///< type of file
36
38 {
40
42 bytestream2_put_be32u(&s->
p, avctx->
width);
43 bytestream2_put_be32u(&s->
p, avctx->
height);
44 bytestream2_put_be32u(&s->
p, s->
depth);
45 bytestream2_put_be32u(&s->
p, s->
length);
46 bytestream2_put_be32u(&s->
p, s->
type);
47 bytestream2_put_be32u(&s->
p, s->
maptype);
49 }
50
53 const uint32_t *palette_data,
54 int linesize)
55 {
59
63
68
69 for (x = 0; x <
len; x++) {
70 uint32_t
pixel = palette_data[x];
71
72 bytestream2_put_byteu(&pb_r, (pixel >> 16) & 0xFF);
73 bytestream2_put_byteu(&pb_g, (pixel >> 8) & 0xFF);
74 bytestream2_put_byteu(&s->
p, pixel & 0xFF);
75 }
76 }
77
79 alen = len + (len & 1);
80 ptr = pixels;
81
85
86 ptr = pixels;
87
88 #define GET_VALUE y >= avctx->height ? 0 : x >= len ? ptr[len-1] : ptr[x]
89
90 x = 0, y = 0;
92 while (y < avctx->
height) {
93 run = 1;
94 value = value2;
95 x++;
96 if (x >= alen) {
97 x = 0;
98 ptr += linesize, y++;
99 }
100
102 while (value2 == value && run < 256 && y < avctx->height) {
103 x++;
104 run++;
105 if (x >= alen) {
106 x = 0;
107 ptr += linesize, y++;
108 }
110 }
111
114 bytestream2_put_byteu(&s->
p, run - 1);
115 if (run > 1)
116 bytestream2_put_byteu(&s->
p, value);
117 } else if (run == 1) {
118 bytestream2_put_byteu(&s->
p, value);
119 } else
120 bytestream2_put_be16u(&s->
p, (value << 8) | value);
121 }
122
123 // update data length for header
125 } else {
126 for (y = 0; y < avctx->
height; y++) {
128 if (len < alen)
129 bytestream2_put_byteu(&s->
p, 0);
130 ptr += linesize;
131 }
132 }
133 }
134
136 {
138
142 break;
145 break;
146 default:
149 }
150
153
157 break;
163 break;
166 break;
167 default:
169 }
173
174 return 0;
175 }
176
179 {
182
185
189 (
const uint32_t *)frame->
data[1],
191 // update data length in header after RLE
194
195 *got_packet_ptr = 1;
198 return 0;
199 }
200
202 {
204 return 0;
205 }
206
208 { "coder", "rle" },
209 { NULL },
210 };
211
227 };