Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master: (22 commits)
als: prevent infinite loop in zero_remaining().
cook: prevent div-by-zero if channels is zero.
pamenc: switch to encode2().
svq1enc: switch to encode2().
dvenc: switch to encode2().
dpxenc: switch to encode2().
pngenc: switch to encode2().
v210enc: switch to encode2().
xwdenc: switch to encode2().
ttadec: use branchless unsigned-to-signed unfolding
avcodec: add a Sun Rasterfile encoder
sunrast: Move common defines to a new header file.
cdxl: fix video decoding for some files
cdxl: fix audio for some samples
apetag: add proper support for binary tags
ttadec: remove dead code
swscale: make access to filter data conditional on filter type.
swscale: update context offsets after removal of AlpMmxFilter.
prores: initialise encoder and decoder parts only when needed
swscale: make monowhite/black RGB-independent.
...

Conflicts:
Changelog
libavcodec/alsdec.c
libavcodec/dpxenc.c
libavcodec/golomb.h
libavcodec/pamenc.c
libavcodec/pngenc.c
libavformat/img2.c
libswscale/output.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/02/18 10:20:19
Showing 29 changed files
... ...
@@ -7,6 +7,7 @@ version next:
7 7
 - CDXL demuxer and decoder
8 8
 - Apple ProRes encoder
9 9
 - ffprobe -count_packets and -count_frames options
10
+- Sun Rasterfile Encoder
10 11
 
11 12
 
12 13
 version 0.10:
... ...
@@ -395,7 +395,7 @@ following image formats are supported:
395 395
     @tab V.Flash PTX format
396 396
 @item SGI          @tab X @tab X
397 397
     @tab SGI RGB image format
398
-@item Sun Rasterfile  @tab   @tab X
398
+@item Sun Rasterfile  @tab X @tab X
399 399
     @tab Sun RAS image format
400 400
 @item TIFF         @tab X @tab X
401 401
     @tab YUV, JPEG and some extension is not supported yet.
... ...
@@ -393,6 +393,7 @@ OBJS-$(CONFIG_SP5X_DECODER)            += sp5xdec.o mjpegdec.o mjpeg.o
393 393
 OBJS-$(CONFIG_SRT_DECODER)             += srtdec.o ass.o
394 394
 OBJS-$(CONFIG_SRT_ENCODER)             += srtenc.o ass_split.o
395 395
 OBJS-$(CONFIG_SUNRAST_DECODER)         += sunrast.o
396
+OBJS-$(CONFIG_SUNRAST_ENCODER)         += sunrastenc.o
396 397
 OBJS-$(CONFIG_SVQ1_DECODER)            += svq1dec.o svq1.o h263.o \
397 398
                                           mpegvideo.o error_resilience.o
398 399
 OBJS-$(CONFIG_SVQ1_ENCODER)            += svq1enc.o svq1.o    \
... ...
@@ -204,7 +204,7 @@ void avcodec_register_all(void)
204 204
     REGISTER_DECODER (SMC, smc);
205 205
     REGISTER_ENCDEC  (SNOW, snow);
206 206
     REGISTER_DECODER (SP5X, sp5x);
207
-    REGISTER_DECODER (SUNRAST, sunrast);
207
+    REGISTER_ENCDEC  (SUNRAST, sunrast);
208 208
     REGISTER_ENCDEC  (SVQ1, svq1);
209 209
     REGISTER_DECODER (SVQ3, svq3);
210 210
     REGISTER_ENCDEC  (TARGA, targa);
... ...
@@ -60,27 +60,29 @@ static void import_palette(CDXLVideoContext *c, uint32_t *new_palette)
60 60
     }
61 61
 }
62 62
 
63
-static void bitplanar2chunky(CDXLVideoContext *c, int width,
64
-                             int linesize, uint8_t *out)
63
+static void bitplanar2chunky(CDXLVideoContext *c, int linesize, uint8_t *out)
65 64
 {
65
+    int skip = FFALIGN(c->avctx->width, 16) - c->avctx->width;
66 66
     GetBitContext gb;
67 67
     int x, y, plane;
68 68
 
69 69
     init_get_bits(&gb, c->video, c->video_size * 8);
70 70
     memset(out, 0, linesize * c->avctx->height);
71
-    for (plane = 0; plane < c->bpp; plane++)
72
-        for (y = 0; y < c->avctx->height; y++)
73
-            for (x = 0; x < width; x++)
71
+    for (plane = 0; plane < c->bpp; plane++) {
72
+        for (y = 0; y < c->avctx->height; y++) {
73
+            for (x = 0; x < c->avctx->width; x++)
74 74
                 out[linesize * y + x] |= get_bits1(&gb) << plane;
75
+            skip_bits(&gb, skip);
76
+        }
77
+    }
75 78
 }
76 79
 
77 80
 static void cdxl_decode_rgb(CDXLVideoContext *c)
78 81
 {
79 82
     uint32_t *new_palette = (uint32_t *)c->frame.data[1];
80
-    int padded_width = FFALIGN(c->avctx->width, 16);
81 83
 
82 84
     import_palette(c, new_palette);
83
-    bitplanar2chunky(c, padded_width, c->frame.linesize[0], c->frame.data[0]);
85
+    bitplanar2chunky(c, c->frame.linesize[0], c->frame.data[0]);
84 86
 }
85 87
 
86 88
 static void cdxl_decode_ham6(CDXLVideoContext *c)
... ...
@@ -94,7 +96,7 @@ static void cdxl_decode_ham6(CDXLVideoContext *c)
94 94
     out = c->frame.data[0];
95 95
 
96 96
     import_palette(c, new_palette);
97
-    bitplanar2chunky(c, avctx->width, avctx->width, c->new_video);
97
+    bitplanar2chunky(c, avctx->width, c->new_video);
98 98
 
