Statistics
| Branch: | Revision:

ffmpeg / libavcodec / indeo3.c @ bc0219fd

History | View | Annotate | Download (37.4 KB)

1 deabd4fd Mike Melanson
/*
2
 * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
3
 * written, produced, and directed by Alan Smithee
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
20
#include <stdio.h>
21
#include <stdlib.h>
22
#include <string.h>
23
#include <unistd.h>
24
25
#include "common.h"
26
#include "avcodec.h"
27
#include "dsputil.h"
28
#include "mpegvideo.h"
29
30
#include "indeo3data.h"
31
32
typedef struct
33
{
34
  unsigned char *Ybuf;
35
  unsigned char *Ubuf;
36
  unsigned char *Vbuf;
37
  unsigned char *the_buf;
38
  unsigned int the_buf_size;
39
  unsigned short y_w, y_h;
40
  unsigned short uv_w, uv_h;
41
} YUVBufs;
42
43
typedef struct Indeo3DecodeContext {
44
    AVCodecContext *avctx;
45
    int width, height;
46
    AVFrame frame;
47
48
    YUVBufs iv_frame[2];
49
    YUVBufs *cur_frame;
50
    YUVBufs *ref_frame;
51
52
    unsigned char *ModPred;
53
    unsigned short *corrector_type;
54
} Indeo3DecodeContext;
55
56
static int corrector_type_0[24] = {
57
  195, 159, 133, 115, 101,  93,  87,  77,
58
  195, 159, 133, 115, 101,  93,  87,  77,
59
  128,  79,  79,  79,  79,  79,  79,  79
60
};
61
62
static int corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
63
64
static void build_modpred(Indeo3DecodeContext *s) 
65
{
66
  int i, j;
67
68
  s->ModPred = (unsigned char *) av_malloc (8 * 128);
69
70
  for (i=0; i < 128; ++i) {
71
    s->ModPred[i+0*128] = (i > 126) ? 254 : 2*((i + 1) - ((i + 1) % 2));
72
    s->ModPred[i+1*128] = (i == 7)  ?  20 : ((i == 119 || i == 120)
73
                                 ? 236 : 2*((i + 2) - ((i + 1) % 3)));
74
    s->ModPred[i+2*128] = (i > 125) ? 248 : 2*((i + 2) - ((i + 2) % 4));
75
    s->ModPred[i+3*128] =                         2*((i + 1) - ((i - 3) % 5));
76
    s->ModPred[i+4*128] = (i == 8)  ?  20 : 2*((i + 1) - ((i - 3) % 6));
77
    s->ModPred[i+5*128] =                         2*((i + 4) - ((i + 3) % 7));
78
    s->ModPred[i+6*128] = (i > 123) ? 240 : 2*((i + 4) - ((i + 4) % 8));
79
    s->ModPred[i+7*128] =                         2*((i + 5) - ((i + 4) % 9));
80
  }
81
82
  s->corrector_type = (unsigned short *) av_malloc (24 * 256 * sizeof(unsigned short));
83
84
  for (i=0; i < 24; ++i) {
85
    for (j=0; j < 256; ++j) {
86
      s->corrector_type[i*256+j] = (j < corrector_type_0[i])
87
                                ? 1 : ((j < 248 || (i == 16 && j == 248))
88
                                       ? 0 : corrector_type_2[j - 248]);
89
    }
90
  }
91
}
92
93
static void iv_Decode_Chunk(Indeo3DecodeContext *s, unsigned char *cur, 
94
  unsigned char *ref, int width, int height, unsigned char *buf1, 
95
  long fflags2, unsigned char *hdr,
96
  unsigned char *buf2, int min_width_160);
97
98
#define min(a,b) ((a) < (b) ? (a) : (b))
99
100
/* ---------------------------------------------------------------------- */
101
static void iv_alloc_frames(Indeo3DecodeContext *s) 
102
{
103
  int luma_width, luma_height, luma_pixels, chroma_width, chroma_height,
104
    chroma_pixels, bufsize, i;
105
106 2ecad8bd Michael Niedermayer
  luma_width   = (s->width  + 3) & (~3);
107
  luma_height  = (s->height + 3) & (~3);
108 deabd4fd Mike Melanson
109
  s->iv_frame[0].y_w = s->iv_frame[0].y_h = 
110
    s->iv_frame[0].the_buf_size = 0;
111
  s->iv_frame[1].y_w = s->iv_frame[1].y_h = 
112
    s->iv_frame[1].the_buf_size = 0;
113
  s->iv_frame[1].the_buf = NULL;
114
115 2ecad8bd Michael Niedermayer
  chroma_width  = ((luma_width >> 2) + 3) & (~3);
116
  chroma_height = ((luma_height>> 2) + 3) & (~3);
117 deabd4fd Mike Melanson
  luma_pixels = luma_width * luma_height;
118
  chroma_pixels = chroma_width * chroma_height;
119
120
  bufsize = luma_pixels * 2 + luma_width * 3 + 
121
    (chroma_pixels + chroma_width) * 4;
122
123
  if((s->iv_frame[0].the_buf = 
124
    (s->iv_frame[0].the_buf_size == 0 ? av_malloc(bufsize) : 
125
      av_realloc(s->iv_frame[0].the_buf, bufsize))) == NULL)
126
    return;
127
  s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width;
128
  s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height;
129
  s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width;
130
  s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height;
131
  s->iv_frame[0].the_buf_size = bufsize;
132
133
  s->iv_frame[0].Ybuf = s->iv_frame[0].the_buf + luma_width;
134
  i = luma_pixels + luma_width * 2;
135
  s->iv_frame[1].Ybuf = s->iv_frame[0].the_buf + i;
136
  i += (luma_pixels + luma_width);
137
  s->iv_frame[0].Ubuf = s->iv_frame[0].the_buf + i;
138
  i += (chroma_pixels + chroma_width);
139
  s->iv_frame[1].Ubuf = s->iv_frame[0].the_buf + i;
140
  i += (chroma_pixels + chroma_width);
141
  s->iv_frame[0].Vbuf = s->iv_frame[0].the_buf + i;
142
  i += (chroma_pixels + chroma_width);
143
  s->iv_frame[1].Vbuf = s->iv_frame[0].the_buf + i;
144
145
  for(i = 1; i <= luma_width; i++)
146
    s->iv_frame[0].Ybuf[-i] = s->iv_frame[1].Ybuf[-i] = 
147
      s->iv_frame[0].Ubuf[-i] = 0x80;
148
149
  for(i = 1; i <= chroma_width; i++) {
150
    s->iv_frame[1].Ubuf[-i] = 0x80;
151
    s->iv_frame[0].Vbuf[-i] = 0x80;
152
    s->iv_frame[1].Vbuf[-i] = 0x80;
153
    s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80;
154
  }
155
}
156
157
/* ---------------------------------------------------------------------- */
158
static void iv_free_func(Indeo3DecodeContext *s) 
159
{
160
  int i;
161
162
  for(i = 0 ; i < 2 ; i++) {
163
    if(s->iv_frame[i].the_buf != NULL) 
164
      av_free(s->iv_frame[i].the_buf);
165
    s->iv_frame[i].Ybuf = s->iv_frame[i].Ubuf = 
166
      s->iv_frame[i].Vbuf = NULL;
167
    s->iv_frame[i].the_buf = NULL;
168
    s->iv_frame[i].the_buf_size = 0;
169
    s->iv_frame[i].y_w = s->iv_frame[i].y_h = 0;
170
    s->iv_frame[i].uv_w = s->iv_frame[i].uv_h = 0;
171
  }
172
173
  av_free(s->ModPred);
174
  av_free(s->corrector_type);
175
}
176
177
/* ---------------------------------------------------------------------- */
178
static unsigned long iv_decode_frame(Indeo3DecodeContext *s, 
179
                                     unsigned char *buf, int buf_size) 
