in Extended WebP file header, the bits order for flags is in "big-endian" or "little-endian"?

43 views
Skip to first unread message

sha...@gmail.com

unread,
Apr 9, 2018, 7:42:33 AM4/9/18
to webp-d...@webmproject.org
Hi,

I feel maybe there is an issue in bits order below.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Rsv|I|L|E|X|A|R|                   Reserved                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


in libwebp code, when try to get the animation bit, the code below is 
src/webp/mux_types.h:  ANIMATION_FLAG  = 0x00000002,

According to the definition in code, perhaps the bit order for flags should be reversed as below?

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|R|A|X|E|L|I|Rsv|                   Reserved                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Regards,
Solan

James Zern

unread,
Apr 9, 2018, 7:02:12 PM4/9/18
to WebP Discussion
Hi,


On Monday, April 9, 2018 at 4:42:33 AM UTC-7, 书林 wrote:
Hi,

I feel maybe there is an issue in bits order below.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Rsv|I|L|E|X|A|R|                   Reserved                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


in libwebp code, when try to get the animation bit, the code below is 
src/webp/mux_types.h:  ANIMATION_FLAG  = 0x00000002,

According to the definition in code, perhaps the bit order for flags should be reversed as below?

The order is correct, the bits in the diagrams are in MSB 0 order, from:
"Bit numbering in chunk diagrams starts at 0 for the most significant bit ('MSB 0') as described in RFC 1166."

sha...@gmail.com

unread,
Apr 9, 2018, 10:27:54 PM4/9/18
to webp-d...@webmproject.org
Hi James,

Thank you for reminding me. 

Maybe it make me confused, that this bit numbering definition does not keep consistent with other field.

For example,  In the definitions for Chunk Size/Canvas Width Minus One, etc,  I feel, these integer with LSB written first.
And in lossless specification, the definitions for image width/height/alpha bit of image, also start at 0 for LSB 0 as below.

Maybe the definitions for integer/string are of LSB first. all the lefts are of MSB first.

Thank you,
Solan

The first 28 bits of the bitstream specify the width and height of the image. Width and height are decoded as 14-bit integers as follows:

int image_width = ReadBits(14) + 1;
int image_height = ReadBits(14) + 1;

The 14-bit dynamics for image size limit the maximum size of a WebP lossless image to 16384✕16384 pixels.

The alpha_is_used bit is a hint only, and should not impact decoding. It should be set to 0 when all alpha values are 255 in the picture, and 1 otherwise.

int alpha_is_used = ReadBits(1);

The version_number is a 3 bit code that must be set to 0. Any other value should be treated as an error. [AMENDED]

int version_number = ReadBits(3);


--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss+unsubscribe@webmproject.org.
To post to this group, send email to webp-d...@webmproject.org.
Visit this group at https://groups.google.com/a/webmproject.org/group/webp-discuss/.
For more options, visit https://groups.google.com/a/webmproject.org/d/optout.

James Zern

unread,
Apr 9, 2018, 11:52:24 PM4/9/18
to WebP Discussion
Hi,


On Monday, April 9, 2018 at 7:27:54 PM UTC-7, 书林 wrote:
Hi James,

Thank you for reminding me. 

Maybe it make me confused, that this bit numbering definition does not keep consistent with other field.

For example,  In the definitions for Chunk Size/Canvas Width Minus One, etc,  I feel, these integer with LSB written first.

The layout of these values are documented here:
e.g., "A 24-bit, little-endian, unsigned integer."
 
And in lossless specification, the definitions for image width/height/alpha bit of image, also start at 0 for LSB 0 as below.

Maybe the definitions for integer/string are of LSB first. all the lefts are of MSB first.

MSB is meant to describe the bitfield layouts only. The remainder of the values are defined as separate sized types.
 

Thank you,
Solan

The first 28 bits of the bitstream specify the width and height of the image. Width and height are decoded as 14-bit integers as follows:

int image_width = ReadBits(14) + 1;
int image_height = ReadBits(14) + 1;

The 14-bit dynamics for image size limit the maximum size of a WebP lossless image to 16384✕16384 pixels.


This is part of the bitstream itself and not the riff chunk diagrams that the MSB comment refers to.
Reply all
Reply to author
Forward
0 new messages