Exemple #1
0
/**
 * Parse the palette segment packet.
 *
 * The palette segment contains details of the palette,
 * a maximum of 256 colors can be defined.
 *
 * @param avctx contains the current codec context
 * @param buf pointer to the packet to process
 * @param buf_size size of packet to process
 */
static void parse_palette_segment(AVCodecContext *avctx,
                                  const uint8_t *buf, int buf_size)
{
    PGSSubContext *ctx = avctx->priv_data;

    const uint8_t *buf_end = buf + buf_size;
    const uint8_t *cm      = ff_cropTbl + MAX_NEG_CROP;
    int color_id;
    int y, cb, cr, alpha;
    int r, g, b, r_add, g_add, b_add;

    /* Skip two null bytes */
    buf += 2;

    while (buf < buf_end) {
        color_id  = bytestream_get_byte(&buf);
        y         = bytestream_get_byte(&buf);
        cb        = bytestream_get_byte(&buf);
        cr        = bytestream_get_byte(&buf);
        alpha     = bytestream_get_byte(&buf);

        YUV_TO_RGB1(cb, cr);
        YUV_TO_RGB2(r, g, b, y);

        av_dlog(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);

        /* Store color in palette */
        ctx->clut[color_id] = RGBA(r,g,b,alpha);
    }
}
Exemple #2
0
void yuv420_to_rgb555(int width, int height,
    const  uchar* pY, int yLine,
    const  uchar* pU, int uLine,
    const  uchar* pV, int vLine,
    uchar* rgb, int rgbLine)
{
    if (!s_bCropTblInit) {
        int i;
        for (i=0;i<MAX_NEG_CROP;++i) {
            cropTbl[i] = 0;
            cropTbl[i+MAX_NEG_CROP+256] = 255;
        }
        for (i=0;i<256;++i) 
            cropTbl[i+MAX_NEG_CROP] = i;
        s_bCropTblInit = true;
    }
    int w, y, cb, cr, r_add, g_add, b_add;
    uchar*  cm = cropTbl + MAX_NEG_CROP;
    unsigned int r, g, b;

    int dx     = 2;
    int dy     = rgbLine;

    uchar* d = rgb;
    const uchar* y1_ptr = pY;
    const uchar* cb_ptr = pU;
    const uchar* cr_ptr = pV;
    int   width2 = (width + 1) >> 1;

    for(;height >= 2; height -= 2) {
        uchar* d1 = d;
        uchar* d2 = d + dy;
        const uchar* y2_ptr = y1_ptr + yLine;

        for(w = width; w >= 2; w -= 2) {
            YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
            /* output 4 pixels */
            YUV_TO_RGB2(r, g, b, y1_ptr[0]);
            RGB_OUT_555(d1, r, g, b);

            YUV_TO_RGB2(r, g, b, y1_ptr[1]);
            RGB_OUT_555(d1 + dx, r, g, b);

            YUV_TO_RGB2(r, g, b, y2_ptr[0]);
            RGB_OUT_555(d2, r, g, b);

            YUV_TO_RGB2(r, g, b, y2_ptr[1]);
            RGB_OUT_555(d2 + dx, r, g, b);

            d1 += dx+dx;
            d2 += dx+dx;

            y1_ptr += 2;
            y2_ptr += 2;
            cb_ptr++;
            cr_ptr++;
        }

        // handle odd width
        if (w) {
            YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
            YUV_TO_RGB2(r, g, b, y1_ptr[0]);
            RGB_OUT_555(d1, r, g, b);

            YUV_TO_RGB2(r, g, b, y2_ptr[0]);
            RGB_OUT_555(d2, r, g, b);
            d1 += dx;
            d2 += dx;
            y1_ptr++;
            y2_ptr++;
            cb_ptr++;
            cr_ptr++;
        }
        d += dy + dy;
        y1_ptr += 2 * yLine - width;
        cb_ptr += uLine - width2;
        cr_ptr += vLine - width2;
    }

    /* handle odd height */
    if (height) {
        uchar* d1 = d;
        for(w = width; w >= 2; w -= 2) {
            YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
            /* output 2 pixels */
            YUV_TO_RGB2(r, g, b, y1_ptr[0]);
            RGB_OUT_555(d1, r, g, b);

            YUV_TO_RGB2(r, g, b, y1_ptr[1]);
            RGB_OUT_555(d1 + dx, r, g, b);

            d1 += dx+dx;

            y1_ptr += 2;
            cb_ptr++;
            cr_ptr++;
        }
        /* handle width */
        if (w) {
            YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
            /* output 2 pixels */
            YUV_TO_RGB2(r, g, b, y1_ptr[0]);
            RGB_OUT_555(d1, r, g, b);
            d1 += dx;

            y1_ptr++;
            cb_ptr++;
            cr_ptr++;
        }
    }
}