180
{
181
  unsigned int hdr_width, hdr_height,
182
    chroma_width, chroma_height;
183
  unsigned long fflags1, fflags2, fflags3, offs1, offs2, offs3, offs;
184
  unsigned char *hdr_pos, *buf_pos;
185
186
  buf_pos = buf;
187
  buf_pos += 18;
188
189
  fflags1 = le2me_16(*(uint16_t *)buf_pos);
190
  buf_pos += 2;
191
  fflags3 = le2me_32(*(uint32_t *)buf_pos);
192
  buf_pos += 4;
193
  fflags2 = *buf_pos++;
194
  buf_pos += 3;
195
  hdr_height = le2me_16(*(uint16_t *)buf_pos);
196
  buf_pos += 2;
197
  hdr_width = le2me_16(*(uint16_t *)buf_pos);
198
  buf_pos += 2;
199
  chroma_height = ((hdr_height >> 2) + 3) & 0x7ffc;
200
  chroma_width = ((hdr_width >> 2) + 3) & 0x7ffc;
201
  offs1 = le2me_32(*(uint32_t *)buf_pos);
202
  buf_pos += 4;
203
  offs2 = le2me_32(*(uint32_t *)buf_pos);
204
  buf_pos += 4;
205
  offs3 = le2me_32(*(uint32_t *)buf_pos);
206
  buf_pos += 8;
207
  hdr_pos = buf_pos;
208
  if(fflags3 == 0x80) return 4;
209
210
  if(fflags1 & 0x200) {
211
    s->cur_frame = s->iv_frame + 1;
212
    s->ref_frame = s->iv_frame;
213
  } else {
214
    s->cur_frame = s->iv_frame;
215
    s->ref_frame = s->iv_frame + 1;
216
  }
217
218
  buf_pos = buf + 16 + offs1;
219
  offs = le2me_32(*(uint32_t *)buf_pos);
220
  buf_pos += 4;
221
222
  iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, hdr_width, 
223
    hdr_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, 
224
    min(hdr_width, 160));
225
226
  buf_pos = buf + 16 + offs2;
227
  offs = le2me_32(*(uint32_t *)buf_pos);
228
  buf_pos += 4;
229
230
  iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width, 
231
    chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, 
232
    min(chroma_width, 40));
233
234
  buf_pos = buf + 16 + offs3;
235
  offs = le2me_32(*(uint32_t *)buf_pos);
236
  buf_pos += 4;
237
238
  iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width, 
239
    chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, 
240
    min(chroma_width, 40));
241
242
  return 8;
