~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/ulti.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    int width, height, blocks;
39
39
    AVFrame frame;
40
40
    const uint8_t *ulti_codebook;
 
41
    GetByteContext gb;
41
42
} UltimotionDecodeContext;
42
43
 
43
44
static av_cold int ulti_decode_init(AVCodecContext *avctx)
231
232
        return -1;
232
233
    }
233
234
 
 
235
    bytestream2_init(&s->gb, buf, buf_size);
 
236
 
234
237
    while(!done) {
235
238
        int idx;
236
239
        if(blocks >= s->blocks || y >= s->height)
237
240
            break;//all blocks decoded
238
241
 
239
 
        idx = *buf++;
 
242
        if (bytestream2_get_bytes_left(&s->gb) < 1)
 
243
            goto err;
 
244
        idx = bytestream2_get_byteu(&s->gb);
240
245
        if((idx & 0xF8) == 0x70) {
241
246
            switch(idx) {
242
247
            case 0x70: //change modifier
243
 
                modifier = *buf++;
 
248
                modifier = bytestream2_get_byte(&s->gb);
244
249
                if(modifier>1)
245
250
                    av_log(avctx, AV_LOG_INFO, "warning: modifier must be 0 or 1, got %i\n", modifier);
246
251
                break;
254
259
                done = 1;
255
260
                break;
256
261
            case 0x74: //skip some blocks
257
 
                skip = *buf++;
 
262
                skip = bytestream2_get_byte(&s->gb);
258
263
                if ((blocks + skip) >= s->blocks)
259
264
                    break;
260
265
                blocks += skip;
280
285
                chroma = 0;
281
286
            } else {
282
287
                cf = 0;
283
 
                if (idx)
284
 
                    chroma = *buf++;
 
288
                if (idx) {
 
289
                    chroma = bytestream2_get_byte(&s->gb);
 
290
                }
285
291
            }
286
292
            for (i = 0; i < 4; i++) { // for every subblock
287
293
                code = (idx >> (6 - i*2)) & 3; //extract 2 bits
288
294
                if(!code) //skip subblock
289
295
                    continue;
290
 
                if(cf)
291
 
                    chroma = *buf++;
 
296
                if(cf) {
 
297
                    chroma = bytestream2_get_byte(&s->gb);
 
298
                }
292
299
                tx = x + block_coords[i * 2];
293
300
                ty = y + block_coords[(i * 2) + 1];
294
301
                switch(code) {
295
302
                case 1:
296
 
                    tmp = *buf++;
 
303
                    tmp = bytestream2_get_byte(&s->gb);
297
304
 
298
305
                    angle = angle_by_index[(tmp >> 6) & 0x3];
299
306
 
313
320
 
314
321
                case 2:
315
322
                    if (modifier) { // unpack four luma samples
316
 
                        tmp = bytestream_get_be24(&buf);
 
323
                        tmp = bytestream2_get_be24(&s->gb);
317
324
 
318
325
                        Y[0] = (tmp >> 18) & 0x3F;
319
326
                        Y[1] = (tmp >> 12) & 0x3F;
321
328
                        Y[3] = tmp & 0x3F;
322
329
                        angle = 16;
323
330
                    } else { // retrieve luma samples from codebook
324
 
                        tmp = bytestream_get_be16(&buf);
 
331
                        tmp = bytestream2_get_be16(&s->gb);
325
332
 
326
333
                        angle = (tmp >> 12) & 0xF;
327
334
                        tmp &= 0xFFF;
337
344
                    if (modifier) { // all 16 luma samples
338
345
                        uint8_t Luma[16];
339
346
 
340
 
                        tmp = bytestream_get_be24(&buf);
 
347
                        if (bytestream2_get_bytes_left(&s->gb) < 12)
 
348
                            goto err;
 
349
                        tmp = bytestream2_get_be24u(&s->gb);
341
350
                        Luma[0] = (tmp >> 18) & 0x3F;
342
351
                        Luma[1] = (tmp >> 12) & 0x3F;
343
352
                        Luma[2] = (tmp >> 6) & 0x3F;
344
353
                        Luma[3] = tmp & 0x3F;
345
354
 
346
 
                        tmp = bytestream_get_be24(&buf);
 
355
                        tmp = bytestream2_get_be24u(&s->gb);
347
356
                        Luma[4] = (tmp >> 18) & 0x3F;
348
357
                        Luma[5] = (tmp >> 12) & 0x3F;
349
358
                        Luma[6] = (tmp >> 6) & 0x3F;
350
359
                        Luma[7] = tmp & 0x3F;
351
360
 
352
 
                        tmp = bytestream_get_be24(&buf);
 
361
                        tmp = bytestream2_get_be24u(&s->gb);
353
362
                        Luma[8] = (tmp >> 18) & 0x3F;
354
363
                        Luma[9] = (tmp >> 12) & 0x3F;
355
364
                        Luma[10] = (tmp >> 6) & 0x3F;
356
365
                        Luma[11] = tmp & 0x3F;
357
366
 
358
 
                        tmp = bytestream_get_be24(&buf);
 
367
                        tmp = bytestream2_get_be24u(&s->gb);
359
368
                        Luma[12] = (tmp >> 18) & 0x3F;
360
369
                        Luma[13] = (tmp >> 12) & 0x3F;
361
370
                        Luma[14] = (tmp >> 6) & 0x3F;
363
372
 
364
373
                        ulti_convert_yuv(&s->frame, tx, ty, Luma, chroma);
365
374
                    } else {
366
 
                        tmp = *buf++;
 
375
                        if (bytestream2_get_bytes_left(&s->gb) < 4)
 
376
                            goto err;
 
377
                        tmp = bytestream2_get_byteu(&s->gb);
367
378
                        if(tmp & 0x80) {
368
379
                            angle = (tmp >> 4) & 0x7;
369
 
                            tmp = (tmp << 8) + *buf++;
 
380
                            tmp = (tmp << 8) + bytestream2_get_byteu(&s->gb);
370
381
                            Y[0] = (tmp >> 6) & 0x3F;
371
382
                            Y[1] = tmp & 0x3F;
372
 
                            Y[2] = (*buf++) & 0x3F;
373
 
                            Y[3] = (*buf++) & 0x3F;
 
383
                            Y[2] = bytestream2_get_byteu(&s->gb) & 0x3F;
 
384
                            Y[3] = bytestream2_get_byteu(&s->gb) & 0x3F;
374
385
                            ulti_grad(&s->frame, tx, ty, Y, chroma, angle); //draw block
375
386
                        } else { // some patterns
376
387
                            int f0, f1;
377
 
                            f0 = *buf++;
 
388
                            f0 = bytestream2_get_byteu(&s->gb);
378
389
                            f1 = tmp;
379
 
                            Y[0] = (*buf++) & 0x3F;
380
 
                            Y[1] = (*buf++) & 0x3F;
 
390
                            Y[0] = bytestream2_get_byteu(&s->gb) & 0x3F;
 
391
                            Y[1] = bytestream2_get_byteu(&s->gb) & 0x3F;
381
392
                            ulti_pattern(&s->frame, tx, ty, f1, f0, Y[0], Y[1], chroma);
382
393
                        }
383
394
                    }
399
410
    *(AVFrame*)data= s->frame;
400
411
 
401
412
    return buf_size;
 
413
 
 
414
err:
 
415
    av_log(avctx, AV_LOG_ERROR,
 
416
           "Insufficient data\n");
 
417
    return AVERROR_INVALIDDATA;
402
418
}
403
419
 
404
420
AVCodec ff_ulti_decoder = {
405
 
    "ultimotion",
406
 
    AVMEDIA_TYPE_VIDEO,
407
 
    CODEC_ID_ULTI,
408
 
    sizeof(UltimotionDecodeContext),
409
 
    ulti_decode_init,
410
 
    NULL,
411
 
    ulti_decode_end,
412
 
    ulti_decode_frame,
413
 
    CODEC_CAP_DR1,
414
 
    NULL,
 
421
    .name           = "ultimotion",
 
422
    .type           = AVMEDIA_TYPE_VIDEO,
 
423
    .id             = CODEC_ID_ULTI,
 
424
    .priv_data_size = sizeof(UltimotionDecodeContext),
 
425
    .init           = ulti_decode_init,
 
426
    .close          = ulti_decode_end,
 
427
    .decode         = ulti_decode_frame,
 
428
    .capabilities   = CODEC_CAP_DR1,
415
429
    .long_name = NULL_IF_CONFIG_SMALL("IBM UltiMotion"),
416
430
};
417
431