Discussion:
[MPlayer-dev-eng] decoding of MS-RLE in 4-bit is buggy
Michael Günnewig
2003-06-13 18:13:46 UTC
Permalink
Hallo.

The decoding of Microsoft-RLE in 4-bit doesn't work correctly under
all circumstances. As described at

http://www.pcisys.net/~melanson/codecs/msrle.txt

must the code be aligned at a word-boundary when in absolute mode. I
have an AVI file which decodes correctly under Windows. The
problematic segment is the following (in hex):

00 09 77 70 78 88 80 00 3A 88 00 08 77 07 7F FF 29 FF 00 00

This code results that the variable rle_code will be 9 / 2, which will
be 4. This will decode the next 4 bytes into the corresponding 8
pixels. The 9th pixel will be interpreted by mplayer as an
encoded-code-segment instead of be a pixel with pal-index 9 (and skip
the 0 in the lsb) and an extra-byte for alignment. This results in
very strange decoded frames and warning-messages about violated
boundaries:

MS RLE: stream ptr just went out of bounds (1)

The fix would be to round up the computation of rle_code and leave the
for-loop in the middle when rounded up, or? But my problem is, that is
won't solve the distorted frames. Any hints?

The problematic AVI file (60 kB size) is available at:
http://ls6-www.cs.uni-dortmund.de/~guennewi/mplayer-msrle-4bit.avi


Michael
Roberto Togni
2003-06-15 15:05:00 UTC
Permalink
Post by Michael Günnewig
Hallo.
The decoding of Microsoft-RLE in 4-bit doesn't work correctly under
all circumstances. As described at
http://www.pcisys.net/~melanson/codecs/msrle.txt
must the code be aligned at a word-boundary when in absolute mode. I
have an AVI file which decodes correctly under Windows. The
00 09 77 70 78 88 80 00 3A 88 00 08 77 07 7F FF 29 FF 00 00
This code results that the variable rle_code will be 9 / 2, which will
be 4. This will decode the next 4 bytes into the corresponding 8
pixels. The 9th pixel will be interpreted by mplayer as an
encoded-code-segment instead of be a pixel with pal-index 9 (and skip
the 0 in the lsb) and an extra-byte for alignment. This results in
very strange decoded frames and warning-messages about violated
MS RLE: stream ptr just went out of bounds (1)
The fix would be to round up the computation of rle_code and leave the
for-loop in the middle when rounded up, or? But my problem is, that is
won't solve the distorted frames. Any hints?
There are at least two problems:
- the extra_byte flag needs to be computed on stream_byte, not on
rle_code (it must be done on byte count, not on nibble count). To be
exact, ytou have an extra byte if (stream_byte/2 + stream_byte%2) is odd
- the second problem is the 9th nibble not being decoded at all.

The logical solution is:
- fix extra_byte computation
- do the first half of the for cycle for the last nibble if nibble
counter is even (can be implemented in various ways, i changed the for
to be executed 9 times (in this example) and i use the i variable to
find out if i must decode the high or low nibble of the byte)
- increment the stream pointer afret the for cycle by stram_byte/2 +
stream_byte%2
- if i have an extra byte, increment stream pointer again.

But it doesn't work!
I dont't have any more errors, but the image is distorted. Looks like
something goes wrong when it checks if the current pixel position is
greater than the current line length.

I'm still looking at it.
Post by Michael Günnewig
http://ls6-www.cs.uni-dortmund.de/~guennewi/mplayer-msrle-4bit.avi
Do you have any other samples with 4 bit msrle? I'd expecially like to
have a sample that works now, to check that my fixes don't break
anything (even if, looking at the code, i wonder if it even worked at
all).
Post by Michael Günnewig
Michael
Ciao,
Roberto
Michael Günnewig
2003-06-16 17:32:26 UTC
Permalink
Post by Roberto Togni
I dont't have any more errors, but the image is distorted. Looks like
something goes wrong when it checks if the current pixel position is
greater than the current line length.
Ah, I see. Will also have a look at it.
Post by Roberto Togni
Do you have any other samples with 4 bit msrle? I'd expecially like to
have a sample that works now, to check that my fixes don't break
anything (even if, looking at the code, i wonder if it even worked at
all).
Sorry, only this one. But I could try to generate one with the encoder
in wine, even if some things are missing in there the generated files
are decoded without problems under Windows.


Michael
Michael Günnewig
2003-06-17 21:08:52 UTC
Permalink
Post by Roberto Togni
Post by Michael Günnewig
Hallo.
The decoding of Microsoft-RLE in 4-bit doesn't work correctly under
all circumstances. As described at
http://www.pcisys.net/~melanson/codecs/msrle.txt
must the code be aligned at a word-boundary when in absolute mode.
...
Post by Roberto Togni
- the extra_byte flag needs to be computed on stream_byte, not on
rle_code (it must be done on byte count, not on nibble count). To be
exact, ytou have an extra byte if (stream_byte/2 + stream_byte%2) is odd
...
Post by Roberto Togni
But it doesn't work!
Okay, I have it.