243
}
244
245
typedef struct {
246
  long xpos;
247
  long ypos;
248
  long width;
249
  long height;
250
  long split_flag;
251
  long split_direction;
252
  long usl7;
253
} ustr_t;
254
255
/* ---------------------------------------------------------------------- */
256
257 a44f8ccb Mike Melanson
#define LV1_CHECK(buf1,rle_v3,lv1,lp2)  \
258
  if((lv1 & 0x80) != 0) {   \
259
    if(rle_v3 != 0)         \
260
      rle_v3 = 0;           \
261
    else {                  \
262
      rle_v3 = 1;           \
263
      buf1 -= 2;            \
264
    }                       \
265
  }                         \
266
  lp2 = 4;
267
268
269
#define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)  \
270
  if(rle_v3 == 0) {         \
271
    rle_v2 = *buf1;         \
272
    rle_v1 = 1;             \
273
    if(rle_v2 > 32) {       \
274
      rle_v2 -= 32;         \
275
      rle_v1 = 0;           \
276
    }                       \
277
    rle_v3 = 1;             \
278
  }                         \
279
  buf1--;
280
281
282
#define LP2_CHECK(buf1,rle_v3,lp2)  \
283
  if(lp2 == 0 && rle_v3 != 0)     \
284
    rle_v3 = 0;           \
285
  else {                  \
286
    buf1--;               \
287
    rle_v3 = 1;           \
288
  }
289
290
291
#define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
292
  rle_v2--;             \
293
  if(rle_v2 == 0) {     \
294
    rle_v3 = 0;         \
295
    buf1 += 2;          \
296
  }                     \
297
  lp2 = 4;
298
299 deabd4fd Mike Melanson
static void iv_Decode_Chunk(Indeo3DecodeContext *s,
300
  unsigned char *cur, unsigned char *ref, int width, int height, 
301
  unsigned char *buf1, long fflags2, unsigned char *hdr,
302
  unsigned char *buf2, int min_width_160)
303
{
304
  unsigned char bit_buf;
305
  unsigned long bit_pos, lv, lv1, lv2;
306
  long *width_tbl, width_tbl_arr[10];
307
  char *ref_vectors;
308
  unsigned char *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
309 09b85c13 Fabrice Bellard
  uint32_t *cur_lp, *ref_lp;
310
  const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
311 deabd4fd Mike Melanson
  unsigned short *correction_type_sp[2];
312 a44f8ccb Mike Melanson
  ustr_t strip_tbl[20], *strip;
313 deabd4fd Mike Melanson
  int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,
314
    rle_v1, rle_v2, rle_v3;
315
316
  bit_buf = 0;
317
  ref_vectors = NULL;
318
319
  width_tbl = width_tbl_arr + 1;
320
  i = (width < 0 ? width + 3 : width)/4;
321
  for(j = -1; j < 8; j++) 
322
    width_tbl[j] = i * j;
323
324 a44f8ccb Mike Melanson
  strip = strip_tbl;
325 deabd4fd Mike Melanson
326
  for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);
327
328 a44f8ccb Mike Melanson
  strip->ypos = strip->xpos = 0;
329
  for(strip->width = min_width_160; width > strip->width; strip->width *= 2);
330
  strip->height = height;
331
  strip->split_direction = 0;
332
  strip->split_flag = 0;
333
  strip->usl7 = 0;
334 deabd4fd Mike Melanson
335
  bit_pos = 0;
336
337
  rle_v1 = rle_v2 = rle_v3 = 0;
338
339 a44f8ccb Mike Melanson
  while(strip >= strip_tbl) {
340 deabd4fd Mike Melanson
    if(bit_pos <= 0) {
341
      bit_pos = 8;
342
      bit_buf = *buf1++;
343
    }
344
345
    bit_pos -= 2;
346
    cmd = (bit_buf >> bit_pos) & 0x03;
347
348
    if(cmd == 0) {
349 a44f8ccb Mike Melanson
      strip++;
350
      memcpy(strip, strip-1, sizeof(ustr_t));
351
      strip->split_flag = 1;
352
      strip->split_direction = 0;
353
      strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
354 deabd4fd Mike Melanson
      continue;
355
    } else if(cmd == 1) {
356 a44f8ccb Mike Melanson
      strip++;
357
      memcpy(strip, strip-1, sizeof(ustr_t));
358
      strip->split_flag = 1;
359
      strip->split_direction = 1;
360
      strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
361 deabd4fd Mike Melanson
      continue;
362
    } else if(cmd == 2) {
363 a44f8ccb Mike Melanson
      if(strip->usl7 == 0) {
364
        strip->usl7 = 1;
365 deabd4fd Mike Melanson
        ref_vectors = NULL;
366
        continue;
367
      }
368
    } else if(cmd == 3) {
369 a44f8ccb Mike Melanson
      if(strip->usl7 == 0) {
370
        strip->usl7 = 1;
371 deabd4fd Mike Melanson
        ref_vectors = buf2 + (*buf1 * 2);
372
        buf1++;
373
        continue;
374
      }
375
    }
376
377 a44f8ccb Mike Melanson
    cur_frm_pos = cur + width * strip->ypos + strip->xpos;
378 deabd4fd Mike Melanson
379 a44f8ccb Mike Melanson
    if((blks_width = strip->width) < 0) 
380 deabd4fd Mike Melanson
      blks_width += 3;
381
    blks_width >>= 2;
382 a44f8ccb Mike Melanson
    blks_height = strip->height;
383 deabd4fd Mike Melanson
384
    if(ref_vectors != NULL) {
385 a44f8ccb Mike Melanson
      ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
386
        ref_vectors[1] + strip->xpos;
387 deabd4fd Mike Melanson
    } else 
388
      ref_frm_pos = cur_frm_pos - width_tbl[4];
389
390
    if(cmd == 2) {
391
      if(bit_pos <= 0) {
392
        bit_pos = 8;
393
        bit_buf = *buf1++;
394
      }
395
396
      bit_pos -= 2;
397
      cmd = (bit_buf >> bit_pos) & 0x03;
398
399
      if(cmd == 0 || ref_vectors != NULL) {
400
        for(lp1 = 0; lp1 < blks_width; lp1++) {
401
          for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
402 09b85c13 Fabrice Bellard
            ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
403 deabd4fd Mike Melanson
          cur_frm_pos += 4;
404
          ref_frm_pos += 4;
405
        }
406
      } else if(cmd != 1) 
407
        return;
408
    } else {
409
      k = *buf1 >> 4;
410
      j = *buf1 & 0x0f;
411
      buf1++;
412
      lv = j + fflags2;
413
414
      if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
415
        cp2 = s->ModPred + ((lv - 8) << 7);
416
        cp = ref_frm_pos;
417 09b85c13 Fabrice Bellard
        for(i = 0; i < blks_width << 2; i++) { 
418
            int v = *cp >> 1;
419
            *(cp++) = cp2[v]; 
420
        }
421 deabd4fd Mike Melanson
      }
422
423
      if(k == 1 || k == 4) {
424
        lv = (hdr[j] & 0xf) + fflags2;
425
        correction_type_sp[0] = s->corrector_type + (lv << 8);
426
        correction_lp[0] = correction + (lv << 8);
427
        lv = (hdr[j] >> 4) + fflags2;
428
        correction_lp[1] = correction + (lv << 8);
429
        correction_type_sp[1] = s->corrector_type + (lv << 8);
430
      } else {
431
        correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
432
        correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
433
        correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);
434
        correction_lp[0] = correction_lp[1] = correction + (lv << 8);
435
      }
