Revision 8c18e490 libavcodec/lcldec.c

View differences:

libavcodec/lcldec.c
71 71
} LclDecContext;
72 72

  
73 73

  
74
/*
75
 *
76
 * Helper functions
77
 *
78
 */
79
static inline unsigned char fix (int pix14)
80
{
81
    int tmp;
82

  
83
    tmp = (pix14 + 0x80000) >> 20;
84
    return av_clip_uint8(tmp);
85
}
86

  
87

  
88

  
89
static inline unsigned char get_b (unsigned char yq, signed char bq)
90
{
91
    return fix((yq << 20) + bq * 1858076);
92
}
93

  
94

  
95

  
96
static inline unsigned char get_g (unsigned char yq, signed char bq, signed char rq)
97
{
98
    return fix((yq << 20) - bq * 360857 - rq * 748830);
99
}
100

  
101

  
102

  
103
static inline unsigned char get_r (unsigned char yq, signed char rq)
104
{
105
    return fix((yq << 20) + rq * 1470103);
106
}
107

  
108

  
109

  
110 74
static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize)
111 75
{
112 76
    unsigned char *destptr_bak = destptr;
......
166 130
    unsigned int pixel_ptr;
167 131
    int row, col;
168 132
    unsigned char *outptr;
133
    uint8_t *y_out, *u_out, *v_out;
169 134
    unsigned int width = avctx->width; // Real image width
170 135
    unsigned int height = avctx->height; // Real image height
171 136
    unsigned int mszh_dlen;
......
397 362
    }
398 363

  
399 364
    /* Convert colorspace */
365
    y_out = c->pic.data[0] + (height - 1) * c->pic.linesize[0];
366
    u_out = c->pic.data[1] + (height - 1) * c->pic.linesize[1];
367
    v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2];
400 368
    switch (c->imgtype) {
401 369
    case IMGTYPE_YUV111:
402
        for (row = height - 1; row >= 0; row--) {
403
            pixel_ptr = row * c->pic.linesize[0];
370
        for (row = 0; row < height; row++) {
404 371
            for (col = 0; col < width; col++) {
405
                outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]);
406
                outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]);
407
                outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]);
408
                encoded += 3;
372
                y_out[col] = *encoded++;
373
                u_out[col] = *encoded++ + 128;
374
                v_out[col] = *encoded++ + 128;
409 375
            }
376
            y_out -= c->pic.linesize[0];
377
            u_out -= c->pic.linesize[1];
378
            v_out -= c->pic.linesize[2];
410 379
        }
411 380
        break;
412 381
    case IMGTYPE_YUV422:
413
        for (row = height - 1; row >= 0; row--) {
414
            pixel_ptr = row * c->pic.linesize[0];
415
            for (col = 0; col < width/4; col++) {
416
                outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
417
                outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]);
418
                outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]);
419
                outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
420
                outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]);
421
                outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]);
422
                outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]);
423
                outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]);
424
                outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]);
425
                outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]);
426
                outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]);
427
                outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]);
428
                encoded += 8;
382
        for (row = 0; row < height; row++) {
383
            for (col = 0; col < width - 3; col += 4) {
384
                memcpy(y_out + col, encoded, 4);
385
                encoded += 4;
386
                u_out[ col >> 1     ] = *encoded++ + 128;
387
                u_out[(col >> 1) + 1] = *encoded++ + 128;
388
                v_out[ col >> 1     ] = *encoded++ + 128;
389
                v_out[(col >> 1) + 1] = *encoded++ + 128;
429 390
            }
391
            y_out -= c->pic.linesize[0];
392
            u_out -= c->pic.linesize[1];
393
            v_out -= c->pic.linesize[2];
430 394
        }
431 395
        break;
432 396
    case IMGTYPE_RGB24:
......
437 401
        }
438 402
        break;
439 403
    case IMGTYPE_YUV411:
440
        for (row = height - 1; row >= 0; row--) {
441
            pixel_ptr = row * c->pic.linesize[0];
442
            for (col = 0; col < width/4; col++) {
443
                outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
444
                outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]);
445
                outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]);
446
                outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
447
                outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]);
448
                outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]);
449
                outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]);
450
                outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]);
451
                outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]);
452
                outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]);
453
                outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]);
454
                outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]);
455
                encoded += 6;
404
        for (row = 0; row < height; row++) {
405
            for (col = 0; col < width - 3; col += 4) {
406
                memcpy(y_out + col, encoded, 4);
407
                encoded += 4;
408
                u_out[col >> 2] = *encoded++ + 128;
409
                v_out[col >> 2] = *encoded++ + 128;
456 410
            }
411
            y_out -= c->pic.linesize[0];
412
            u_out -= c->pic.linesize[1];
413
            v_out -= c->pic.linesize[2];
457 414
        }