rle_code = ((stream_byte + 1) & (~1)) / 2; // same as yours
extra_byte = (stream_byte / 2) & 0x01 || (stream_byte % 2);

extra_byte is wrong comparing to spec (see above), but Windows decodes
it correct -- very strange. Will generate some very stupid
test-patterns and look at the results of Windows decoder. I'm very
interested in the results.


Michael Günnewig
Roberto Togni
2003-06-18 21:42:19 UTC
Permalink
Post by Michael Günnewig
Post by Michael Günnewig
Hallo.
The decoding of Microsoft-RLE in 4-bit doesn't work correctly under
[...]
Post by Michael Günnewig
Michael Günnewig
Sorry for not answering before, but i'll be very busy 'till the
weekend, then i'll look at it again.

Ciao,
Roberto
Michael Günnewig
2003-06-29 16:59:20 UTC
Permalink
Post by Michael Günnewig
Post by Michael Günnewig
Hallo.
The decoding of Microsoft-RLE in 4-bit doesn't work correctly under
all circumstances. As described at
http://www.pcisys.net/~melanson/codecs/msrle.txt
must the code be aligned at a word-boundary when in absolute mode.
...
Post by Michael Günnewig
Okay, I have it.
rle_code = ((stream_byte + 1) & (~1)) / 2; // same as yours
extra_byte = (stream_byte / 2) & 0x01 || (stream_byte % 2);
extra_byte is wrong comparing to spec (see above), but Windows decodes
it correct -- very strange. Will generate some very stupid
test-patterns and look at the results of Windows decoder. I'm very
interested in the results.
Okay, now I have the results. The above code works with the previous
test-video, but not with some other test-videos. I also found out that
the previous test-video was bad, but I couldn't find out why I was
possible to decode it correctly under windows -- think I have changed it
by mistacke with anotherone.

The correct code must be

rle_code = ((stream_byte + 1) & (~1)) / 2;
extra_byte = rle_code & 0x01;

which is the same as the spec says.


Michael Günnewig


The resulting patch:
Roberto Togni
2003-06-30 18:40:32 UTC
Permalink
Post by Michael Günnewig
Post by Michael Günnewig
Hallo.
The decoding of Microsoft-RLE in 4-bit doesn't work correctly
under
Post by Michael Günnewig
all circumstances. As described at
http://www.pcisys.net/~melanson/codecs/msrle.txt
must the code be aligned at a word-boundary when in absolute mode.
...
[...]
Post by Michael Günnewig
Okay, now I have the results. The above code works with the previous
test-video, but not with some other test-videos. I also found out that
the previous test-video was bad, but I couldn't find out why I was
possible to decode it correctly under windows -- think I have changed it
by mistacke with anotherone.
The correct code must be
rle_code = ((stream_byte + 1) & (~1)) / 2;
extra_byte = rle_code & 0x01;
which is the same as the spec says.
I'll apply it. Can you please upload a working sample (i don't have any
4bit MSrle files)?
Post by Michael Günnewig
Michael Günnewig
Ciao,
Roberto
Alex Beregszaszi
2003-07-20 17:31:21 UTC
Permalink
Hi,
Post by Roberto Togni
Post by Michael Günnewig
The correct code must be
rle_code = ((stream_byte + 1) & (~1)) / 2;
extra_byte = rle_code & 0x01;
which is the same as the spec says.
I'll apply it. Can you please upload a working sample (i don't have
any 4bit MSrle files)?
Any progress on this thread? I would be happy to have this fixed before
the release.
--
Alex Beregszaszi <***@fsn.hu>
(MPlayer Core Developer -- http://www.mplayerhq.hu/)
Michael Günnewig
2003-07-06 17:35:43 UTC
Permalink
Post by Roberto Togni
I'll apply it. Can you please upload a working sample (i don't have
any 4bit MSrle files)?
http://ls6-www.cs.uni-dortmund.de/~guennewi/mplayer-msrle-4bit.avi (53 kB)


Michael
Roberto Togni
2003-07-21 19:00:15 UTC
Permalink
Post by Michael Günnewig
Post by Roberto Togni
I'll apply it. Can you please upload a working sample (i don't have
any 4bit MSrle files)?
http://ls6-www.cs.uni-dortmund.de/~guennewi/mplayer-msrle-4bit.avi (53 kB)
Applied, thanks.

It works with your new sample and (obviously) fails with the old broken
one.
Post by Michael Günnewig
Michael
Ciao,
Roberto

Loading...