436
437
      switch(k) {
438
        case 1:
439
        case 0:                    /********** CASE 0 **********/
440
          for( ; blks_height > 0; blks_height -= 4) {
441
            for(lp1 = 0; lp1 < blks_width; lp1++) {
442
              for(lp2 = 0; lp2 < 4; ) {
443
                k = *buf1++;
444 09b85c13 Fabrice Bellard
                cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
445
                ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
446 deabd4fd Mike Melanson
447
                switch(correction_type_sp[0][k]) {
448
                  case 0:
449
                    *cur_lp = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
450
                    lp2++;
451
                    break;
452
                  case 1:
453
                    ((unsigned short *)cur_lp)[0] = ((((unsigned short *)(ref_lp))[0] >> 1)
454
                      + correction_lp[lp2 & 0x01][*buf1++]) << 1;
455
                    ((unsigned short *)cur_lp)[1] = ((((unsigned short *)(ref_lp))[1] >> 1)
456
                      + correction_lp[lp2 & 0x01][k]) << 1;
457
                    lp2++;
458
                    break;
459
                  case 2:
460
                    if(lp2 == 0) {
461
                      for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])
462
                        cur_lp[j] = ref_lp[j];
463
                      lp2 += 2;
464
                    }
465
                    break;
466
                  case 3:
467
                    if(lp2 < 2) {
468
                      for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
469
                        cur_lp[j] = ref_lp[j];
470
                      lp2 = 3;
471
                    }
472
                    break;
473
                  case 8:
474
                    if(lp2 == 0) {
475 a44f8ccb Mike Melanson
                      RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
476 deabd4fd Mike Melanson
477
                      if(rle_v1 == 1 || ref_vectors != NULL) {
478
                        for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
479
                          cur_lp[j] = ref_lp[j];
480
                      }
481
482 a44f8ccb Mike Melanson
                      RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
483 deabd4fd Mike Melanson
                      break;
484
                    } else {
485
                      rle_v1 = 1;
486
                      rle_v2 = *buf1 - 1;
487
                    }
488
                  case 5:
489 a44f8ccb Mike Melanson
                      LP2_CHECK(buf1,rle_v3,lp2)
490 deabd4fd Mike Melanson
                  case 4:
491
                    for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
492
                      cur_lp[j] = ref_lp[j];
493
                    lp2 = 4;
494
                    break;
495
496
                  case 7:
497
                    if(rle_v3 != 0) 
498
                      rle_v3 = 0;
499
                    else {
500
                      buf1--;
501
                      rle_v3 = 1;
502
                    }
503
                  case 6:
504
                    if(ref_vectors != NULL) {
505
                      for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
506
                        cur_lp[j] = ref_lp[j];
507
                    }
508
                    lp2 = 4;
509
                    break;
510
511
                  case 9:
512
                    lv1 = *buf1++;
513
                    lv = (lv1 & 0x7F) << 1;
514
                    lv += (lv << 8);
515
                    lv += (lv << 16);
516
                    for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
517
                      cur_lp[j] = lv;
518
519 a44f8ccb Mike Melanson
                    LV1_CHECK(buf1,rle_v3,lv1,lp2)
520 deabd4fd Mike Melanson
                    break;
521
                  default: 
522
                    return;
523
                }
524
              }
525
526
              cur_frm_pos += 4;
527
              ref_frm_pos += 4;
528
            }
