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
28
31
34 int length;
///< length (bytes) of image
35 int type;
///< type of file
40
42 {
44
46 bytestream2_put_be32u(&s->
p, avctx->
width);
47 bytestream2_put_be32u(&s->
p, avctx->
height);
48 bytestream2_put_be32u(&s->
p, s->
depth);
49 bytestream2_put_be32u(&s->
p, s->
length);
50 bytestream2_put_be32u(&s->
p, s->
type);
51 bytestream2_put_be32u(&s->
p, s->
maptype);
53 }
54
57 const uint32_t *palette_data,
58 int linesize)
59 {
63
67
72
73 for (x = 0; x <
len; x++) {
74 uint32_t
pixel = palette_data[x];
75
76 bytestream2_put_byteu(&pb_r, (pixel >> 16) & 0xFF);
77 bytestream2_put_byteu(&pb_g, (pixel >> 8) & 0xFF);
78 bytestream2_put_byteu(&s->
p, pixel & 0xFF);
79 }
80 }
81
83 alen = len + (len & 1);
85
89
91
92 #define GET_VALUE y >= avctx->height ? 0 : x >= len ? ptr[len-1] : ptr[x]
93
94 x = 0, y = 0;
96 while (y < avctx->
height) {
97 run = 1;
98 value = value2;
99 x++;
100 if (x >= alen) {
101 x = 0;
102 ptr += linesize, y++;
103 }
104
106 while (value2 == value && run < 256 && y < avctx->height) {
107 x++;
108 run++;
109 if (x >= alen) {
110 x = 0;
111 ptr += linesize, y++;
112 }
114 }
115
118 bytestream2_put_byteu(&s->
p, run - 1);
119 if (run > 1)
120 bytestream2_put_byteu(&s->
p, value);
121 } else if (run == 1) {
122 bytestream2_put_byteu(&s->
p, value);
123 } else
124 bytestream2_put_be16u(&s->
p, (value << 8) | value);
125 }
126
127 // update data length for header
129 } else {
130 for (y = 0; y < avctx->
height; y++) {
132 if (len < alen)
133 bytestream2_put_byteu(&s->
p, 0);
134 ptr += linesize;
135 }
136 }
137 }
138
140 {
142
143 #if FF_API_CODER_TYPE
148 break;
151 break;
152 default:
155 }
158 #endif
159 // adjust boolean option to RT equivalent
161
164
168 break;
172 /* fall-through */
175 break;
178 break;
179 default:
181 }
184
185 return 0;
186 }
187
190 {
192 int ret;
193
195 return ret;
196
200 (
const uint32_t *)frame->
data[1],
202 // update data length in header after RLE
205
206 *got_packet_ptr = 1;
209 return 0;
210 }
211
212 #define OFFSET(x) offsetof(SUNRASTContext, x)
213 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
216
218 };
219
225 };
226
227 #if FF_API_CODER_TYPE
229 { "coder", "rle" },
231 };
232 #endif
233
244 #endif
245 .priv_class = &sunrast_class,
251 };
This structure describes decoded (raw) audio or video data.
static const AVCodecDefault sunrast_defaults[]
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
const char * av_default_item_name(void *ptr)
Return the context name.
#define FF_API_CODER_TYPE
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int length
length (bytes) of image
static int sunrast_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
8 bits with AV_PIX_FMT_RGB32 palette
int maplength
length (bytes) of colormap
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#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. ...
int maptype
type of colormap
const char * name
Name of the codec implementation.
static const AVCodecDefault defaults[]
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
int flags
A combination of AV_PKT_FLAG values.
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
int width
picture width / height.
GLsizei GLboolean const GLfloat * value
static const AVOption options[]
AVCodec ff_sunrast_encoder
packed RGB 8:8:8, 24bpp, BGRBGR...
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
attribute_deprecated int coder_type
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static void sunrast_image_write_image(AVCodecContext *avctx, const uint8_t *pixels, const uint32_t *palette_data, int linesize)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Describe the class of an AVClass context structure.
static void sunrast_image_write_header(AVCodecContext *avctx)
static av_cold int sunrast_encode_init(AVCodecContext *avctx)
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
#define FF_CODER_TYPE_RAW
#define FF_ENABLE_DEPRECATION_WARNINGS
#define FF_CODER_TYPE_RLE
static const AVClass sunrast_class
AVPixelFormat
Pixel format.
This structure stores compressed data.