Re: What color spaces are supported and how to decode them?

1,103 views
Skip to first unread message

Urvang Joshi

unread,
Jan 4, 2013, 2:15:42 PM1/4/13
to webp-d...@webmproject.org
Hi PrasannaKumar,
Answers to your questions inline:

On Fri, Jan 4, 2013 at 10:06 AM, <prasanna...@gmail.com> wrote:
Hi All,

In libwebp library there are some color spaces listed (RGB, RGBA, BGR, BGRA, YUV, etc). It also mentions about RBG565, RGBA4444 etc. In the WebPGetInfo API only the height and width of the image is obtained but not the color depth and color space info. Based on height, width and the color depth I want to allocate a buffer to store the info and use it for further processing.

As noted in the specification, internally, WebP bitstream always stores pixels in a fixed colorspace and color depth:
(a) In case of a lossy bitstream, pixels are stored in Y’CbCr format (YUV420). If alpha is present, it is stored separately in ALPH chunk.
(b) In case of a lossless bitstream, pixels are stored in ARGB format.

However, both the encode & decode APIs allow specifying a variety of colorspaces.
 

My questions are:
1. How to get the color depth?
 
While decoding, you can decode any WebP bitstream to the colorspace of your choice. You can use the APIs WebPDecodeRGBA(), WebPDecodeARGB() etc. based on the  decode to that colorspace.
(Note that, these methods allocate the output buffer themselves, so you need not do that!)
 
2. While encoding how to set the color depth?
Suppose you have a buffer 'buf' in RGBA format. Then you can:
- Use WebPPictureImportRGBA() method to create a WebPPicture object 'pic' from 'buf'
- Use WebPEncode() method to encode the 'pic'.
 
3. What are the color spaces supported (grayscale and bw supported?)
Have a look at WEBP_CSP_MODE enum in decode.h file for a list of supported colorspaces for decoding.

WebP doesn't have a special colorspace for grayscale or black-and-white.
If you want to encode a grayscale/bw image to WebP, just convert the gray buffer to RGB buffer and encode the image normally. The encoder would be smart enough to encode it efficiently.

Hope that helps!

Regards,
Urvang
 

Regards,
PrasannaKumar

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To view this discussion on the web visit https://groups.google.com/a/webmproject.org/d/msg/webp-discuss/-/vvdu-wfd8joJ.
To post to this group, send email to webp-d...@webmproject.org.
To unsubscribe from this group, send email to webp-discuss...@webmproject.org.
For more options, visit this group at http://groups.google.com/a/webmproject.org/group/webp-discuss/?hl=en.

Vikas Arora

unread,
Jan 4, 2013, 2:18:31 PM1/4/13
to webp-d...@webmproject.org
Hi PrasannaKumar -

The WebP colorspaces (RGB, RGBA, BGR, BGRA, RBG565, RGBA4444 etc) gives you an option to decode the WebP image and return the decode-buffer in a specified color-space. It's like post-processing step (applied internally) over the decoded RGB/RGBA data. The colorspace is something that's user specific and not inherent to the WebP data (bit-stream), and that's reason it's not returned by WebPGetInfo (decode) API.

So if you want to decode the image in pre-allocated (application) buffer and intend to get the BGR color-space, you can use function 'WebPDecodeBGRInto'
WebPDecodeBGRInto(data, data_size, decode_buffer, decode_buffer_size,  row_stride)

The color-depth for encoding WebP is always 8. If you have input picture in BGR color-space (for instance), you can use WebPEncodeBGR API to encode this BGR image to WebP format. Again this provides pre-processing step on the input buffer and imports the image as RGB/RGBA buffer and then encodes it in WebP format.

WebP encoding comes in two flavors (lossy & lossless). For lossless encoding the equivalent (BGR color-space) API is WebPEncodeLosslessBGR.

Grayscale/bw input will have to be converted to either RGB or BGR data (by replicating 8 bit grayscale value to RGB colors) to encode it in WebP format.

Thanks & Reegards,
Vikas


On Fri, Jan 4, 2013 at 10:06 AM, <prasanna...@gmail.com> wrote:
Hi All,

In libwebp library there are some color spaces listed (RGB, RGBA, BGR, BGRA, YUV, etc). It also mentions about RBG565, RGBA4444 etc. In the WebPGetInfo API only the height and width of the image is obtained but not the color depth and color space info. Based on height, width and the color depth I want to allocate a buffer to store the info and use it for further processing.

My questions are:
1. How to get the color depth?
2. While encoding how to set the color depth?
3. What are the color spaces supported (grayscale and bw supported?)

prasannatsmkumar

unread,
Jan 5, 2013, 2:24:27 AM1/5/13
to webp-d...@webmproject.org
Thanks for the info. I looked into the decoder.h header and found the
enum but in encoding there is no parameter that specified the bpp (8,
16 or 24 bits). That was the reason for my doubt.

Thanks,
PrasannaKumar

prasannatsmkumar