529
530
            cur_frm_pos += ((width - blks_width) * 4);
531
            ref_frm_pos += ((width - blks_width) * 4);
532
          }
533
          break;
534
535
        case 4:
536
        case 3:                    /********** CASE 3 **********/
537
          if(ref_vectors != NULL) 
538
            return;
539
          flag1 = 1;
540
541
          for( ; blks_height > 0; blks_height -= 8) {
542
            for(lp1 = 0; lp1 < blks_width; lp1++) {
543
              for(lp2 = 0; lp2 < 4; ) {
544
                k = *buf1++;
545
546 09b85c13 Fabrice Bellard
                cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
547
                ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
548 deabd4fd Mike Melanson
549
                switch(correction_type_sp[lp2 & 0x01][k]) {
550
                  case 0:
551
                    cur_lp[width_tbl[1]] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
552 a44f8ccb Mike Melanson
                    if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
553 deabd4fd Mike Melanson
                      cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
554
                    else
555
                      cur_lp[0] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
556
                    lp2++;
557
                    break;
558
559
                  case 1:
560
                    ((unsigned short *)cur_lp)[width_tbl[2]] =
561
                      ((((unsigned short *)ref_lp)[0] >> 1) + correction_lp[lp2 & 0x01][*buf1++]) << 1;
562
                    ((unsigned short *)cur_lp)[width_tbl[2]+1] =
563
                      ((((unsigned short *)ref_lp)[1] >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
564 a44f8ccb Mike Melanson
                    if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
565 deabd4fd Mike Melanson
                      cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
566
                    else
567
                      cur_lp[0] = cur_lp[width_tbl[1]];
568
                    lp2++;
569
                    break;
570
571
                  case 2:
572
                    if(lp2 == 0) {
573
                      for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
574
                        cur_lp[j] = *ref_lp;
575
                      lp2 += 2;
576
                    }
577
                    break;
578
579
                  case 3:
580
                    if(lp2 < 2) {
581
                      for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
582
                        cur_lp[j] = *ref_lp;
583
                      lp2 = 3;
584
                    }
585
                    break;
586
587
                  case 6:
588
                    lp2 = 4;
589
                    break;
590
591
                  case 7:
592
                    if(rle_v3 != 0) 
593
                      rle_v3 = 0;
594
                    else {
595
                      buf1--;
596
                      rle_v3 = 1;
597
                    }
598
                    lp2 = 4;
599
                    break;
600
601
                  case 8:
602
                    if(lp2 == 0) {
603 a44f8ccb Mike Melanson
                      RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
604 deabd4fd Mike Melanson
605
                      if(rle_v1 == 1) {
606
                        for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
607
                          cur_lp[j] = ref_lp[j];
608
                      }
609
610 a44f8ccb Mike Melanson
                      RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
611 deabd4fd Mike Melanson
                      break;
612
                    } else {
613
                      rle_v2 = (*buf1) - 1;
614
                      rle_v1 = 1;
615
                    }
616
                  case 5:
617 a44f8ccb Mike Melanson
                      LP2_CHECK(buf1,rle_v3,lp2)
618 deabd4fd Mike Melanson
                  case 4:
619
                    for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
620
                      cur_lp[j] = *ref_lp;
621
                    lp2 = 4;
622
                    break;
623
624
                  case 9:
625
                    fprintf(stderr, "UNTESTED.\n");
626
                    lv1 = *buf1++;
627
                    lv = (lv1 & 0x7F) << 1;
628
                    lv += (lv << 8);
629
                    lv += (lv << 16);
630
631
                    for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
632
                      cur_lp[j] = lv;
633
634 a44f8ccb Mike Melanson
                    LV1_CHECK(buf1,rle_v3,lv1,lp2)
635 deabd4fd Mike Melanson
                    break;
636
637
                  default: 
638
                    return;
639
                }
640
              }
641
642
              cur_frm_pos += 4;
643
            }
644
645
            cur_frm_pos += (((width * 2) - blks_width) * 4);
646
            flag1 = 0;
647
          }
648
          break;
649
650
        case 10:                    /********** CASE 10 **********/
651
          if(ref_vectors == NULL) {
652
            flag1 = 1;
653
654
            for( ; blks_height > 0; blks_height -= 8) {
655
              for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
656
                for(lp2 = 0; lp2 < 4; ) {
657
                  k = *buf1++;
658 09b85c13 Fabrice Bellard
                  cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
659
                  ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
660 deabd4fd Mike Melanson
                  lv1 = ref_lp[0];
661
                  lv2 = ref_lp[1];
662
                  if(lp2 == 0 && flag1 != 0) {
663
                    lv1 = lv1 & 0x00FF00FF;
664
                    lv1 = (lv1 << 8) | lv1;
665
                    lv2 = lv2 & 0x00FF00FF;
666
                    lv2 = (lv2 << 8) | lv2;
667
                  }
668
669
                  switch(correction_type_sp[lp2 & 0x01][k]) {
670
                    case 0:
671
                      cur_lp[width_tbl[1]] = ((lv1 >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1;
672
                      cur_lp[width_tbl[1]+1] = ((lv2 >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1;
673 a44f8ccb Mike Melanson
                      if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
674 deabd4fd Mike Melanson
                        cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
675
                        cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
676
                      } else {
677
                        cur_lp[0] = cur_lp[width_tbl[1]];
678
                        cur_lp[1] = cur_lp[width_tbl[1]+1];
679
                      }
680
                      lp2++;
681
                      break;
682
683
                    case 1:
684
                      cur_lp[width_tbl[1]] = ((lv1 >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1++]) << 1;
685
                      cur_lp[width_tbl[1]+1] = ((lv2 >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1;
686 a44f8ccb Mike Melanson
                      if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
687 deabd4fd Mike Melanson
                        cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
688
                        cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
689
                      } else {
690
                        cur_lp[0] = cur_lp[width_tbl[1]];
691
                        cur_lp[1] = cur_lp[width_tbl[1]+1];
692
                      }
693
                      lp2++;
694
                      break;
695
696
                    case 2:
697
                      if(lp2 == 0) {
698
                        if(flag1 != 0) {
699
                          for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
700
                            cur_lp[j] = lv1;
701
                            cur_lp[j+1] = lv2;
702
                          }
703
                          cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
704
                          cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
705
                        } else {
706
                          for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
707
                            cur_lp[j] = lv1;
708
                            cur_lp[j+1] = lv2;
709
                          }
710
                        }
711
                        lp2 += 2;
712
                      }
713
                      break;
714
715
                    case 3:
716
                      if(lp2 < 2) {
717
                        if(lp2 == 0 && flag1 != 0) {
718
                          for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
719
                            cur_lp[j] = lv1;
720
                            cur_lp[j+1] = lv2;
721
                          }
722
                          cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
723
                          cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
724
                        } else {
725
                          for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
726
                            cur_lp[j] = lv1;
727
                            cur_lp[j+1] = lv2;
728
                          }
729
                        }
730
                        lp2 = 3;
731
                      }
732
                      break;
733
734
                    case 8:
735
                      if(lp2 == 0) {
736 a44f8ccb Mike Melanson
                        RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
737 deabd4fd Mike Melanson
                        if(rle_v1 == 1) {
738
                          if(flag1 != 0) {
739
                            for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
740
                              cur_lp[j] = lv1;
741
                              cur_lp[j+1] = lv2;
742
                            }
743
                            cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
744
                            cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
745
                          } else {
746
                            for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
747
                              cur_lp[j] = lv1;
748
                              cur_lp[j+1] = lv2;
749
                            }
750
                          }
751
                        }
752 a44f8ccb Mike Melanson
                        RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
753 deabd4fd Mike Melanson
                        break;
754
                      } else {
755
                        rle_v1 = 1;
756
                        rle_v2 = (*buf1) - 1;
757
                      }
758
                    case 5:
759 a44f8ccb Mike Melanson
                        LP2_CHECK(buf1,rle_v3,lp2)
760 deabd4fd Mike Melanson
                    case 4:
761
                      if(lp2 == 0 && flag1 != 0) {
762
                        for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
763
                          cur_lp[j] = lv1;
764
                          cur_lp[j+1] = lv2;
765
                        }
766
                        cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
767
                        cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
768
                      } else {
769
                        for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
770
                          cur_lp[j] = lv1;
771
                          cur_lp[j+1] = lv2;
772
                        }
773
                      }
774
                      lp2 = 4;
775
                      break;
776
777
                    case 6:
778
                      lp2 = 4;
779
                      break;
780
781
                    case 7:
782
                      if(lp2 == 0) {
783
                        if(rle_v3 != 0) 
784
                          rle_v3 = 0;
785
                        else {
786
                          buf1--;
787
                          rle_v3 = 1;
788
                        }
789
                        lp2 = 4;
790
                      }
791
                      break;
792
793
                    case 9:
794
                      fprintf(stderr, "UNTESTED.\n");
795
                      lv1 = *buf1;
796
                      lv = (lv1 & 0x7F) << 1;
797
                      lv += (lv << 8);
798
                      lv += (lv << 16);
799
                      for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
800
                        cur_lp[j] = lv;
801 a44f8ccb Mike Melanson
                      LV1_CHECK(buf1,rle_v3,lv1,lp2)
802 deabd4fd Mike Melanson
                      break;
803
804
                    default: 
805
                      return;
806
                  }
807
                }
