Discussion:
[Libjpeg-turbo-users] read and write RGBA images wkith libjpeg-turbo
j***@gmail.com
2015-11-10 16:18:42 UTC
Permalink
Hi everyone,

I'm trying to add RGBA read and write via libjpeg-turbo to my
image-processing library using the IJG API.

Write seems to be simple, I just set in_color_space and
jpeg_color_space to JCS_EXT_RGBA, gave it 4 byte pixels, and I seem to
get a file that's a bit bigger.

But for the reader, I need to be able to tell if a .jpg file has been
written with this extra channel. I've puzzled over the docs and I
can't see it. How can you tell if a .jpg has an alpha?

I've tried calling jpeg_read_header() but jpeg_color_space is always
JCS_YCbCr and out_color_space seems to be always JCS_RGB, I guess for
compatibility. Where should I be looking?

Or perhaps I'm not writing the file correctly? Does anyone have an
example RGBA file I could use for testing?

This is with libjpeg-turbo from git master, if that makes a difference.

John

------------------------------------------------------------------------------
DRC
2015-11-10 18:22:18 UTC
Permalink
There is no way to store alpha channel data in a "regular" JPEG file.
You have to use JPEG XT, which is an official spec (ISO/IEC 18477), but
JPEG XT files are not widely supported. I looked into supporting them
at one time-- the idea being that libjpeg-turbo would automatically
create a JPEG XT file whenever one of the alpha-enabled colorspaces was
used during compression-- but the necessary modifications to
libjpeg-turbo to support JPEG XT Part 9 would unfortunately not be
straightforward.

At the moment, there is no difference between the "A" and "X"
colorspaces when compressing. The alpha channel is always ignored.
When decompressing, using one of the "A" colorspaces guarantees that the
alpha channel in the output image will be set to opaque, whereas using
one of the "X" colorspaces leaves that channel undefined.
Post by j***@gmail.com
Hi everyone,
I'm trying to add RGBA read and write via libjpeg-turbo to my
image-processing library using the IJG API.
Write seems to be simple, I just set in_color_space and
jpeg_color_space to JCS_EXT_RGBA, gave it 4 byte pixels, and I seem to
get a file that's a bit bigger.
But for the reader, I need to be able to tell if a .jpg file has been
written with this extra channel. I've puzzled over the docs and I
can't see it. How can you tell if a .jpg has an alpha?
I've tried calling jpeg_read_header() but jpeg_color_space is always
JCS_YCbCr and out_color_space seems to be always JCS_RGB, I guess for
compatibility. Where should I be looking?
Or perhaps I'm not writing the file correctly? Does anyone have an
example RGBA file I could use for testing?
This is with libjpeg-turbo from git master, if that makes a difference.
John
------------------------------------------------------------------------------
j***@gmail.com
2015-11-10 21:18:37 UTC
Permalink
Ah OK, I thought libjpeg-turbo was able to write an extra band. Thank
you very much for the clarification.

John
Post by DRC
There is no way to store alpha channel data in a "regular" JPEG file.
You have to use JPEG XT, which is an official spec (ISO/IEC 18477), but
JPEG XT files are not widely supported. I looked into supporting them
at one time-- the idea being that libjpeg-turbo would automatically
create a JPEG XT file whenever one of the alpha-enabled colorspaces was
used during compression-- but the necessary modifications to
libjpeg-turbo to support JPEG XT Part 9 would unfortunately not be
straightforward.
At the moment, there is no difference between the "A" and "X"
colorspaces when compressing. The alpha channel is always ignored.
When decompressing, using one of the "A" colorspaces guarantees that the
alpha channel in the output image will be set to opaque, whereas using
one of the "X" colorspaces leaves that channel undefined.
Post by j***@gmail.com
Hi everyone,
I'm trying to add RGBA read and write via libjpeg-turbo to my
image-processing library using the IJG API.
Write seems to be simple, I just set in_color_space and
jpeg_color_space to JCS_EXT_RGBA, gave it 4 byte pixels, and I seem to
get a file that's a bit bigger.
But for the reader, I need to be able to tell if a .jpg file has been
written with this extra channel. I've puzzled over the docs and I
can't see it. How can you tell if a .jpg has an alpha?
I've tried calling jpeg_read_header() but jpeg_color_space is always
JCS_YCbCr and out_color_space seems to be always JCS_RGB, I guess for
compatibility. Where should I be looking?
Or perhaps I'm not writing the file correctly? Does anyone have an
example RGBA file I could use for testing?
This is with libjpeg-turbo from git master, if that makes a difference.
John
------------------------------------------------------------------------------
_______________________________________________
Libjpeg-turbo-users mailing list
https://lists.sourceforge.net/lists/listinfo/libjpeg-turbo-users
------------------------------------------------------------------------------
DRC
2015-11-10 23:28:43 UTC
Permalink
As a note to the community, if I'm mistaken and this is perhaps more of
a straightforward hack than I think it is, please let me know, because
it would be nice to support this in the future (Mozilla, for instance,
has expressed interest in it.)
Post by j***@gmail.com
Ah OK, I thought libjpeg-turbo was able to write an extra band. Thank
you very much for the clarification.
John
Post by DRC
There is no way to store alpha channel data in a "regular" JPEG file.
You have to use JPEG XT, which is an official spec (ISO/IEC 18477), but
JPEG XT files are not widely supported. I looked into supporting them
at one time-- the idea being that libjpeg-turbo would automatically
create a JPEG XT file whenever one of the alpha-enabled colorspaces was
used during compression-- but the necessary modifications to
libjpeg-turbo to support JPEG XT Part 9 would unfortunately not be
straightforward.
At the moment, there is no difference between the "A" and "X"
colorspaces when compressing. The alpha channel is always ignored.
When decompressing, using one of the "A" colorspaces guarantees that the
alpha channel in the output image will be set to opaque, whereas using
one of the "X" colorspaces leaves that channel undefined.
Post by j***@gmail.com
Hi everyone,
I'm trying to add RGBA read and write via libjpeg-turbo to my
image-processing library using the IJG API.
Write seems to be simple, I just set in_color_space and
jpeg_color_space to JCS_EXT_RGBA, gave it 4 byte pixels, and I seem to
get a file that's a bit bigger.
But for the reader, I need to be able to tell if a .jpg file has been
written with this extra channel. I've puzzled over the docs and I
can't see it. How can you tell if a .jpg has an alpha?
I've tried calling jpeg_read_header() but jpeg_color_space is always
JCS_YCbCr and out_color_space seems to be always JCS_RGB, I guess for
compatibility. Where should I be looking?
Or perhaps I'm not writing the file correctly? Does anyone have an
example RGBA file I could use for testing?
This is with libjpeg-turbo from git master, if that makes a difference.
John
------------------------------------------------------------------------------
_______________________________________________
Libjpeg-turbo-users mailing list
https://lists.sourceforge.net/lists/listinfo/libjpeg-turbo-users
------------------------------------------------------------------------------
_______________________________________________
Libjpeg-turbo-users mailing list
https://lists.sourceforge.net/lists/listinfo/libjpeg-turbo-users
------------------------------------------------------------------------------
Loading...