annotate sgienc.c @ 9676:f39076e0d605 libavcodec

Use iMDCT output scaling to simplify ffvorbis and make it slightly faster.
author serge
date Wed, 20 May 2009 07:26:09 +0000
parents 777deb3dc12b
children 38cfe222e1a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
1 /*
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
2 * SGI image encoder
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
3 * Todd Kirby <doubleshot@pacbell.net>
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
4 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
5 * This file is part of FFmpeg.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
6 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
11 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
15 * Lesser General Public License for more details.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
16 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
20 */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
21
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
22 #include "avcodec.h"
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
23 #include "bytestream.h"
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
24 #include "sgi.h"
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
25 #include "rle.h"
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
26
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
27 #define SGI_SINGLE_CHAN 2
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
28 #define SGI_MULTI_CHAN 3
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
29
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
30 typedef struct SgiContext {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
31 AVFrame picture;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
32 } SgiContext;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
33
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 4790
diff changeset
34 static av_cold int encode_init(AVCodecContext *avctx){
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
35 SgiContext *s = avctx->priv_data;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
36
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
37 avcodec_get_frame_defaults(&s->picture);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
38 avctx->coded_frame = &s->picture;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
39
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
40 return 0;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
41 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
42
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
43 static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
44 int buf_size, void *data) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
45 SgiContext *s = avctx->priv_data;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
46 AVFrame * const p = &s->picture;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
47 uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
48 int x, y, z, length, tablesize;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
49 unsigned int width, height, depth, dimension;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
50 unsigned char *orig_buf = buf, *end_buf = buf + buf_size;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
51
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
52 *p = *(AVFrame*)data;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
53 p->pict_type = FF_I_TYPE;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
54 p->key_frame = 1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
55
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
56 width = avctx->width;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
57 height = avctx->height;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
58
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
59 switch (avctx->pix_fmt) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
60 case PIX_FMT_GRAY8:
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
61 dimension = SGI_SINGLE_CHAN;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
62 depth = SGI_GRAYSCALE;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
63 break;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
64 case PIX_FMT_RGB24:
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
65 dimension = SGI_MULTI_CHAN;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
66 depth = SGI_RGB;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
67 break;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
68 case PIX_FMT_RGBA:
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
69 dimension = SGI_MULTI_CHAN;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
70 depth = SGI_RGBA;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
71 break;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
72 default:
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
73 return AVERROR_INVALIDDATA;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
74 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
75
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
76 tablesize = depth * height * 4;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
77 length = tablesize * 2 + SGI_HEADER_SIZE;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
78
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
79 if (buf_size < length) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
80 av_log(avctx, AV_LOG_ERROR, "buf_size too small(need %d, got %d)\n", length, buf_size);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
81 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
82 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
83
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
84 /* Encode header. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
85 bytestream_put_be16(&buf, SGI_MAGIC);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
86 bytestream_put_byte(&buf, 1); /* RLE */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
87 bytestream_put_byte(&buf, 1); /* bytes_per_channel */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
88 bytestream_put_be16(&buf, dimension);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
89 bytestream_put_be16(&buf, width);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
90 bytestream_put_be16(&buf, height);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
91 bytestream_put_be16(&buf, depth);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
92
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
93 /* The rest are constant in this implementation. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
94 bytestream_put_be32(&buf, 0L); /* pixmin */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
95 bytestream_put_be32(&buf, 255L); /* pixmax */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
96 bytestream_put_be32(&buf, 0L); /* dummy */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
97
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
98 /* name */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
99 memset(buf, 0, SGI_HEADER_SIZE);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
100 buf += 80;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
101
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
102 /* colormap */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
103 bytestream_put_be32(&buf, 0L);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
104
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
105 /* The rest of the 512 byte header is unused. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
106 buf += 404;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
107 offsettab = buf;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
108
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
109 /* Skip RLE offset table. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
110 buf += tablesize;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
111 lengthtab = buf;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
112
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
113 /* Skip RLE length table. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
114 buf += tablesize;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
115
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
116 /* Make an intermediate consecutive buffer. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
117 if ((encode_buf = av_malloc(width)) == NULL)
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
118 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
119
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
120 for (z = 0; z < depth; z++) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
121 in_buf = p->data[0] + p->linesize[0] * (height - 1) + z;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
122
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
123 for (y = 0; y < height; y++) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
124 bytestream_put_be32(&offsettab, buf - orig_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
125
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
126 for (x = 0; x < width; x++)
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
127 encode_buf[x] = in_buf[depth * x];
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
128
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
129 if((length = ff_rle_encode(buf, end_buf - buf - 1, encode_buf, 1, width, 0, 0, 0x80, 0)) < 1) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
130 av_free(encode_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
131 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
132 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
133
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
134 buf += length;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
135 bytestream_put_byte(&buf, 0);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
136 bytestream_put_be32(&lengthtab, length + 1);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
137 in_buf -= p->linesize[0];
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
138 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
139 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
140
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
141 av_free(encode_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
142 /* total length */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
143 return buf - orig_buf;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
144 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
145
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
146 AVCodec sgi_encoder = {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
147 "sgi",
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
148 CODEC_TYPE_VIDEO,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
149 CODEC_ID_SGI,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
150 sizeof(SgiContext),
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
151 encode_init,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
152 encode_frame,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
153 NULL,
9624
777deb3dc12b sgi encoder does not support pal8
bcoudurier
parents: 7040
diff changeset
154 .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_GRAY8, PIX_FMT_NONE},
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6788
diff changeset
155 .long_name= NULL_IF_CONFIG_SMALL("SGI image"),
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
156 };
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
157