808
809
                cur_frm_pos += 8;
810
              }
811
812
              cur_frm_pos += (((width * 2) - blks_width) * 4);
813
              flag1 = 0;
814
            }
815
          } else {
816
            for( ; blks_height > 0; blks_height -= 8) {
817
              for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
818
                for(lp2 = 0; lp2 < 4; ) {
819
                  k = *buf1++;
820 09b85c13 Fabrice Bellard
                  cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
821
                  ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
822 deabd4fd Mike Melanson
823
                  switch(correction_type_sp[lp2 & 0x01][k]) {
824
                    case 0:
825
                      lv1 = correctionloworder_lp[lp2 & 0x01][k];
826
                      lv2 = correctionhighorder_lp[lp2 & 0x01][k];
827
                      cur_lp[0] = ((ref_lp[0] >> 1) + lv1) << 1;
828
                      cur_lp[1] = ((ref_lp[1] >> 1) + lv2) << 1;
829
                      cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + lv1) << 1;
830
                      cur_lp[width_tbl[1]+1] = ((ref_lp[width_tbl[1]+1] >> 1) + lv2) << 1;
831
                      lp2++;
832
                      break;
833
834
                    case 1:
835
                      lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
836
                      lv2 = correctionloworder_lp[lp2 & 0x01][k];
837
                      cur_lp[0] = ((ref_lp[0] >> 1) + lv1) << 1;
838
                      cur_lp[1] = ((ref_lp[1] >> 1) + lv2) << 1;
839
                      cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + lv1) << 1;
840
                      cur_lp[width_tbl[1]+1] = ((ref_lp[width_tbl[1]+1] >> 1) + lv2) << 1;
841
                      lp2++;
842
                      break;
843
844
                    case 2:
845
                      if(lp2 == 0) {
846
                        for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
847
                          cur_lp[j] = ref_lp[j];
848
                          cur_lp[j+1] = ref_lp[j+1];
849
                        }
850
                        lp2 += 2;
851
                      }
852
                      break;
853
854
                    case 3:
855
                      if(lp2 < 2) {
856
                        for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
857
                          cur_lp[j] = ref_lp[j];
858
                          cur_lp[j+1] = ref_lp[j+1];
859
                        }
860
                        lp2 = 3;
861
                      }
