lavc/qtrle: Use AV_PIX_FMT_PAL8 for 1-bit video

This commit fixes the lack of palettized display of 1-bit video
in the qtrle decoder. It is related to my commit of
lavf/qtpalette, which added 1-bit video to the "palettized video"
category. As far as I can see, everything works fine, but comments are
of course welcome.

Below are links to sample files, which should now be displayed properly
with bluish colors, but which were previously displayed in black &
white.

Matroska:
https://drive.google.com/open?id=0B3_pEBoLs0faNjI0cHBMWDhYY2c
Earth Spin 1-bit qtrle.mkv

QuickTime (mov):
https://drive.google.com/open?id=0B3_pEBoLs0faUlItWm9KaGJSTEE
Earth Spin 1-bit qtrle.mov

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Mats Peterson 2015-12-29 22:50:56 +01:00 committed by Michael Niedermayer
parent 4da2ac5c7a
commit bf42a7ef6d
2 changed files with 71 additions and 50 deletions

View File

@ -83,9 +83,9 @@ static void qtrle_decode_1bpp(QtrleContext *s, int row_ptr, int lines_to_change)
if(skip & 0x80) {
lines_to_change--;
row_ptr += row_inc;
pixel_ptr = row_ptr + 2 * (skip & 0x7f);
pixel_ptr = row_ptr + 2 * 8 * (skip & 0x7f);
} else
pixel_ptr += 2 * skip;
pixel_ptr += 2 * 8 * skip;
CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
if(rle_code == -1)
@ -99,19 +99,42 @@ static void qtrle_decode_1bpp(QtrleContext *s, int row_ptr, int lines_to_change)
pi0 = bytestream2_get_byte(&s->g);
pi1 = bytestream2_get_byte(&s->g);
CHECK_PIXEL_PTR(rle_code * 2);
CHECK_PIXEL_PTR(rle_code * 2 * 8);
while (rle_code--) {
rgb[pixel_ptr++] = pi0;
rgb[pixel_ptr++] = pi1;
rgb[pixel_ptr++] = (pi0 >> 7) & 0x01;
rgb[pixel_ptr++] = (pi0 >> 6) & 0x01;
rgb[pixel_ptr++] = (pi0 >> 5) & 0x01;
rgb[pixel_ptr++] = (pi0 >> 4) & 0x01;
rgb[pixel_ptr++] = (pi0 >> 3) & 0x01;
rgb[pixel_ptr++] = (pi0 >> 2) & 0x01;
rgb[pixel_ptr++] = (pi0 >> 1) & 0x01;
rgb[pixel_ptr++] = pi0 & 0x01;
rgb[pixel_ptr++] = (pi1 >> 7) & 0x01;
rgb[pixel_ptr++] = (pi1 >> 6) & 0x01;
rgb[pixel_ptr++] = (pi1 >> 5) & 0x01;
rgb[pixel_ptr++] = (pi1 >> 4) & 0x01;
rgb[pixel_ptr++] = (pi1 >> 3) & 0x01;
rgb[pixel_ptr++] = (pi1 >> 2) & 0x01;
rgb[pixel_ptr++] = (pi1 >> 1) & 0x01;
rgb[pixel_ptr++] = pi1 & 0x01;
}
} else {
/* copy the same pixel directly to output 2 times */
rle_code *= 2;
CHECK_PIXEL_PTR(rle_code);
CHECK_PIXEL_PTR(rle_code * 8);
bytestream2_get_buffer(&s->g, &rgb[pixel_ptr], rle_code);
pixel_ptr += rle_code;
while (rle_code--) {
int x = bytestream2_get_byte(&s->g);
rgb[pixel_ptr++] = (x >> 7) & 0x01;
rgb[pixel_ptr++] = (x >> 6) & 0x01;
rgb[pixel_ptr++] = (x >> 5) & 0x01;
rgb[pixel_ptr++] = (x >> 4) & 0x01;
rgb[pixel_ptr++] = (x >> 3) & 0x01;
rgb[pixel_ptr++] = (x >> 2) & 0x01;
rgb[pixel_ptr++] = (x >> 1) & 0x01;
rgb[pixel_ptr++] = x & 0x01;
}
}
}
}
@ -364,13 +387,10 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
switch (avctx->bits_per_coded_sample) {
case 1:
case 33:
avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
break;
case 2:
case 4:
case 8:
case 33:
case 34:
case 36:
case 40:
@ -446,6 +466,7 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
case 1:
case 33:
qtrle_decode_1bpp(s, row_ptr, height);
has_palette = 1;
break;
case 2:

View File

@ -1,39 +1,39 @@
#tb 0: 1/12
0, 0, 0, 1, 9600, 0xc5921aa2
0, 1, 1, 1, 9600, 0x9032fc52
0, 2, 2, 1, 9600, 0x7db0038e
0, 3, 3, 1, 9600, 0x95b73c41
0, 4, 4, 1, 9600, 0x531e4189
0, 5, 5, 1, 9600, 0xb73390ec
0, 6, 6, 1, 9600, 0x958e8221
0, 7, 7, 1, 9600, 0xd393f8a6
0, 8, 8, 1, 9600, 0xa085da1c
0, 9, 9, 1, 9600, 0x57ace74f
0, 10, 10, 1, 9600, 0x5d11a308
0, 11, 11, 1, 9600, 0x13e133b7
0, 12, 12, 1, 9600, 0x494edb86
0, 13, 13, 1, 9600, 0x43a448ea
0, 14, 14, 1, 9600, 0x3562d35b
0, 15, 15, 1, 9600, 0x0bc655d2
0, 16, 16, 1, 9600, 0xbece73a1
0, 17, 17, 1, 9600, 0x82e7cfa1
0, 18, 18, 1, 9600, 0xda29fd8f
0, 19, 19, 1, 9600, 0x70fb700b
0, 20, 20, 1, 9600, 0xaf57a6b0
0, 21, 21, 1, 9600, 0x0a5ed9b9
0, 22, 22, 1, 9600, 0xf7c62c38
0, 23, 23, 1, 9600, 0x0aa2ccfd
0, 24, 24, 1, 9600, 0xc9adabae
0, 25, 25, 1, 9600, 0x67ff0aba
0, 26, 26, 1, 9600, 0xea79a465
0, 27, 27, 1, 9600, 0x8928c626
0, 28, 28, 1, 9600, 0x8dab4111
0, 29, 29, 1, 9600, 0x81ef63f9
0, 30, 30, 1, 9600, 0xf977bc5e
0, 31, 31, 1, 9600, 0x9e6a3f4a
0, 32, 32, 1, 9600, 0x77c92865
0, 33, 33, 1, 9600, 0x3915170d
0, 34, 34, 1, 9600, 0xbe19b995
0, 35, 35, 1, 9600, 0x3e8a3077
0, 36, 36, 1, 9600, 0x1331342e
0, 37, 37, 1, 9600, 0x4d692175
0, 0, 0, 1, 77824, 0xc298c68b
0, 1, 1, 1, 77824, 0x22f7c63e
0, 2, 2, 1, 77824, 0x2aacc669
0, 3, 3, 1, 77824, 0xb428c6e9
0, 4, 4, 1, 77824, 0x5d50c786
0, 5, 5, 1, 77824, 0x8ddbc9e9
0, 6, 6, 1, 77824, 0x6dd5c9cf
0, 7, 7, 1, 77824, 0x7a72c647
0, 8, 8, 1, 77824, 0x0659c448
0, 9, 9, 1, 77824, 0x228bc465
0, 10, 10, 1, 77824, 0x87d9c3f9
0, 11, 11, 1, 77824, 0xd07dbf9c
0, 12, 12, 1, 77824, 0x9c91bc67
0, 13, 13, 1, 77824, 0xf91fb881
0, 14, 14, 1, 77824, 0x068eb41a
0, 15, 15, 1, 77824, 0x4b52b03f
0, 16, 16, 1, 77824, 0xc5e9b11b
0, 17, 17, 1, 77824, 0xf0aeac90
0, 18, 18, 1, 77824, 0x5700ad55
0, 19, 19, 1, 77824, 0x4d93a895
0, 20, 20, 1, 77824, 0x6df1aac7
0, 21, 21, 1, 77824, 0xeee6b4ae
0, 22, 22, 1, 77824, 0x6fe5bf5a
0, 23, 23, 1, 77824, 0x8c1ac3d3
0, 24, 24, 1, 77824, 0x5ab2c2da
0, 25, 25, 1, 77824, 0x6141aeab
0, 26, 26, 1, 77824, 0xbda0a2b8
0, 27, 27, 1, 77824, 0x46fa932a
0, 28, 28, 1, 77824, 0xed009680
0, 29, 29, 1, 77824, 0xf3078f3e
0, 30, 30, 1, 77824, 0x444f8b3c
0, 31, 31, 1, 77824, 0x7b468685
0, 32, 32, 1, 77824, 0x2b078646
0, 33, 33, 1, 77824, 0x9165859b
0, 34, 34, 1, 77824, 0xf96682c7
0, 35, 35, 1, 77824, 0x239186d0
0, 36, 36, 1, 77824, 0x499b8ec3
0, 37, 37, 1, 77824, 0x20658ea8