Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5970923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:26:40+00:00 2026-05-22T20:26:40+00:00

There seems to be some debate about whether JPEGs with alpha channels are valid

  • 0

There seems to be some debate about whether JPEGs with alpha channels are valid or not. The answer I had always understood to be correct is that in the JPEG FAQ, which is essentially “No”. (This is reiterated in another question on Stack Overflow.)

However, Java’s JPEGImageWriter in Sun’s ImageIO library will happily write and read grayscale and RGB images with an alpha channel, even though there are virtually no applications on Linux I’ve tried so far that will load such JPEGs correctly. This has been reported in the past as a bug, but Sun’s response is that these are valid files:

This is not an Image I/O bug, but rather a deficiency in the other applications
the submitter mentions. The IIO JPEGImageWriter is able to write images with
a color model that contains an alpha channel (referred to in the IJG native
source code as the “NIFTY” color spaces, such as RGBA, YCbCrA, etc.), but many applications are not aware of these color spaces. So even though these images
written by the IIO JPEG writer are compliant with the JPEG specification (which
is blind to the various color space possiblities), some applications may not
recognize color spaces that contain an alpha channel and may throw an
error or render a corrupted image, as the submitter describes.

Developers wishing to maintain compatibility with these other alpha-unaware
applications should write images that do not contain an alpha channel (such as
TYPE_INT_RGB). Developers who want the capability of writing/reading an image
containing an alpha channel in the JPEG format can do so using the Image I/O
API, but need to be aware that many native applications out there are not quite
compliant with the YCbCrA and RGBA formats.

For more information, see the Image I/O JPEG Metadata Format Specification and Usage Notes:
http://java.sun.com/j2se/1.4.1/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html

Closing as “not a bug”.
xxxxx@xxxxx 2003-03-24

I’m working with a Java application that creates files like these, and want to write some C code that will load these as fast as possible. (Essentially the problem is that the Java ImageIO library is remarkably slow at decompressing these files, and we would like to replace the loader with native code via JNI that improves this – it’s a performance bottleneck at the moment.)

There are some example files here – apologies to anyone who’s coulrophobic:

  • http://mythic-beasts.com/~mark/example-jpegs/

And here you can see the results of trying to view the grayscale+alpha and RGB+alpha images with various bit of Linux software that I believe use libjpeg:

grayscale image with alpha channel view with various programs http://mythic-beasts.com/~mark/all-alpha-bridges.png

RGB image with alpha channel view with various programs
(source: mark at mythic-beasts.com)

So it looks as if the color space is just being misinterpreted in each case. The only allowed values in jpeglib.h are:

/* Known color spaces. */

typedef enum {
        JCS_UNKNOWN,            /* error/unspecified */
        JCS_GRAYSCALE,          /* monochrome */
        JCS_RGB,                /* red/green/blue */
        JCS_YCbCr,              /* Y/Cb/Cr (also known as YUV) */
        JCS_CMYK,               /* C/M/Y/K */
        JCS_YCCK                /* Y/Cb/Cr/K */
} J_COLOR_SPACE;

… which doesn’t look promising.

If I load these images with a slightly modified version of example.c from libjpeg, the values of cinfo.jpeg_color_space and cinfo.out_color_space for each image after reading the header are as follows:

gray-normal.jpg: jpeg_color_space is JCS_GRAYSCALE, out_color_space is JCS_GRAYSCALE
gray-alpha.jpg: jpeg_color_space is JCS_CMYK, out_color_space is JCS_CMYK

rgb-normal.jpg: jpeg_color_space is JCS_YCbCr, out_color_space is JCS_RGB
rgb-alpha.jpg: jpeg_color_space is JCS_CMYK, out_color_space is JCS_CMYK

So, my questions are:

  • Can libjpeg be used to correctly read these files?
  • If not, is there an alternative C library I can use which will cope with them?

Obviously there are at least two other solutions to the more general problem:

  1. Change the software to output normal JPEGs + a PNG file representing the alpha channel
  2. Somehow improve the performance of Sun’s ImageIO

… but the first would involve a lot of code changes, and it’s not clear how to go about the latter. In any case, I think that the question of how to use libjpeg to load such files is likely to be one of more general interest.

Any suggestions would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:26:41+00:00Added an answer on May 22, 2026 at 8:26 pm

    Have you already tried libjpeg-turbo? It is supposed to be able to decode RGBA and there is already a Java wrapper for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've had some experience with Pygame, but there seems to be a lot of
I'm using EPIC, but it seems to have some drawbacks. Are there any other
Is there some easy way to pad Strings in Java? Seems like something that
There seems to be a lot of heated discussion on the net about the
There seems to be no extension method to include some arbitrary route values that
Can anyone tell me why this crashes my app? There seems to be some
There seems to be no good way to localize a WPF application. MSDN seems
There seems to be two major conventions for organizing project files and then many
There seems to be three common approaches for mapping an application end user to
So there seems to be this problem with GNU Make's $(wildcard) function keeping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.