862
                      break;
863
864
                    case 8:
865
                      if(lp2 == 0) {
866 a44f8ccb Mike Melanson
                        RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
867 deabd4fd Mike Melanson
                        for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
868 09b85c13 Fabrice Bellard
                          ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
869
                          ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];
870 deabd4fd Mike Melanson
                        }
871 a44f8ccb Mike Melanson
                        RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
872 deabd4fd Mike Melanson
                        break;
873
                      } else {
874
                        rle_v1 = 1;
875
                        rle_v2 = (*buf1) - 1;
876
                      }
877
                    case 5:
878
                    case 7:
879 a44f8ccb Mike Melanson
                        LP2_CHECK(buf1,rle_v3,lp2)
880 deabd4fd Mike Melanson
                    case 6:
881
                    case 4:
882
                      for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
883
                        cur_lp[j] = ref_lp[j];
884
                        cur_lp[j+1] = ref_lp[j+1];
885
                      }
886
                      lp2 = 4;
887
                      break;
888
889
                    case 9:
890
                      fprintf(stderr, "UNTESTED.\n");
891
                      lv1 = *buf1;
892
                      lv = (lv1 & 0x7F) << 1;
893
                      lv += (lv << 8);
894
                      lv += (lv << 16);
895
                      for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
896 09b85c13 Fabrice Bellard
                        ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;
897 a44f8ccb Mike Melanson
                      LV1_CHECK(buf1,rle_v3,lv1,lp2)
898 deabd4fd Mike Melanson
                      break;
899
900
                    default: 
901
                      return;
902
                  }
903
                }
904
905
                cur_frm_pos += 8;
906
                ref_frm_pos += 8;
907
              }
908
909
              cur_frm_pos += (((width * 2) - blks_width) * 4);
910
              ref_frm_pos += (((width * 2) - blks_width) * 4);
911
            }
912
          }
913
          break;
914
915
        case 11:                    /********** CASE 11 **********/
916
          if(ref_vectors == NULL) 
917
            return;
918
919
          for( ; blks_height > 0; blks_height -= 8) {
920
            for(lp1 = 0; lp1 < blks_width; lp1++) {
921
              for(lp2 = 0; lp2 < 4; ) {
922
                k = *buf1++;
923 09b85c13 Fabrice Bellard
                cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
924
                ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
925 deabd4fd Mike Melanson
926
                switch(correction_type_sp[lp2 & 0x01][k]) {
927
                  case 0:
928
                    cur_lp[0] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
929
                    cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
930
                    lp2++;
931
                    break;
932
933
                  case 1:
934
                    lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);
935
                    lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);
936
                    ((unsigned short *)cur_lp)[0] = ((((unsigned short *)ref_lp)[0] >> 1) + lv1) << 1;
937
                    ((unsigned short *)cur_lp)[1] = ((((unsigned short *)ref_lp)[1] >> 1) + lv2) << 1;
938
                    ((unsigned short *)cur_lp)[width_tbl[2]] = ((((unsigned short *)ref_lp)[width_tbl[2]] >> 1) + lv1) << 1;
939
                    ((unsigned short *)cur_lp)[width_tbl[2]+1] = ((((unsigned short *)ref_lp)[width_tbl[2]+1] >> 1) + lv2) << 1;
940
                    lp2++;
941
                    break;
942
943
                  case 2:
944
                    if(lp2 == 0) {
945
                      for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
946
                        cur_lp[j] = ref_lp[j];
947
                      lp2 += 2;
948
                    }
949
                    break;
950
951
                  case 3:
952
                    if(lp2 < 2) {
953
                      for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
954
                        cur_lp[j] = ref_lp[j];
955
                      lp2 = 3;
956
                    }
957
                    break;
958
959
                  case 8:
960
                    if(lp2 == 0) {
961 a44f8ccb Mike Melanson
                      RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
962 deabd4fd Mike Melanson
963
                      for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
964
                        cur_lp[j] = ref_lp[j];
965
966 a44f8ccb Mike Melanson
                      RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
967 deabd4fd Mike Melanson
                      break;
968
                    } else {
969
                      rle_v1 = 1;
970
                      rle_v2 = (*buf1) - 1;
971
                    }
972
                  case 5:
973
                  case 7:
974 a44f8ccb Mike Melanson
                      LP2_CHECK(buf1,rle_v3,lp2)
975 deabd4fd Mike Melanson
                  case 4:
976
                  case 6:
977
                    for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
978
                      cur_lp[j] = ref_lp[j];
979
                    lp2 = 4;
980
                    break;
981
982
                case 9:
983
                  fprintf(stderr, "UNTESTED.\n");
984
                  lv1 = *buf1++;
985
                  lv = (lv1 & 0x7F) << 1;
986
                  lv += (lv << 8);
987
                  lv += (lv << 16);
988
                  for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
989
                    cur_lp[j] = lv;
990 a44f8ccb Mike Melanson
                  LV1_CHECK(buf1,rle_v3,lv1,lp2)
991 deabd4fd Mike Melanson
                  break;
992
993
                  default: 
994
                    return;
995
                }
996
              }