458 415
        break;
459 416
    case IMGTYPE_YUV211:
460
        for (row = height - 1; row >= 0; row--) {
461
            pixel_ptr = row * c->pic.linesize[0];
462
            for (col = 0; col < width/2; col++) {
463
                outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]);
464
                outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]);
465
                outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]);
466
                outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]);
467
                outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]);
468
                outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]);
469
                encoded += 4;
417
        for (row = 0; row < height; row++) {
418
            for (col = 0; col < width - 1; col += 2) {
419
                memcpy(y_out + col, encoded, 2);
420
                encoded += 2;
421
                u_out[col >> 1] = *encoded++ + 128;
422
                v_out[col >> 1] = *encoded++ + 128;
470 423
            }
424
            y_out -= c->pic.linesize[0];
425
            u_out -= c->pic.linesize[1];
426
            v_out -= c->pic.linesize[2];
471 427
        }
472 428
        break;
473 429
    case IMGTYPE_YUV420:
474
        for (row = height / 2 - 1; row >= 0; row--) {
475
            pixel_ptr = 2 * row * c->pic.linesize[0];
476
            for (col = 0; col < width/2; col++) {
477
                outptr[pixel_ptr] = get_b(encoded[0], encoded[4]);
478
                outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]);
479
                outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]);
480
                outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]);
481
                outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]);
482
                outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]);
483
                outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]);
484
                outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]);
485
                outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]);
486
                outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]);
487
                outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]);
488
                outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]);
489
                pixel_ptr += 6;
490
                encoded += 6;
430
        u_out = c->pic.data[1] + ((height >> 1) - 1) * c->pic.linesize[1];
431
        v_out = c->pic.data[2] + ((height >> 1) - 1) * c->pic.linesize[2];
432
        for (row = 0; row < height - 1; row += 2) {
433
            for (col = 0; col < width - 1; col += 2) {
434
                memcpy(y_out + col, encoded, 2);
435
                encoded += 2;
436
                memcpy(y_out + col - c->pic.linesize[0], encoded, 2);
437
                encoded += 2;
438
                u_out[col >> 1] = *encoded++ + 128;
439
                v_out[col >> 1] = *encoded++ + 128;
491 440
            }
441
            y_out -= c->pic.linesize[0] << 1;
442
            u_out -= c->pic.linesize[1];
443
            v_out -= c->pic.linesize[2];
492 444
        }
493 445
        break;
494 446
    default:
......
543 495
    case IMGTYPE_YUV111:
544 496
        c->decomp_size = basesize * 3;
545 497
        max_decomp_size = max_basesize * 3;
498
        avctx->pix_fmt = PIX_FMT_YUV444P;
546 499
        av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n");
547 500
        break;
548 501
    case IMGTYPE_YUV422:
549 502
        c->decomp_size = basesize * 2;
550 503
        max_decomp_size = max_basesize * 2;
504
        avctx->pix_fmt = PIX_FMT_YUV422P;
551 505
        av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n");
552 506
        break;
553 507
    case IMGTYPE_RGB24:
554 508
        c->decomp_size = basesize * 3;
555 509
        max_decomp_size = max_basesize * 3;
510
        avctx->pix_fmt = PIX_FMT_BGR24;
556 511
        av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n");
557 512
        break;
558 513
    case IMGTYPE_YUV411:
559 514
        c->decomp_size = basesize / 2 * 3;
560 515
        max_decomp_size = max_basesize / 2 * 3;
516
        avctx->pix_fmt = PIX_FMT_YUV411P;
561 517
        av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n");
562 518
        break;
563 519
    case IMGTYPE_YUV211:
564 520
        c->decomp_size = basesize * 2;
565 521
        max_decomp_size = max_basesize * 2;
522
        avctx->pix_fmt = PIX_FMT_YUV422P;
566 523
        av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n");
567 524
        break;
568 525
    case IMGTYPE_YUV420:
569 526
        c->decomp_size = basesize / 2 * 3;
570 527
        max_decomp_size = max_basesize / 2 * 3;
528
        avctx->pix_fmt = PIX_FMT_YUV420P;
571 529
        av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n");
572 530
        break;
573 531
    default:
......
657 615
#endif
658 616
    }
659 617

  
660
    avctx->pix_fmt = PIX_FMT_BGR24;
661

  
662 618
    return 0;
663 619
}
664 620

  

Also available in: Unified diff