unread,
Jan 5, 2013, 2:43:20 AM1/5/13
to webp-d...@webmproject.org
Thanks Vikas and Urvang for the detailed information.

I was trying to add WebP support to OpenCV library. OpenCV needs the
image properties to allocate buffer for decoded data. I think decoding
the image in BGR (OpenCV expects the decoded data in BGR format)
format will make sense. OpenCV pre-allocates the data buffer to store
the image data so I think using WebPDecodeBGRInto will be the apt API.

I think people who use OpenCV will have more control on conversion and
other things so support for RGB and BGR will be sufficient while
encoding.

Any further comments or suggestions related to adding WebP support in
OpenCV will be welcome.

PS: I have not yet discussed with OpenCV developers about adding WebP support.

Thanks and Regards,
PrasannaKumar

Urvang Joshi

unread,
Jan 7, 2013, 12:56:12 PM1/7/13
to webp-d...@webmproject.org
On Fri, Jan 4, 2013 at 11:43 PM, prasannatsmkumar <prasanna...@gmail.com> wrote:
Thanks Vikas and Urvang for the detailed information.

I was trying to add WebP support to OpenCV library.

Good to know!
 
OpenCV needs the
image properties to allocate buffer for decoded data. I think decoding
the image in BGR (OpenCV expects the decoded data in BGR format)
format will make sense. OpenCV pre-allocates the data buffer to store
the image data so I think using WebPDecodeBGRInto will be the apt API.

Yes, that's correct. WebPDecodeXXXInto() methods are the ones to be used when writing into pre-allocated buffers.

Urvang Joshi

unread,
Jan 7, 2013, 1:19:11 PM1/7/13
to webp-d...@webmproject.org
Btw,

I haven't looked at the code in detail, but it may be of some help.
[It may be a bit outdated though. Also, it may not be the best way to code (e.g. He's not using the 'Into' variant of decode method we just mentioned), so take it with a grain of salt].

-Urvang

Pascal Massimino

unread,
Jan 8, 2013, 1:32:38 PM1/8/13
to webp-d...@webmproject.org
Hi PrasannaKumar,

On Sat, Jan 5, 2013 at 8:43 AM, prasannatsmkumar <prasanna...@gmail.com> wrote:
Thanks Vikas and Urvang for the detailed information.

I was trying to add WebP support to OpenCV library. OpenCV needs the
image properties to allocate buffer for decoded data. I think decoding
the image in BGR (OpenCV expects the decoded data in BGR format)
format will make sense. OpenCV pre-allocates the data buffer to store
the image data so I think using WebPDecodeBGRInto will be the apt API.

yes, that's definitely the typical use-case for calling WebPDecodeBGRInto()
or any equivalent function that doesn't allocate the output buffer itself.

If none of these canned all-in-one function fit, you can still use the
advanced API to achieve this:

prasannatsmkumar

unread,
Jan 9, 2013, 1:43:18 AM1/9/13
to webp-d...@webmproject.org
On 7 January 2013 23:49, Urvang Joshi <urv...@google.com> wrote:
> Someone had started work on a patch for OpenCV 2.2 long back.
> (http://www.atinfinity.info/wiki/index.php?OpenCV%2FPatch%20to%20support%20WebP%20format%20on%20OpenCV%202.2).

I had a quick look into the code. It seems the code has some
limitations. Also the code does not check for the "WEBPVP8 " signature
to determine the file type (at least I am not able to find a place
where the file type is identified). Still some part of the code can be
reused I guess.

Thanks,
PrasannaKumar

Pascal Massimino

unread,
Jan 9, 2013, 11:05:19 AM1/9/13
to webp-d...@webmproject.org
Hi PrasannaKumar,

On Wed, Jan 9, 2013 at 7:43 AM, prasannatsmkumar <prasanna...@gmail.com> wrote:
On 7 January 2013 23:49, Urvang Joshi <urv...@google.com> wrote:
> Someone had started work on a patch for OpenCV 2.2 long back.
> (http://www.atinfinity.info/wiki/index.php?OpenCV%2FPatch%20to%20support%20WebP%20format%20on%20OpenCV%202.2).

I had a quick look into the code. It seems the code has some
limitations. Also the code does not check for the "WEBPVP8 " signature
to determine the file type (at least I am not able to find a place
where the file type is identified).

in WebPDecoder::readHeader() (grfmt_webp.cpp:49), the function
WebPGetInfo() is  called, which does the necessary checks for signatures.

Still some part of the code can be
reused I guess.

Thanks,
PrasannaKumar

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.

prasannatsmkumar

unread,
Jan 9, 2013, 1:23:39 PM1/9/13
to webp-d...@webmproject.org

If signature is valid then opencv creates the image decoder object (in this case it is webpdecoder) and then calls readheader member function. In the current code webpdecoder object is created for any image (before confirming that it is webp image). The code will work as readheader function will fail for non webp images. But logically this method destroys the purpose of checking signature (at least that is my thought). If wrong please correct me.

Thanks and Regards,
PrasannaKumar.

Reply all
Reply to author
Forward
0 new messages