codecparsers: vc1: fix bitplanes decoding (INVERT mode).

This commit is contained in:
Gwenole Beauchesne 2011-10-07 15:21:34 +02:00 committed by Thibault Saunier
parent 4280a61a23
commit 839acd54f6

View file

@ -279,23 +279,26 @@ static const VLCTable vc1_norm6_vlc_table[64] = {
static inline gboolean static inline gboolean
decode_colskip (GstBitReader * br, guint8 * data, guint width, guint height, decode_colskip (GstBitReader * br, guint8 * data, guint width, guint height,
guint stride) guint stride, guint invert)
{ {
guint x, y; guint x, y;
guint8 colskip; guint8 colskip, v;
GST_DEBUG ("Parsing colskip"); GST_DEBUG ("Parsing colskip");
invert &= 1;
for (x = 0; x < width; x++) { for (x = 0; x < width; x++) {
READ_UINT8 (br, colskip, 1); READ_UINT8 (br, colskip, 1);
if (data) { if (data) {
if (colskip) { if (colskip) {
for (y = 0; y < height; y++) for (y = 0; y < height; y++) {
READ_UINT8 (br, data[y * stride], 1); READ_UINT8 (br, v, 1);
data[y * stride] = v ^ invert;
}
} else { } else {
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
data[y * stride] = 0; data[y * stride] = invert;
} }
data++; data++;
} else if (colskip) } else if (colskip)
@ -312,22 +315,25 @@ failed:
static inline gboolean static inline gboolean
decode_rowskip (GstBitReader * br, guint8 * data, guint width, guint height, decode_rowskip (GstBitReader * br, guint8 * data, guint width, guint height,
guint stride) guint stride, guint invert)
{ {
guint x, y; guint x, y;
guint8 rowskip; guint8 rowskip, v;
GST_DEBUG ("Parsing rowskip"); GST_DEBUG ("Parsing rowskip");
invert &= 1;
for (y = 0; y < height; y++) { for (y = 0; y < height; y++) {
READ_UINT8 (br, rowskip, 1); READ_UINT8 (br, rowskip, 1);
if (data) { if (data) {
if (!rowskip) if (!rowskip)
memset (data, 0, width); memset (data, invert, width);
else { else {
for (x = 0; x < width; x++) for (x = 0; x < width; x++) {
READ_UINT8 (br, data[x], 1); READ_UINT8 (br, v, 1);
data[x] = v ^ invert;
}
} }
data += stride; data += stride;
} else if (rowskip) } else if (rowskip)
@ -448,6 +454,7 @@ bitplane_decoding (GstBitReader * br, guint8 * data,
invert_mask = 0; invert_mask = 0;
/* fall-through */ /* fall-through */
case IMODE_NORM2: case IMODE_NORM2:
invert_mask &= 3;
GST_DEBUG ("Parsing IMODE_DIFF2 or IMODE_NORM2 biplane"); GST_DEBUG ("Parsing IMODE_DIFF2 or IMODE_NORM2 biplane");
@ -455,7 +462,7 @@ bitplane_decoding (GstBitReader * br, guint8 * data,
if ((height * width) & 1) { if ((height * width) & 1) {
GET_BITS (br, 1, &v); GET_BITS (br, 1, &v);
if (pdata) { if (pdata) {
*pdata++ = v; *pdata++ = (v ^ invert_mask) & 1;
if (++x == width) { if (++x == width) {
x = 0; x = 0;
pdata += stride - width; pdata += stride - width;
@ -468,6 +475,7 @@ bitplane_decoding (GstBitReader * br, guint8 * data,
G_N_ELEMENTS (vc1_norm2_vlc_table))) G_N_ELEMENTS (vc1_norm2_vlc_table)))
goto failed; goto failed;
if (pdata) { if (pdata) {
v ^= invert_mask;
*pdata++ = v >> 1; *pdata++ = v >> 1;
if (++x == width) { if (++x == width) {
x = 0; x = 0;
@ -543,27 +551,27 @@ bitplane_decoding (GstBitReader * br, guint8 * data,
if (x) { if (x) {
if (data) if (data)
pdata = data + y * stride; pdata = data + y * stride;
decode_colskip (br, pdata, x, height, stride); decode_colskip (br, pdata, x, height, stride, invert_mask);
} }
if (y) { if (y) {
if (data) if (data)
pdata = data + x; pdata = data + x;
decode_rowskip (br, pdata, width, y, stride); decode_rowskip (br, pdata, width, y, stride, invert_mask);
} }
break; break;
case IMODE_ROWSKIP: case IMODE_ROWSKIP:
GST_DEBUG ("Parsing IMODE_ROWSKIP biplane"); GST_DEBUG ("Parsing IMODE_ROWSKIP biplane");
if (!decode_rowskip (br, data, width, height, stride)) if (!decode_rowskip (br, data, width, height, stride, invert_mask))
goto failed; goto failed;
break; break;
case IMODE_COLSKIP: case IMODE_COLSKIP:
GST_DEBUG ("Parsing IMODE_COLSKIP biplane"); GST_DEBUG ("Parsing IMODE_COLSKIP biplane");
if (!decode_colskip (br, data, width, height, stride)) if (!decode_colskip (br, data, width, height, stride, invert_mask))
goto failed; goto failed;
break; break;
} }