99 99
     for (y = 0; y < avctx->height; y++) {
100 100
         r = new_palette[0] & 0xFF0000;
... ...
@@ -137,7 +139,7 @@ static void cdxl_decode_ham8(CDXLVideoContext *c)
137 137
     out = c->frame.data[0];
138 138
 
139 139
     import_palette(c, new_palette);
140
-    bitplanar2chunky(c, avctx->width, avctx->width, c->new_video);
140
+    bitplanar2chunky(c, avctx->width, c->new_video);
141 141
 
142 142
     for (y = 0; y < avctx->height; y++) {
143 143
         r = new_palette[0] & 0xFF0000;
... ...
@@ -209,16 +211,13 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data,
209 209
     if (w != avctx->width || h != avctx->height)
210 210
         avcodec_set_dimensions(avctx, w, h);
211 211
 
212
+    if (c->video_size < FFALIGN(avctx->width, 16) * avctx->height * c->bpp / 8)
213
+        return AVERROR_INVALIDDATA;
212 214
     if (encoding == 0) {
213
-        if (c->video_size < FFALIGN(avctx->width, 16) *
214
-                            avctx->height * c->bpp / 8)
215
-            return AVERROR_INVALIDDATA;
216 215
         avctx->pix_fmt = PIX_FMT_PAL8;
217 216
     } else if (encoding == 1 && (c->bpp == 6 || c->bpp == 8)) {
218 217
         if (c->palette_size != (1 << (c->bpp - 1)))
219 218
             return AVERROR_INVALIDDATA;
220
-        if (c->video_size < avctx->width * avctx->height * c->bpp / 8)
221
-            return AVERROR_INVALIDDATA;
222 219
         avctx->pix_fmt = PIX_FMT_BGR24;
223 220
     } else {
224 221
         av_log_ask_for_sample(avctx, "unsupported encoding %d and bpp %d\n",
... ...
@@ -1078,6 +1078,10 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
1078 1078
     q->sample_rate = avctx->sample_rate;
1079 1079
     q->nb_channels = avctx->channels;
1080 1080
     q->bit_rate = avctx->bit_rate;
1081
+    if (!q->nb_channels) {
1082
+        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
1083
+        return AVERROR_INVALIDDATA;
1084
+    }
1081 1085
 
1082 1086
     /* Initialize RNG. */
1083 1087
     av_lfg_init(&q->random_state, 0);
... ...
@@ -22,6 +22,7 @@
22 22
 #include "libavutil/intreadwrite.h"
23 23
 #include "libavutil/imgutils.h"
24 24
 #include "avcodec.h"
25
+#include "internal.h"
25 26
 
26 27
 typedef struct DPXContext {
27 28
     AVFrame picture;
... ...
@@ -104,14 +105,23 @@ static void encode_rgb48_10bit(AVCodecContext *avctx, const AVPicture *pic, uint
104 104
     }
105 105
 }
106 106
 
107
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
107
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
108
+                        const AVFrame *frame, int *got_packet)
108 109
 {
109 110
     DPXContext *s = avctx->priv_data;
110
-    int size;
111
+    int size, ret;
112
+    uint8_t *buf;
111 113
 
112 114
 #define HEADER_SIZE 1664  /* DPX Generic header */
113
-    if (buf_size < HEADER_SIZE)
114
-        return -1;
115
+    if (s->bits_per_component == 10)
116
+        size = avctx->height * avctx->width * 4;
117
+    else
118
+        size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
119
+    if ((ret = ff_alloc_packet(pkt, size + HEADER_SIZE)) < 0) {
120
+        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
121
+        return ret;
122
+    }
123
+    buf = pkt->data;
115 124
 
116 125
     memset(buf, 0, HEADER_SIZE);
117 126
 
... ...
@@ -144,17 +154,14 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
144 144
     switch(s->bits_per_component) {
145 145
     case 8:
146 146
     case 16:
147
-        size = avpicture_layout(data, avctx->pix_fmt,
147
+        size = avpicture_layout((const AVPicture*)frame, avctx->pix_fmt,
148 148
                                 avctx->width, avctx->height,
149
-                                buf + HEADER_SIZE, buf_size - HEADER_SIZE);
149
+                                buf + HEADER_SIZE, pkt->size - HEADER_SIZE);
150 150
         if (size < 0)
151 151
             return size;
152 152
         break;
153 153
     case 10:
154
-        size = avctx->height * avctx->width * 4;
155
-        if (buf_size < HEADER_SIZE + size)
156
-            return -1;
157
-        encode_rgb48_10bit(avctx, data, buf + HEADER_SIZE);
154
+        encode_rgb48_10bit(avctx, (const AVPicture*)frame, buf + HEADER_SIZE);
158 155
         break;
159 156
     default:
160 157
         av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", s->bits_per_component);
... ...
@@ -164,7 +171,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
164 164
     size += HEADER_SIZE;
165 165
 
166 166
     write32(buf + 16, size); /* file size */
167
-    return size;
167
+
168
+    pkt->flags |= AV_PKT_FLAG_KEY;
169
+    *got_packet = 1;
170
+
171
+    return 0;
168 172
 }
169 173
 
170 174
 AVCodec ff_dpx_encoder = {
... ...
@@ -173,7 +184,7 @@ AVCodec ff_dpx_encoder = {
173 173
     .id   = CODEC_ID_DPX,
174 174
     .priv_data_size = sizeof(DPXContext),
175 175
     .init   = encode_init,
176
-    .encode = encode_frame,
176
+    .encode2 = encode_frame,
177 177
     .pix_fmts = (const enum PixelFormat[]){
178 178
         PIX_FMT_RGB24,
179 179
         PIX_FMT_RGBA,
... ...
@@ -42,6 +42,7 @@
42 42
 #include "avcodec.h"
43 43
 #include "dsputil.h"
44 44
 #include "get_bits.h"
45
+#include "internal.h"
45 46
 #include "put_bits.h"
46 47
 #include "simple_idct.h"
47 48
 #include "dvdata.h"
... ...
@@ -1276,29 +1277,37 @@ static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
1276 1276
 }
1277 1277
 
1278 1278
 
1279
-static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size,
1280
-                                void *data)
1279
+static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt,
1280
+                                const AVFrame *frame, int *got_packet)
1281 1281
 {
1282 1282
     DVVideoContext *s = c->priv_data;
1283
+    int ret;
1283 1284
 
1284 1285
     s->sys = avpriv_dv_codec_profile(c);
1285
-    if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys))
1286
+    if (!s->sys || dv_init_dynamic_tables(s->sys))
1286 1287
         return -1;
1288
+    if ((ret = ff_alloc_packet(pkt, s->sys->frame_size)) < 0) {
1289
+        av_log(c, AV_LOG_ERROR, "Error getting output packet.\n");
1290
+        return ret;
1291
+    }
1287 1292
 
1288 1293
     c->pix_fmt           = s->sys->pix_fmt;
1289
-    s->picture           = *((AVFrame *)data);
1294
+    s->picture           = *frame;
1290 1295
     s->picture.key_frame = 1;
1291 1296
     s->picture.pict_type = AV_PICTURE_TYPE_I;
1292 1297
 
1293
-    s->buf = buf;
1298
+    s->buf = pkt->data;
1294 1299
     c->execute(c, dv_encode_video_segment, s->sys->work_chunks, NULL,
1295 1300
                dv_work_pool_size(s->sys), sizeof(DVwork_chunk));
1296 1301
 
1297 1302
     emms_c();
1298 1303
 
1299
-    dv_format_frame(s, buf);
1304
+    dv_format_frame(s, pkt->data);
1300 1305
 
1301
-    return s->sys->frame_size;
1306
+    pkt->flags |= AV_PKT_FLAG_KEY;
1307
+    *got_packet = 1;
1308
+
1309
+    return 0;
1302 1310
 }
1303 1311
 #endif
1304 1312
 
... ...
@@ -1320,7 +1329,7 @@ AVCodec ff_dvvideo_encoder = {
1320 1320
     .id             = CODEC_ID_DVVIDEO,
1321 1321
     .priv_data_size = sizeof(DVVideoContext),
1322 1322
     .init           = dvvideo_init_encoder,
1323
-    .encode         = dvvideo_encode_frame,
1323
+    .encode2        = dvvideo_encode_frame,
1324 1324
     .capabilities = CODEC_CAP_SLICE_THREADS,
1325 1325
     .pix_fmts  = (const enum PixelFormat[]) {PIX_FMT_YUV411P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, PIX_FMT_NONE},
1326 1326
     .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
... ...
@@ -422,7 +422,16 @@ static inline int decode_subframe(FLACContext *s, int channel)
422 422
     type = get_bits(&s->gb, 6);
423 423
 
424 424
     if (get_bits1(&s->gb)) {
425
+        int left = get_bits_left(&s->gb);
425 426
         wasted = 1;
427
+        if ( left < 0 ||
428
+            (left < s->curr_bps && !show_bits_long(&s->gb, left)) ||
429
+                                   !show_bits_long(&s->gb, s->curr_bps)) {
430
+            av_log(s->avctx, AV_LOG_ERROR,
431
+                   "Invalid number of wasted bits > available bits (%d) - left=%d\n",
432
+                   s->curr_bps, left);
433
+            return AVERROR_INVALIDDATA;
434
+        }
426 435
         while (!get_bits1(&s->gb))
427 436
             wasted++;
428 437
         s->curr_bps -= wasted;
... ...
@@ -301,7 +301,7 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int
301 301
         return buf;
302 302
     }else{
303 303
         int i;
304
-        for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){
304
+        for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
305 305
             if (gb->size_in_bits <= re_index)
306 306
                 return -1;
307 307
             LAST_SKIP_BITS(re, gb, 1);
... ...
@@ -20,22 +20,24 @@
20 20
  */
21 21
 
22 22
 #include "avcodec.h"
23
+#include "internal.h"
23 24
 #include "pnm.h"
24 25
 
25 26
 
26
-static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
27
-                            int buf_size, void *data)
27
+static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
28
+                            const AVFrame *pict, int *got_packet)
28 29
 {
29 30
     PNMContext *s     = avctx->priv_data;
30
-    AVFrame *pict     = data;
31 31
     AVFrame * const p = (AVFrame*)&s->picture;
32
-    int i, h, w, n, linesize, depth, maxval;
32
+    int i, h, w, n, linesize, depth, maxval, ret;
33 33
     const char *tuple_type;
34 34
     uint8_t *ptr;
35 35
 
36
-    if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) {
36
+    if ((ret = ff_alloc_packet(pkt, avpicture_get_size(avctx->pix_fmt,
37
+                                                       avctx->width,
38
+                                                       avctx->height) + 200)) < 0) {
37 39
         av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
38
-        return -1;
40
+        return ret;
39 41
     }
40 42
 
41 43
     *p           = *pict;
... ...
@@ -43,8 +45,8 @@ static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
43 43
     p->key_frame = 1;
44 44
 
45 45
     s->bytestream_start =
46
-    s->bytestream       = outbuf;
47
-    s->bytestream_end   = outbuf+buf_size;
46
+    s->bytestream       = pkt->data;
47
+    s->bytestream_end   = pkt->data + pkt->size;
48 48
 
49 49
     h = avctx->height;
50 50
     w = avctx->width;
... ...
@@ -122,7 +124,11 @@ static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
122 122
             ptr           += linesize;
123 123
         }
124 124
     }
125
-    return s->bytestream - s->bytestream_start;
125
+
126
+    pkt->size   = s->bytestream - s->bytestream_start;
127
+    pkt->flags |= AV_PKT_FLAG_KEY;
128
+    *got_packet = 1;
129
+    return 0;
126 130
 }