997
998
              cur_frm_pos += 4;
999
              ref_frm_pos += 4;
1000
            }
1001
1002
            cur_frm_pos += (((width * 2) - blks_width) * 4);
1003
            ref_frm_pos += (((width * 2) - blks_width) * 4);
1004
          }
1005
          break;
1006
1007
        default: 
1008
          return;
1009
      }
1010
    }
1011
1012 a44f8ccb Mike Melanson
    if(strip < strip_tbl) 
1013 deabd4fd Mike Melanson
      return;
1014
1015 a44f8ccb Mike Melanson
    for( ; strip >= strip_tbl; strip--) {
1016
      if(strip->split_flag != 0) {
1017
        strip->split_flag = 0;
1018
        strip->usl7 = (strip-1)->usl7;
1019 deabd4fd Mike Melanson
1020 a44f8ccb Mike Melanson
        if(strip->split_direction) {
1021
          strip->xpos += strip->width;
1022
          strip->width = (strip-1)->width - strip->width;
1023
          if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)
1024
            strip->width = width - strip->xpos;
1025 deabd4fd Mike Melanson
        } else {
1026 a44f8ccb Mike Melanson
          strip->ypos += strip->height;
1027
          strip->height = (strip-1)->height - strip->height;
1028 deabd4fd Mike Melanson
        }
1029
        break;
1030
      }
1031
    }
1032
  }
1033
}
1034
1035
static int indeo3_decode_init(AVCodecContext *avctx)
1036
{
1037
    Indeo3DecodeContext *s = avctx->priv_data;
1038
1039
    s->avctx = avctx;
1040
    s->width = avctx->width;
1041
    s->height = avctx->height;
1042
    avctx->pix_fmt = PIX_FMT_YUV410P;
1043
    avctx->has_b_frames = 0;
1044
1045
    build_modpred(s);
1046
    iv_alloc_frames(s);
1047
1048
    return 0;
1049
}
1050
1051
static int indeo3_decode_frame(AVCodecContext *avctx,
1052
                               void *data, int *data_size,
1053
                               unsigned char *buf, int buf_size)
1054
{
1055
    Indeo3DecodeContext *s=avctx->priv_data;
1056
    unsigned char *src, *dest;
1057
    int y;
1058
1059
    iv_decode_frame(s, buf, buf_size);
1060
1061 e20c4069 Michael Niedermayer
    if(s->frame.data[0])
1062
        avctx->release_buffer(avctx, &s->frame);
1063
1064 deabd4fd Mike Melanson
    s->frame.reference = 0;
1065
    if(avctx->get_buffer(avctx, &s->frame) < 0) {
1066
        fprintf(stderr, "get_buffer() failed\n");
1067
        return -1;
1068
    }
1069
1070
    src = s->cur_frame->Ybuf;
1071
    dest = s->frame.data[0];
1072
    for (y = 0; y < s->height; y++) {
1073
      memcpy(dest, src, s->cur_frame->y_w);
1074
      src += s->cur_frame->y_w;
1075
      dest += s->frame.linesize[0];
1076
    }
1077
1078
    src = s->cur_frame->Ubuf;
1079
    dest = s->frame.data[1];
1080
    for (y = 0; y < s->height / 4; y++) {
1081
      memcpy(dest, src, s->cur_frame->uv_w);
1082
      src += s->cur_frame->uv_w;
1083
      dest += s->frame.linesize[1];
1084
    }
1085
1086
    src = s->cur_frame->Vbuf;
1087
    dest = s->frame.data[2];
1088
    for (y = 0; y < s->height / 4; y++) {
1089
      memcpy(dest, src, s->cur_frame->uv_w);
1090
      src += s->cur_frame->uv_w;
1091
      dest += s->frame.linesize[2];
1092
    }
1093
1094
    *data_size=sizeof(AVFrame);
1095
    *(AVFrame*)data= s->frame;
1096
1097
    return buf_size;
1098
}
1099
1100
static int indeo3_decode_end(AVCodecContext *avctx)
1101
{
1102
    Indeo3DecodeContext *s = avctx->priv_data;
1103
1104
    iv_free_func(s);
1105
1106
    return 0;
1107
}
1108
1109
AVCodec indeo3_decoder = {
1110
    "indeo3",
1111
    CODEC_TYPE_VIDEO,
1112
    CODEC_ID_INDEO3,
1113
    sizeof(Indeo3DecodeContext),
1114
    indeo3_decode_init,
1115
    NULL,
1116
    indeo3_decode_end,
1117
    indeo3_decode_frame,
1118
    0,
1119
    NULL
1120
};