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
23
29
32
35 int length;
///< length (bytes) of image
36 int type;
///< type of file
41
43 {
45
47 bytestream2_put_be32u(&
s->p, avctx->
width);
48 bytestream2_put_be32u(&
s->p, avctx->
height);
49 bytestream2_put_be32u(&
s->p,
s->depth);
50 bytestream2_put_be32u(&
s->p,
s->length);
51 bytestream2_put_be32u(&
s->p,
s->type);
52 bytestream2_put_be32u(&
s->p,
s->maptype);
53 bytestream2_put_be32u(&
s->p,
s->maplength);
54 }
55
57 const uint8_t *pixels,
58 const uint32_t *palette_data,
59 int linesize)
60 {
62 const uint8_t *ptr;
64
65 if (
s->maplength) {
// palettized
67 int len =
s->maplength / 3;
68
73
74 for (x = 0; x <
len; x++) {
75 uint32_t
pixel = palette_data[x];
76
77 bytestream2_put_byteu(&pb_r, (
pixel >> 16) & 0xFF);
78 bytestream2_put_byteu(&pb_g, (
pixel >> 8) & 0xFF);
79 bytestream2_put_byteu(&
s->p,
pixel & 0xFF);
80 }
81 }
82
85 ptr = pixels;
86
88 uint8_t
value, value2;
90
91 ptr = pixels;
92
93 #define GET_VALUE y >= avctx->height ? 0 : x >= len ? ptr[len-1] : ptr[x]
94
95 x = 0, y = 0;
97 while (y < avctx->
height) {
100 x++;
101 if (x >= alen) {
102 x = 0;
103 ptr += linesize, y++;
104 }
105
108 x++;
110 if (x >= alen) {
111 x = 0;
112 ptr += linesize, y++;
113 }
115 }
116
119 bytestream2_put_byteu(&
s->p,
run - 1);
121 bytestream2_put_byteu(&
s->p,
value);
122 }
else if (
run == 1) {
123 bytestream2_put_byteu(&
s->p,
value);
124 } else
125 bytestream2_put_be16u(&
s->p, (
value << 8) |
value);
126 }
127
128 // update data length for header
130 } else {
131 for (y = 0; y < avctx->
height; y++) {
134 bytestream2_put_byteu(&
s->p, 0);
135 ptr += linesize;
136 }
137 }
138 }
139
141 {
143
144 // adjust boolean option to RT equivalent
146
149
153 break;
156 s->maplength = 3 * 256;
157 /* fall-through */
160 break;
163 break;
164 default:
166 }
168 s->size = 32 +
s->maplength +
s->length *
s->type;
169
170 return 0;
171 }
172
175 {
178
181
185 (
const uint32_t *)
frame->data[1],
187 // update data length in header after RLE
190
191 *got_packet_ptr = 1;
193 return 0;
194 }
195
196 #define OFFSET(x) offsetof(SUNRASTContext, x)
197 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
200
202 };
203
209 };
210
226 };