127 131
 
128 132
 
... ...
@@ -132,7 +138,7 @@ AVCodec ff_pam_encoder = {
132 132
     .id             = CODEC_ID_PAM,
133 133
     .priv_data_size = sizeof(PNMContext),
134 134
     .init           = ff_pnm_init,
135
-    .encode         = pam_encode_frame,
135
+    .encode2        = pam_encode_frame,
136 136
     .pix_fmts  = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_RGB48BE, PIX_FMT_RGBA64BE, PIX_FMT_GRAY8, PIX_FMT_GRAY8A, PIX_FMT_GRAY16BE, PIX_FMT_MONOBLACK, PIX_FMT_NONE},
137 137
     .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
138 138
 };
... ...
@@ -212,12 +212,13 @@ static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
212 212
     return 0;
213 213
 }
214 214
 
215
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
215
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
216
+                        const AVFrame *pict, int *got_packet)
217
+{
216 218
     PNGEncContext *s = avctx->priv_data;
217
-    AVFrame *pict = data;
218 219
     AVFrame * const p= &s->picture;
219 220
     int bit_depth, color_type, y, len, row_size, ret, is_progressive;
220
-    int bits_per_pixel, pass_row_size;
221
+    int bits_per_pixel, pass_row_size, max_packet_size;
221 222
     int compression_level;
222 223
     uint8_t *ptr, *top;
223 224
     uint8_t *crow_base = NULL, *crow_buf, *crow;
... ...
@@ -228,9 +229,17 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
228 228
     p->pict_type= AV_PICTURE_TYPE_I;
229 229
     p->key_frame= 1;
230 230
 
231
-    s->bytestream_start=
232
-    s->bytestream= buf;
233
-    s->bytestream_end= buf+buf_size;
231
+    max_packet_size = IOBUF_SIZE*avctx->height + FF_MIN_BUFFER_SIZE;
232
+    if (!pkt->data &&
233
+        (ret = av_new_packet(pkt, max_packet_size)) < 0) {
234
+        av_log(avctx, AV_LOG_ERROR, "Could not allocate output packet of size %d.\n",
235
+               max_packet_size);
236
+        return ret;
237
+    }
238
+
239
+    s->bytestream_start =
240
+    s->bytestream       = pkt->data;
241
+    s->bytestream_end   = pkt->data + pkt->size;
234 242
 
235 243
     is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
236 244
     switch(avctx->pix_fmt) {
... ...
@@ -393,7 +402,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
393 393
     }
394 394
     png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
395 395
 
396
-    ret = s->bytestream - s->bytestream_start;
396
+    pkt->size   = s->bytestream - s->bytestream_start;
397
+    pkt->flags |= AV_PKT_FLAG_KEY;
398
+    *got_packet = 1;
399
+    ret         = 0;
400
+
397 401
  the_end:
398 402
     av_free(crow_base);
399 403
     av_free(progressive_buf);
... ...
@@ -425,7 +438,7 @@ AVCodec ff_png_encoder = {
425 425
     .id             = CODEC_ID_PNG,
426 426
     .priv_data_size = sizeof(PNGEncContext),
427 427
     .init           = png_enc_init,
428
-    .encode         = encode_frame,
428
+    .encode2        = encode_frame,
429 429
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA,
430 430
                                           PIX_FMT_RGB48BE, PIX_FMT_RGBA64BE,
431 431
                                           PIX_FMT_PAL8,
... ...
@@ -53,7 +53,8 @@ extern SINETABLE( 512);
53 53
 extern SINETABLE(1024);
54 54
 extern SINETABLE(2048);
55 55
 extern SINETABLE(4096);
56
+extern SINETABLE(8192);
56 57
 
57
-extern SINETABLE_CONST float * const ff_sine_windows[13];
58
+extern SINETABLE_CONST float * const ff_sine_windows[14];
58 59
 
59 60
 #endif /* AVCODEC_SINEWIN_H */
... ...
@@ -38,7 +38,7 @@ int main(void)
38 38
 
39 39
     write_fileheader();
40 40
 
41
-    for (i = 5; i <= 12; i++) {
41
+    for (i = 5; i <= 13; i++) {
42 42
         ff_init_ff_sine_windows(i);
43 43
         printf("SINETABLE(%4i) = {\n", 1 << i);
44 44
         write_float_array(ff_sine_windows[i], 1 << i);
... ...
@@ -38,6 +38,7 @@ SINETABLE( 512);
38 38
 SINETABLE(1024);
39 39
 SINETABLE(2048);
40 40
 SINETABLE(4096);
41
+SINETABLE(8192);
41 42
 #else
42 43
 #include "libavcodec/sinewin_tables.h"
43 44
 #endif
... ...
@@ -45,7 +46,7 @@ SINETABLE(4096);
45 45
 SINETABLE_CONST float * const ff_sine_windows[] = {
46 46
     NULL, NULL, NULL, NULL, NULL, // unused
47 47
     ff_sine_32 , ff_sine_64 ,
48
-    ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
48
+    ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096, ff_sine_8192
49 49
 };
50 50
 
51 51
 // Generate a sine window.
... ...
@@ -22,32 +22,7 @@
22 22
 #include "libavutil/intreadwrite.h"
23 23
 #include "libavutil/imgutils.h"
24 24
 #include "avcodec.h"
25
-
26
-#define RAS_MAGIC 0x59a66a95
27
-
28
-/* The Old and Standard format types indicate that the image data is
29
- * uncompressed. There is no difference between the two formats. */
30
-#define RT_OLD          0
31
-#define RT_STANDARD     1
32
-
33
-/* The Byte-Encoded format type indicates that the image data is compressed
34
- * using a run-length encoding scheme. */
35
-#define RT_BYTE_ENCODED 2
36
-
37
-/* The RGB format type indicates that the image is uncompressed with reverse
38
- * component order from Old and Standard (RGB vs BGR). */
39
-#define RT_FORMAT_RGB   3
40
-
41
-/* The TIFF and IFF format types indicate that the raster file was originally
42
- * converted from either of these file formats. We do not have any samples or
43
- * documentation of the format details. */
44
-#define RT_FORMAT_TIFF  4
45
-#define RT_FORMAT_IFF   5
46
-
47
-/* The Experimental format type is implementation-specific and is generally an
48
- * indication that the image file does not conform to the Sun Raster file
49
- * format specification. */
50
-#define RT_EXPERIMENTAL 0xffff
25
+#include "sunrast.h"
51 26
 
52 27
 typedef struct SUNRASTContext {
53 28
     AVFrame picture;
54 29
new file mode 100644
... ...
@@ -0,0 +1,56 @@
0
+/*
1
+ * Sun Rasterfile Image Format
2
+ * Copyright (c) 2007, 2008 Ivo van Poorten
3
+ *
4
+ * This file is part of Libav.
5
+ *
6
+ * Libav is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * Libav is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with Libav; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#ifndef AVCODEC_SUNRAST_H
22
+#define AVCODEC_SUNRAST_H
23
+
24
+#define RAS_MAGIC 0x59a66a95
25
+
26
+#define RMT_NONE      0
27
+#define RMT_EQUAL_RGB 1
28
+#define RMT_RAW       2 ///< the data layout of this map type is unknown
29
+
30
+/* The Old and Standard format types indicate that the image data is
31
+ * uncompressed. There is no difference between the two formats. */
32
+#define RT_OLD          0
33
+#define RT_STANDARD     1
34
+
35
+/* The Byte-Encoded format type indicates that the image data is compressed
36
+ * using a run-length encoding scheme. */
37
+#define RT_BYTE_ENCODED 2
38
+#define RLE_TRIGGER 0x80
39
+
40
+/* The RGB format type indicates that the image is uncompressed with reverse
41
+ * component order from Old and Standard (RGB vs BGR). */
42
+#define RT_FORMAT_RGB   3
43
+
44
+/* The TIFF and IFF format types indicate that the raster file was originally
45
+ * converted from either of these file formats. We do not have any samples or
46
+ * documentation of the format details. */
47
+#define RT_FORMAT_TIFF  4
48
+#define RT_FORMAT_IFF   5
49
+
50
+/* The Experimental format type is implementation-specific and is generally an
51
+ * indication that the image file does not conform to the Sun Raster file
52
+ * format specification. */
53
+#define RT_EXPERIMENTAL 0xffff
54
+
55
+#endif /* AVCODEC_SUNRAST_H */
0 56
new file mode 100644
... ...
@@ -0,0 +1,225 @@
0
+/*
1
+ * Sun Rasterfile (.sun/.ras/im{1,8,24}/.sunras) image encoder
2
+ * Copyright (c) 2012 Aneesh Dogra (lionaneesh) <lionaneesh@gmail.com>
3
+ *
4
+ * This file is part of Libav.
5
+ *
6
+ * Libav is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * Libav is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with Libav; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "avcodec.h"
22
+#include "bytestream.h"
23
+#include "internal.h"
24
+#include "sunrast.h"
25
+
26
+typedef struct SUNRASTContext {
27
+    AVFrame picture;
28
+    PutByteContext p;
29
+    int depth;      ///< depth of pixel
30
+    int length;     ///< length (bytes) of image
31
+    int type;       ///< type of file
32
+    int maptype;    ///< type of colormap
33
+    int maplength;  ///< length (bytes) of colormap
34
+    int size;
35
+} SUNRASTContext;
36
+
37
+static void sunrast_image_write_header(AVCodecContext *avctx)
38
+{
39
+    SUNRASTContext *s = avctx->priv_data;
40
+
41
+    bytestream2_put_be32u(&s->p, RAS_MAGIC);
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);
48
+    bytestream2_put_be32u(&s->p, s->maplength);
49
+}
50
+
51
+static void sunrast_image_write_image(AVCodecContext *avctx,
52
+                                      const uint8_t *pixels,
53
+                                      const uint32_t *palette_data,
54
+                                      int linesize)
55
+{
56
+    SUNRASTContext *s = avctx->priv_data;
57
+    const uint8_t *ptr;
58
+    int len, alen, x;
59
+
60
+    if (s->maplength) {     // palettized
61
+        PutByteContext pb_r, pb_g;
62
+        int len = s->maplength / 3;
63
+
64
+        pb_r = s->p;
65
+        bytestream2_skip_p(&s->p, len);
66
+        pb_g = s->p;
67
+        bytestream2_skip_p(&s->p, len);
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
+
78
+    len  = (s->depth * avctx->width + 7) >> 3;
79
+    alen = len + (len & 1);
80
+    ptr  = pixels;
81
+
82
+     if (s->type == RT_BYTE_ENCODED) {
83
+        uint8_t value, value2;
84
+        int run;
85
+        const uint8_t *end = pixels + avctx->height * linesize;
86
+
87
+        ptr = pixels;
88
+
89
+#define GET_VALUE ptr >= end ? 0 : x >= len ? ptr[len-1] : ptr[x]
90
+
91
+        x = 0;
92
+        value2 = GET_VALUE;
93
+        while (ptr < end) {
94
+            run = 1;
95
+            value = value2;
96
+            x++;
97
+            if (x >= alen) {
98
+                x = 0;
99
+                ptr += linesize;
100
+            }
101
+
102
+            value2 = GET_VALUE;
103
+            while (value2 == value && run < 256 && ptr < end) {
104
+                x++;
105
+                run++;
106
+                if (x >= alen) {
107
+                    x = 0;
108
+                    ptr += linesize;
109
+                }
110
+                value2 = GET_VALUE;
111
+            }
112
+
113
+            if (run > 2 || value == RLE_TRIGGER) {
114
+                bytestream2_put_byteu(&s->p, RLE_TRIGGER);
115
+                bytestream2_put_byteu(&s->p, run - 1);
116
+                if (run > 1)
117
+                    bytestream2_put_byteu(&s->p, value);
118
+            } else if (run == 1) {
119
+                bytestream2_put_byteu(&s->p, value);
120
+            } else
121
+                bytestream2_put_be16u(&s->p, (value << 8) | value);
122
+        }
123
+
124
+        // update data length for header
125
+        s->length = bytestream2_tell_p(&s->p) - 32 - s->maplength;
126
+    } else {
127
+        int y;
128
+        for (y = 0; y < avctx->height; y++) {
129
+            bytestream2_put_buffer(&s->p, ptr, len);
130
+            if (len < alen)
131
+                bytestream2_put_byteu(&s->p, 0);
132
+            ptr += linesize;
133
+        }
134
+    }
135
+}
136
+
137
+static av_cold int sunrast_encode_init(AVCodecContext *avctx)
138
+{
139
+    SUNRASTContext *s = avctx->priv_data;
140
+
141
+    switch (avctx->coder_type) {
142
+    case FF_CODER_TYPE_RLE:
143
+        s->type = RT_BYTE_ENCODED;
144
+        break;
145
+    case FF_CODER_TYPE_RAW:
146
+        s->type = RT_STANDARD;
147
+        break;
148
+    default:
149
+        av_log(avctx, AV_LOG_ERROR, "invalid coder_type\n");
150
+        return AVERROR(EINVAL);
151
+    }
152
+
153
+    avctx->coded_frame            = &s->picture;
154
+    avctx->coded_frame->key_frame = 1;
155
+    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
156
+    s->maptype                    = RMT_NONE;
157
+    s->maplength                  = 0;
158
+
159
+    switch (avctx->pix_fmt) {
160
+    case PIX_FMT_MONOWHITE:
161
+        s->depth = 1;
162
+        break;
163
+    case PIX_FMT_PAL8 :
164
+        s->maptype   = RMT_EQUAL_RGB;
165
+        s->maplength = 3 * 256;
166
+    case PIX_FMT_GRAY8:
167
+        s->depth = 8;
168
+        break;
169
+    case PIX_FMT_BGR24:
170
+        s->depth = 24;
171
+        break;
172
+    default:
173
+        return AVERROR_BUG;
174
+    }
175
+    s->length = avctx->height * (FFALIGN(avctx->width * s->depth, 16) >> 3);
176
+    s->size   = 32 + s->maplength +
177
+                s->length * (s->type == RT_BYTE_ENCODED ? 2 : 1);
178
+
179
+    return 0;
180
+}
181
+
182
+static int sunrast_encode_frame(AVCodecContext *avctx,  AVPacket *avpkt,
183
+                                const AVFrame *frame, int *got_packet_ptr)
184
+{
185
+    SUNRASTContext *s = avctx->priv_data;
186
+    int ret;
187
+
188
+    if ((ret = ff_alloc_packet(avpkt, s->size)) < 0)
189
+        return ret;
190
+
191
+    bytestream2_init_writer(&s->p, avpkt->data, avpkt->size);
192
+    sunrast_image_write_header(avctx);
193
+    sunrast_image_write_image(avctx, frame->data[0],
194
+                              (const uint32_t *)frame->data[1],
195
+                              frame->linesize[0]);
196
+    // update data length in header after RLE
197
+    if (s->type == RT_BYTE_ENCODED)
198
+        AV_WB32(&avpkt->data[16], s->length);
199
+
200
+    *got_packet_ptr = 1;
201
+    avpkt->size = bytestream2_tell_p(&s->p);
202
+    return 0;
203
+}
204
+
205
+static const AVCodecDefault sunrast_defaults[] = {
206
+     { "coder", "rle" },
207
+     { NULL },
208
+};
209
+
210
+AVCodec ff_sunrast_encoder = {
211
+    .name           = "sunrast",
212
+    .type           = AVMEDIA_TYPE_VIDEO,
213
+    .id             = CODEC_ID_SUNRAST,
214
+    .priv_data_size = sizeof(SUNRASTContext),
215
+    .init           = sunrast_encode_init,
216
+    .encode2        = sunrast_encode_frame,
217
+    .defaults       = sunrast_defaults,
218
+    .pix_fmts       = (const enum PixelFormat[]){ PIX_FMT_BGR24,
219
+                                                  PIX_FMT_PAL8,
220
+                                                  PIX_FMT_GRAY8,
221
+                                                  PIX_FMT_MONOWHITE,
222
+                                                  PIX_FMT_NONE },
223
+    .long_name      = NULL_IF_CONFIG_SMALL("Sun Rasterfile image"),
224
+};
... ...
@@ -497,14 +497,19 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
497 497
     return 0;
498 498
 }
499 499
 
500
-static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
501
-    int buf_size, void *data)
500
+static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
501
+                             const AVFrame *pict, int *got_packet)
502 502
 {
503 503
     SVQ1Context * const s = avctx->priv_data;
504
-    AVFrame *pict = data;
505 504
     AVFrame * const p= (AVFrame*)&s->picture;
506 505
     AVFrame temp;
507
-    int i;
506
+    int i, ret;
507
+
508
+    if (!pkt->data &&
509
+        (ret = av_new_packet(pkt, s->y_block_width*s->y_block_height*MAX_MB_BYTES*3 + FF_MIN_BUFFER_SIZE) < 0)) {
510
+        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
511
+        return ret;
512
+    }
508 513
 
509 514
     if(avctx->pix_fmt != PIX_FMT_YUV410P){
510 515
         av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
... ...
@@ -521,7 +526,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
521 521
     s->current_picture= s->last_picture;
522 522
     s->last_picture= temp;
523 523
 
524
-    init_put_bits(&s->pb, buf, buf_size);
524
+    init_put_bits(&s->pb, pkt->data, pkt->size);
525 525
 
526 526
     *p = *pict;
527 527
     p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
... ...
@@ -542,7 +547,12 @@ static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
542 542
 
543 543
     flush_put_bits(&s->pb);
544 544
 
545
-    return put_bits_count(&s->pb) / 8;
545
+    pkt->size = put_bits_count(&s->pb) / 8;
546
+    if (p->pict_type == AV_PICTURE_TYPE_I)
547
+        pkt->flags |= AV_PKT_FLAG_KEY;
548
+    *got_packet = 1;
549
+
550
+    return 0;
546 551
 }
547 552
 
548 553
 static av_cold int svq1_encode_end(AVCodecContext *avctx)
... ...
@@ -578,7 +588,7 @@ AVCodec ff_svq1_encoder = {
578 578
     .id             = CODEC_ID_SVQ1,
579 579
     .priv_data_size = sizeof(SVQ1Context),
580 580
     .init           = svq1_encode_init,
581
-    .encode         = svq1_encode_frame,
581
+    .encode2        = svq1_encode_frame,
582 582
     .close          = svq1_encode_end,
583 583
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE},
584 584
     .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
... ...
@@ -39,7 +39,7 @@
39 39
 
40 40
 #define MAX_ORDER 16
41 41
 typedef struct TTAFilter {
42
-    int32_t shift, round, error, mode;
42
+    int32_t shift, round, error;
43 43
     int32_t qm[MAX_ORDER];
44 44
     int32_t dx[MAX_ORDER];
45 45
     int32_t dl[MAX_ORDER];
... ...
@@ -84,19 +84,18 @@ static const uint32_t shift_1[] = {
84 84
 
85 85
 static const uint32_t * const shift_16 = shift_1 + 4;
86 86
 
87
-static const int32_t ttafilter_configs[4][2] = {
88
-    {10, 1},
89
-    {9, 1},
90
-    {10, 1},
91
-    {12, 0}
87
+static const int32_t ttafilter_configs[4] = {
88
+    10,
89
+    9,
90
+    10,
91
+    12
92 92
 };
93 93
 
94
-static void ttafilter_init(TTAFilter *c, int32_t shift, int32_t mode) {
94
+static void ttafilter_init(TTAFilter *c, int32_t shift) {
95 95
     memset(c, 0, sizeof(TTAFilter));
96 96
     c->shift = shift;
97 97
    c->round = shift_1[shift-1];
98 98
 //    c->round = 1 << (shift - 1);
99
-    c->mode = mode;
100 99
 }
101 100
 
102 101
 // FIXME: copy paste from original
... ...
@@ -111,9 +110,8 @@ static inline void memshl(register int32_t *a, register int32_t *b) {
111 111
     *a = *b;
112 112
 }
113 113
 
114
-// FIXME: copy paste from original
115
-// mode=1 encoder, mode=0 decoder
116
-static inline void ttafilter_process(TTAFilter *c, int32_t *in, int32_t mode) {
114
+static inline void ttafilter_process(TTAFilter *c, int32_t *in)
115
+{
117 116
     register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round;
118 117
 
119 118
     if (!c->error) {
... ...
@@ -151,22 +149,13 @@ static inline void ttafilter_process(TTAFilter *c, int32_t *in, int32_t mode) {
151 151
     *(dx-2) = ((*(dl-3) >> 30) | 1) << 1;
152 152
     *(dx-3) = ((*(dl-4) >> 30) | 1);
153 153
 
154
-    // compress
155
-    if (mode) {
156
-        *dl = *in;
157
-        *in -= (sum >> c->shift);
158
-        c->error = *in;
159
-    } else {
160
-        c->error = *in;
161
-        *in += (sum >> c->shift);
162
-        *dl = *in;
163
-    }
154
+    c->error = *in;
155
+    *in += (sum >> c->shift);
156
+    *dl = *in;
164 157
 
165
-    if (c->mode) {
166
-        *(dl-1) = *dl - *(dl-1);
167
-        *(dl-2) = *(dl-1) - *(dl-2);
168
-        *(dl-3) = *(dl-2) - *(dl-3);
169
-    }
158
+    *(dl-1) = *dl - *(dl-1);
159
+    *(dl-2) = *(dl-1) - *(dl-2);
160
+    *(dl-3) = *(dl-2) - *(dl-3);
170 161
 
171 162
     memshl(c->dl, c->dl + 1);
172 163
     memshl(c->dx, c->dx + 1);
... ...
@@ -368,7 +357,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
368 368
     // init per channel states
369 369
     for (i = 0; i < s->channels; i++) {
370 370
         s->ch_ctx[i].predictor = 0;
371
-        ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1][0], ttafilter_configs[s->bps-1][1]);
371
+        ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]);
372 372
         rice_init(&s->ch_ctx[i].rice, 10, 10);
373 373
     }
374 374
 
... ...
@@ -422,11 +411,10 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
422 422
         }
423 423
 
424 424
         // extract coded value
425
-#define UNFOLD(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1))
426
-        *p = UNFOLD(value);
425
+        *p = 1 + ((value >> 1) ^ ((value & 1) - 1));
427 426
 
428 427
         // run hybrid filter
429
-        ttafilter_process(filter, p, 0);
428
+        ttafilter_process(filter, p);
430 429
 
431 430
         // fixed order prediction
432 431
 #define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k)
... ...
@@ -23,6 +23,7 @@
23 23
 
24 24
 #include "avcodec.h"
25 25
 #include "bytestream.h"
26
+#include "internal.h"
26 27
 
27 28
 static av_cold int encode_init(AVCodecContext *avctx)
28 29
 {
... ...
@@ -44,25 +45,24 @@ static av_cold int encode_init(AVCodecContext *avctx)
44 44
     return 0;
45 45
 }
46 46
 
47
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
48
-                        int buf_size, void *data)
47
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
48
+                        const AVFrame *pic, int *got_packet)
49 49
 {
50
-    const AVFrame *pic = data;
51 50
     int aligned_width = ((avctx->width + 47) / 48) * 48;
52 51
     int stride = aligned_width * 8 / 3;
53 52
     int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4;
54
-    int h, w;
53
+    int h, w, ret;
55 54
     const uint16_t *y = (const uint16_t*)pic->data[0];
56 55
     const uint16_t *u = (const uint16_t*)pic->data[1];
57 56
     const uint16_t *v = (const uint16_t*)pic->data[2];
58 57
     PutByteContext p;
59 58
 
60
-    if (buf_size < avctx->height * stride) {
61
-        av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
62
-        return AVERROR(ENOMEM);
59
+    if ((ret = ff_alloc_packet(pkt, avctx->height * stride)) < 0) {
60
+        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
61
+        return ret;
63 62
     }
64 63
 
65
-    bytestream2_init_writer(&p, buf, buf_size);
64
+    bytestream2_init_writer(&p, pkt->data, pkt->size);
66 65
 
67 66
 #define CLIP(v) av_clip(v, 4, 1019)
68 67
 
... ...
@@ -104,7 +104,9 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
104 104
         v += pic->linesize[2] / 2 - avctx->width / 2;
105 105
     }
106 106
 
107
-    return bytestream2_tell_p(&p);
107
+    pkt->flags |= AV_PKT_FLAG_KEY;
108
+    *got_packet = 1;
109
+    return 0;
108 110
 }
109 111
 
110 112
 static av_cold int encode_close(AVCodecContext *avctx)
... ...
@@ -119,7 +121,7 @@ AVCodec ff_v210_encoder = {
119 119
     .type           = AVMEDIA_TYPE_VIDEO,
120 120
     .id             = CODEC_ID_V210,
121 121
     .init           = encode_init,
122
-    .encode         = encode_frame,
122
+    .encode2        = encode_frame,
123 123
     .close          = encode_close,
124 124
     .pix_fmts       = (const enum PixelFormat[]){PIX_FMT_YUV422P10, PIX_FMT_NONE},
125 125
     .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
... ...
@@ -105,7 +105,7 @@
105 105
 #define MAX_FRAMESIZE  32768                                 ///< maximum compressed frame size
106 106
 
107 107
 #define WMAPRO_BLOCK_MIN_BITS  6                                           ///< log2 of min block size
108
-#define WMAPRO_BLOCK_MAX_BITS 12                                           ///< log2 of max block size
108
+#define WMAPRO_BLOCK_MAX_BITS 13                                           ///< log2 of max block size
109 109
 #define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS)                 ///< maximum block size
110 110
 #define WMAPRO_BLOCK_SIZES    (WMAPRO_BLOCK_MAX_BITS - WMAPRO_BLOCK_MIN_BITS + 1) ///< possible block sizes
111 111
 
... ...
@@ -276,7 +276,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
276 276
     WMAProDecodeCtx *s = avctx->priv_data;
277 277
     uint8_t *edata_ptr = avctx->extradata;
278 278
     unsigned int channel_mask;
279
-    int i;
279
+    int i, bits;
280 280
     int log2_max_num_subframes;
281 281
     int num_possible_block_sizes;
282 282
 
... ...
@@ -310,8 +310,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
310 310
     s->len_prefix  = (s->decode_flags & 0x40);
311 311
 
312 312
     /** get frame len */
313
-    s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
314
-                                                          3, s->decode_flags);
313
+    bits = ff_wma_get_frame_len_bits(avctx->sample_rate, 3, s->decode_flags);
314
+    if (bits > WMAPRO_BLOCK_MAX_BITS) {
315
+        av_log_missing_feature(avctx, "14-bits block sizes", 1);
316
+        return AVERROR_INVALIDDATA;
317
+    }
318
+    s->samples_per_frame = 1 << bits;
315 319
 
316 320
     /** subframe info */
317 321
     log2_max_num_subframes       = ((s->decode_flags & 0x38) >> 3);
... ...
@@ -24,6 +24,7 @@
24 24
 #include "libavutil/pixdesc.h"
25 25
 #include "avcodec.h"
26 26
 #include "bytestream.h"
27
+#include "internal.h"
27 28
 #include "xwd.h"
28 29
 
29 30
 #define WINDOW_NAME         "lavcxwdenc"
... ...
@@ -38,16 +39,15 @@ static av_cold int xwd_encode_init(AVCodecContext *avctx)
38 38
     return 0;
39 39
 }
40 40
 
41
-static int xwd_encode_frame(AVCodecContext *avctx, uint8_t *buf,
42
-                            int buf_size, void *data)
41
+static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
42
+                            const AVFrame *p, int *got_packet)
43 43
 {
44
-    AVFrame *p = data;
45 44
     enum PixelFormat pix_fmt = avctx->pix_fmt;
46 45
     uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
47 46
     uint32_t rgb[3] = { 0 };
48 47
     uint32_t header_size;
49
-    int i, out_size;
50
-    uint8_t *ptr;
48
+    int i, out_size, ret;
49
+    uint8_t *ptr, *buf;
51 50
 
52 51
     pixdepth = av_get_bits_per_pixel(&av_pix_fmt_descriptors[pix_fmt]);
53 52
     if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BE)
... ...
@@ -146,10 +146,11 @@ static int xwd_encode_frame(AVCodecContext *avctx, uint8_t *buf,
146 146
     header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE;
147 147
     out_size    = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize;
148 148
 
149
-    if (buf_size < out_size) {
149
+    if ((ret = ff_alloc_packet(pkt, out_size)) < 0) {
150 150
         av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
151
-        return AVERROR(ENOMEM);
151
+        return ret;
152 152
     }
153
+    buf = pkt->data;
153 154
 
154 155
     avctx->coded_frame->key_frame = 1;
155 156
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
... ...
@@ -204,7 +205,9 @@ static int xwd_encode_frame(AVCodecContext *avctx, uint8_t *buf,
204 204
         ptr += p->linesize[0];
205 205
     }
206 206
 
207
-    return out_size;
207
+    pkt->flags |= AV_PKT_FLAG_KEY;
208
+    *got_packet = 1;
209
+    return 0;
208 210
 }
209 211
 
210 212
 static av_cold int xwd_encode_close(AVCodecContext *avctx)
... ...
@@ -219,7 +222,7 @@ AVCodec ff_xwd_encoder = {
219 219
     .type         = AVMEDIA_TYPE_VIDEO,
220 220
     .id           = CODEC_ID_XWD,
221 221
     .init         = xwd_encode_init,
222
-    .encode       = xwd_encode_frame,
222
+    .encode2      = xwd_encode_frame,
223 223
     .close        = xwd_encode_close,
224 224
     .pix_fmts     = (const enum PixelFormat[]) { PIX_FMT_BGRA,
225 225
                                                  PIX_FMT_RGBA,
... ...
@@ -29,16 +29,17 @@
29 29
 #define APE_TAG_FOOTER_BYTES          32
30 30
 #define APE_TAG_FLAG_CONTAINS_HEADER  (1 << 31)
31 31
 #define APE_TAG_FLAG_IS_HEADER        (1 << 29)
32
+#define APE_TAG_FLAG_IS_BINARY        (1 << 1)
32 33
 
33 34
 static int ape_tag_read_field(AVFormatContext *s)
34 35
 {
35 36
     AVIOContext *pb = s->pb;
36 37
     uint8_t key[1024], *value;
37
-    uint32_t size;
38
+    uint32_t size, flags;
38 39
     int i, c;
39 40
 
40 41
     size = avio_rl32(pb);  /* field size */
41
-    avio_skip(pb, 4);      /* field flags */
42
+    flags = avio_rl32(pb); /* field flags */
42 43
     for (i = 0; i < sizeof(key) - 1; i++) {
43 44
         c = avio_r8(pb);
44 45
         if (c < 0x20 || c > 0x7E)
... ...
@@ -53,12 +54,30 @@ static int ape_tag_read_field(AVFormatContext *s)
53 53
     }
54 54
     if (size >= UINT_MAX)
55 55
         return -1;
56
-    value = av_malloc(size+1);
57
-    if (!value)
58
-        return AVERROR(ENOMEM);
59
-    avio_read(pb, value, size);
60
-    value[size] = 0;
61
-    av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
56
+    if (flags & APE_TAG_FLAG_IS_BINARY) {
57
+        uint8_t filename[1024];
58
+        AVStream *st = avformat_new_stream(s, NULL);
59
+        if (!st)
60
+            return AVERROR(ENOMEM);
61
+        avio_get_str(pb, INT_MAX, filename, sizeof(filename));
62
+        st->codec->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
63
+        if (!st->codec->extradata)
64
+            return AVERROR(ENOMEM);
65
+        if (avio_read(pb, st->codec->extradata, size) != size) {
66
+            av_freep(&st->codec->extradata);
67
+            return AVERROR(EIO);
68
+        }
69
+        st->codec->extradata_size = size;
70
+        av_dict_set(&st->metadata, key, filename, 0);
71
+        st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT;
72
+    } else {
73
+        value = av_malloc(size+1);
74
+        if (!value)
75
+            return AVERROR(ENOMEM);
76
+        c = avio_read(pb, value, size);
77
+        value[c] = 0;
78
+        av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
79
+    }
62 80
     return 0;
63 81
 }
64 82
 
... ...
@@ -62,9 +62,8 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
62 62
 {
63 63
     CDXLDemuxContext *cdxl = s->priv_data;
64 64
     AVIOContext *pb = s->pb;
65
-    uint32_t current_size;
66
-    uint16_t audio_size, palette_size;
67
-    int32_t  video_size;
65
+    uint32_t current_size, video_size, image_size;
66
+    uint16_t audio_size, palette_size, width, height;
68 67
     int64_t  pos;
69 68
     int      ret;
70 69
 
... ...
@@ -81,14 +80,17 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
81 81
     }
82 82
 
83 83
     current_size = AV_RB32(&cdxl->header[2]);
84
+    width        = AV_RB16(&cdxl->header[14]);
85
+    height       = AV_RB16(&cdxl->header[16]);
84 86
     palette_size = AV_RB16(&cdxl->header[20]);
85 87
     audio_size   = AV_RB16(&cdxl->header[22]);
88
+    image_size   = FFALIGN(width, 16) * height * cdxl->header[19] / 8;
89
+    video_size   = palette_size + image_size;
86 90
 
87 91
     if (palette_size > 512)
88 92
         return AVERROR_INVALIDDATA;
89
-    if (current_size < audio_size + palette_size + CDXL_HEADER_SIZE)
93
+    if (current_size < (uint64_t)audio_size + video_size + CDXL_HEADER_SIZE)
90 94
         return AVERROR_INVALIDDATA;
91
-    video_size   = current_size - audio_size - CDXL_HEADER_SIZE;
92 95
 
93 96
     if (cdxl->read_chunk && audio_size) {
94 97
         if (cdxl->audio_stream_index == -1) {
... ...
@@ -121,8 +123,8 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
121 121
             st->codec->codec_type    = AVMEDIA_TYPE_VIDEO;
122 122
             st->codec->codec_tag     = 0;
123 123
             st->codec->codec_id      = CODEC_ID_CDXL;
124
-            st->codec->width         = AV_RB16(&cdxl->header[14]);
125
-            st->codec->height        = AV_RB16(&cdxl->header[16]);
124
+            st->codec->width         = width;
125
+            st->codec->height        = height;
126 126
             cdxl->video_stream_index = st->index;
127 127
             avpriv_set_pts_info(st, 63, cdxl->fps.den, cdxl->fps.num);
128 128
         }
... ...
@@ -141,6 +143,8 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
141 141
         cdxl->read_chunk   = audio_size;
142 142
     }
143 143
 
144
+    if (!cdxl->read_chunk)
145
+        avio_skip(pb, current_size - audio_size - video_size - CDXL_HEADER_SIZE);
144 146
     return ret;
145 147
 }
146 148
 
... ...
@@ -520,7 +520,8 @@ AVOutputFormat ff_image2_muxer = {
520 520
     .name           = "image2",
521 521
     .long_name      = NULL_IF_CONFIG_SMALL("image2 sequence"),
522 522
     .extensions     = "bmp,dpx,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png,"
523
-                      "ppm,sgi,tga,tif,tiff,jp2,j2c,xwd",
523
+                      "ppm,sgi,tga,tif,tiff,jp2,j2c,xwd,sun,ras,rs,im1,im8,im24,"
524
+                      "sunras",
524 525
     .priv_data_size = sizeof(VideoData),
525 526
     .video_codec    = CODEC_ID_MJPEG,
526 527
     .write_header   = write_header,
... ...
@@ -298,6 +298,9 @@ static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterS
298 298
         }
299 299
 }
300 300
 
301
+#define accumulate_bit(acc, val) \
302
+    acc <<= 1; \
303
+    acc |= (val) >= (128 + 110)
301 304
 #define output_pixel(pos, acc) \
302 305
     if (target == PIX_FMT_MONOBLACK) { \
303 306
         pos = acc; \
... ...
@@ -314,7 +317,6 @@ yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
314 314
                       int y, enum PixelFormat target)
315 315
 {
316 316
     const uint8_t * const d128=dither_8x8_220[y&7];
317
-    uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
318 317
     int i;
319 318
     unsigned acc = 0;
320 319
 
... ...
@@ -333,8 +335,8 @@ yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
333 333
             Y1 = av_clip_uint8(Y1);
334 334
             Y2 = av_clip_uint8(Y2);
335 335
         }
336
-        acc += acc + g[Y1 + d128[(i + 0) & 7]];
337
-        acc += acc + g[Y2 + d128[(i + 1) & 7]];
336
+        accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
337
+        accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
338 338
         if ((i & 7) == 6) {
339 339
             output_pixel(*dest++, acc);
340 340
         }
... ...
@@ -350,19 +352,29 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
350 350
 {
351 351
     const int16_t *buf0  = buf[0],  *buf1  = buf[1];
352 352
     const uint8_t * const d128 = dither_8x8_220[y & 7];
353
-    uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
354 353
     int  yalpha1 = 4095 - yalpha;
355 354
     int i;
356 355
 
357 356
     for (i = 0; i < dstW - 7; i += 8) {
358
-        int acc =    g[((buf0[i    ] * yalpha1 + buf1[i    ] * yalpha) >> 19) + d128[0]];
359
-        acc += acc + g[((buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19) + d128[1]];
360
-        acc += acc + g[((buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19) + d128[2]];
361
-        acc += acc + g[((buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19) + d128[3]];
362
-        acc += acc + g[((buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19) + d128[4]];
363
-        acc += acc + g[((buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19) + d128[5]];
364
-        acc += acc + g[((buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19) + d128[6]];
365
-        acc += acc + g[((buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19) + d128[7]];
357
+        int Y, acc = 0;
358
+
359
+        Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
360
+        accumulate_bit(acc, Y + d128[0]);
361
+        Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
362
+        accumulate_bit(acc, Y + d128[1]);
363
+        Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
364
+        accumulate_bit(acc, Y + d128[2]);
365
+        Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
366
+        accumulate_bit(acc, Y + d128[3]);
367
+        Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
368
+        accumulate_bit(acc, Y + d128[4]);
369
+        Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
370
+        accumulate_bit(acc, Y + d128[5]);
371
+        Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
372
+        accumulate_bit(acc, Y + d128[6]);
373
+        Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
374
+        accumulate_bit(acc, Y + d128[7]);
375
+
366 376
         output_pixel(*dest++, acc);
367 377
     }
368 378
 }
... ...
@@ -374,23 +386,26 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
374 374
                       int uvalpha, int y, enum PixelFormat target)
375 375
 {
376 376
     const uint8_t * const d128 = dither_8x8_220[y & 7];
377
-    uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
378 377
     int i;
379 378
 
380 379
     for (i = 0; i < dstW - 7; i += 8) {
381
-        int acc =    g[((buf0[i    ] + 64) >> 7) + d128[0]];
382
-        acc += acc + g[((buf0[i + 1] + 64) >> 7) + d128[1]];
383
-        acc += acc + g[((buf0[i + 2] + 64) >> 7) + d128[2]];
384
-        acc += acc + g[((buf0[i + 3] + 64) >> 7) + d128[3]];
385
-        acc += acc + g[((buf0[i + 4] + 64) >> 7) + d128[4]];
386
-        acc += acc + g[((buf0[i + 5] + 64) >> 7) + d128[5]];
387
-        acc += acc + g[((buf0[i + 6] + 64) >> 7) + d128[6]];
388
-        acc += acc + g[((buf0[i + 7] + 64) >> 7) + d128[7]];
380
+        int acc = 0;
381
+
382
+        accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
383
+        accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
384
+        accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
385
+        accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
386
+        accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
387
+        accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
388
+        accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
389
+        accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
390
+
389 391
         output_pixel(*dest++, acc);
390 392
     }
391 393
 }
392 394
 
393 395
 #undef output_pixel
396
+#undef accumulate_bit
394 397
 
395 398
 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
396 399
 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
... ...
@@ -358,11 +358,10 @@ typedef struct SwsContext {
358 358
 #define U_TEMP                "11*8+4*4*256*2+24"
359 359
 #define V_TEMP                "11*8+4*4*256*2+32"
360 360
 #define Y_TEMP                "11*8+4*4*256*2+40"
361
-#define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
362
-#define UV_OFF_PX             "11*8+4*4*256*3+48"
363
-#define UV_OFF_BYTE           "11*8+4*4*256*3+56"
364
-#define DITHER16              "11*8+4*4*256*3+64"
365
-#define DITHER32              "11*8+4*4*256*3+80"
361
+#define UV_OFF_PX             "11*8+4*4*256*2+48"
362
+#define UV_OFF_BYTE           "11*8+4*4*256*2+56"
363
+#define DITHER16              "11*8+4*4*256*2+64"
364
+#define DITHER32              "11*8+4*4*256*2+80"
366 365
 
367 366
     DECLARE_ALIGNED(8, uint64_t, redDither);
368 367
     DECLARE_ALIGNED(8, uint64_t, greenDither);
... ...
@@ -384,7 +383,6 @@ typedef struct SwsContext {
384 384
     DECLARE_ALIGNED(8, uint64_t, u_temp);
385 385
     DECLARE_ALIGNED(8, uint64_t, v_temp);
386 386
     DECLARE_ALIGNED(8, uint64_t, y_temp);
387
-    int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
388 387
     // alignment of these values is not necessary, but merely here
389 388
     // to maintain the same offset across x8632 and x86-64. Once we
390 389
     // use proper offset macros in the asm, they can be removed.
... ...
@@ -423,6 +421,7 @@ typedef struct SwsContext {
423 423
 #if HAVE_VIS
424 424
     DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
425 425
 #endif
426
+    int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
426 427
     int use_mmx_vfilter;
427 428
 
428 429
     /* function pointers for swScale() */
... ...
@@ -342,7 +342,7 @@ static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter,
342 342
         "movq                      %%mm2, "U_TEMP"(%0)  \n\t"
343 343
         "movq                      %%mm4, "V_TEMP"(%0)  \n\t"
344 344
         "movq                      %%mm5, "Y_TEMP"(%0)  \n\t"
345
-        YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET)
345
+        YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET)
346 346
         "movq               "Y_TEMP"(%0), %%mm5         \n\t"
347 347
         "psraw                        $3, %%mm1         \n\t"
348 348
         "psraw                        $3, %%mm7         \n\t"
... ...
@@ -372,7 +372,7 @@ static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter,
372 372
     if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
373 373
         YSCALEYUV2PACKEDX
374 374
         YSCALEYUV2RGBX
375
-        YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7)
375
+        YSCALEYUV2PACKEDX_YA(LUM_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7)
376 376
         "psraw                        $3, %%mm1         \n\t"
377 377
         "psraw                        $3, %%mm7         \n\t"
378 378
         "packuswb                  %%mm7, %%mm1         \n\t"
... ...
@@ -1162,14 +1162,15 @@ static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2],
1162 1162
  * YV12 to RGB without scaling or interpolating
1163 1163
  */
1164 1164
 static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0,
1165
-                                const int16_t *ubuf[2], const int16_t *bguf[2],
1165
+                                const int16_t *ubuf[2], const int16_t *vbuf[2],
1166 1166
                                 const int16_t *abuf0, uint8_t *dest,
1167 1167
                                 int dstW, int uvalpha, int y)
1168 1168
 {
1169
-    const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
1169
+    const int16_t *ubuf0 = ubuf[0];
1170 1170
     const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1171 1171
 
1172 1172
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1173
+        const int16_t *ubuf1 = ubuf[0];
1173 1174
         if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1174 1175
             __asm__ volatile(
1175 1176
                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
... ...
@@ -1198,6 +1199,7 @@ static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0,
1198 1198
             );
1199 1199
         }
1200 1200
     } else {
1201
+        const int16_t *ubuf1 = ubuf[1];
1201 1202
         if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1202 1203
             __asm__ volatile(
1203 1204
                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
... ...
@@ -1229,14 +1231,15 @@ static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0,
1229 1229
 }
1230 1230
 
1231 1231
 static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0,
1232
-                                const int16_t *ubuf[2], const int16_t *bguf[2],
1232
+                                const int16_t *ubuf[2], const int16_t *vbuf[2],
1233 1233
                                 const int16_t *abuf0, uint8_t *dest,
1234 1234
                                 int dstW, int uvalpha, int y)
1235 1235
 {
1236
-    const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
1236
+    const int16_t *ubuf0 = ubuf[0];
1237 1237
     const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1238 1238
 
1239 1239
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1240
+        const int16_t *ubuf1 = ubuf[0];
1240 1241
         __asm__ volatile(
1241 1242
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1242 1243
             "mov        %4, %%"REG_b"               \n\t"
... ...
@@ -1250,6 +1253,7 @@ static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0,
1250 1250
                "a" (&c->redDither)
1251 1251
         );
1252 1252
     } else {
1253
+        const int16_t *ubuf1 = ubuf[1];
1253 1254
         __asm__ volatile(
1254 1255
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1255 1256
             "mov        %4, %%"REG_b"               \n\t"
... ...
@@ -1266,14 +1270,15 @@ static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0,
1266 1266
 }
1267 1267
 
1268 1268
 static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,
1269
-                                 const int16_t *ubuf[2], const int16_t *bguf[2],
1269
+                                 const int16_t *ubuf[2], const int16_t *vbuf[2],
1270 1270
                                  const int16_t *abuf0, uint8_t *dest,
1271 1271
                                  int dstW, int uvalpha, int y)
1272 1272
 {
1273
-    const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
1273
+    const int16_t *ubuf0 = ubuf[0];
1274 1274
     const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1275 1275
 
1276 1276
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1277
+        const int16_t *ubuf1 = ubuf[0];
1277 1278
         __asm__ volatile(
1278 1279
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1279 1280
             "mov        %4, %%"REG_b"               \n\t"
... ...
@@ -1293,6 +1298,7 @@ static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,
1293 1293
                "a" (&c->redDither)
1294 1294
         );
1295 1295
     } else {
1296
+        const int16_t *ubuf1 = ubuf[1];
1296 1297
         __asm__ volatile(
1297 1298
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1298 1299
             "mov        %4, %%"REG_b"               \n\t"
... ...
@@ -1315,14 +1321,15 @@ static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,
1315 1315
 }
1316 1316
 
1317 1317
 static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0,
1318
-                                 const int16_t *ubuf[2], const int16_t *bguf[2],
1318
+                                 const int16_t *ubuf[2], const int16_t *vbuf[2],
1319 1319
                                  const int16_t *abuf0, uint8_t *dest,
1320 1320
                                  int dstW, int uvalpha, int y)
1321 1321
 {
1322
-    const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
1322
+    const int16_t *ubuf0 = ubuf[0];
1323 1323
     const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1324 1324
 
1325 1325
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1326
+        const int16_t *ubuf1 = ubuf[0];
1326 1327
         __asm__ volatile(
1327 1328
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1328 1329
             "mov        %4, %%"REG_b"               \n\t"
... ...
@@ -1342,6 +1349,7 @@ static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0,
1342 1342
                "a" (&c->redDither)
1343 1343
         );
1344 1344
     } else {
1345
+        const int16_t *ubuf1 = ubuf[1];
1345 1346
         __asm__ volatile(
1346 1347
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1347 1348
             "mov        %4, %%"REG_b"               \n\t"
... ...
@@ -1401,14 +1409,15 @@ static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0,
1401 1401
 #define YSCALEYUV2PACKED1b(index, c)  REAL_YSCALEYUV2PACKED1b(index, c)
1402 1402
 
1403 1403
 static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0,
1404
-                                  const int16_t *ubuf[2], const int16_t *bguf[2],
1404
+                                  const int16_t *ubuf[2], const int16_t *vbuf[2],
1405 1405
                                   const int16_t *abuf0, uint8_t *dest,
1406 1406
                                   int dstW, int uvalpha, int y)
1407 1407
 {
1408
-    const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];
1408
+    const int16_t *ubuf0 = ubuf[0];
1409 1409
     const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1410 1410
 
1411 1411
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1412
+        const int16_t *ubuf1 = ubuf[0];
1412 1413
         __asm__ volatile(
1413 1414
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1414 1415
             "mov        %4, %%"REG_b"               \n\t"
... ...
@@ -1421,6 +1430,7 @@ static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0,
1421 1421
                "a" (&c->redDither)
1422 1422
         );
1423 1423
     } else {
1424
+        const int16_t *ubuf1 = ubuf[1];
1424 1425
         __asm__ volatile(
1425 1426
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1426 1427
             "mov        %4, %%"REG_b"               \n\t"