Board index » delphi » How to set palette on JPEG and save that palette

How to set palette on JPEG and save that palette

How to set palette on JPEG image and save that palette in my source code
Thanks.
 

Re:How to set palette on JPEG and save that palette


Hristo,

Are you sure you need a palette. Only 256 Grey Scale JPegs use a
palette. All colour jpegs are 24 bit.

Bob
----
Sent using Virtual Access 5.01 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:How to set palette on JPEG and save that palette


Thanks, I fix the problem but I want ask you how to convert compresed JPEG
in to BMP

Quote
Bob Villiers <bob_villi...@lineone.net> wrote in message

news:VA.0000019b.00120018@lineone.net...
Quote
> Hristo,

> Are you sure you need a palette. Only 256 Grey Scale JPegs use a
> palette. All colour jpegs are 24 bit.

> Bob
> ----
> Sent using Virtual Access 5.01 - download your freeware copy now
> http://www.atlantic-coast.com/downloads/vasetup.exe

Re:How to set palette on JPEG and save that palette


Quote
Bob Villiers wrote:
> Only 256 Grey Scale JPegs use a palette. All colour jpegs are 24 bit.

Not entirely correct, I'm afraid. You might be right if you're talking
about the VCL encapsulation of the IJG code (don't know, I don't use
it). But true jpeg's as supported by this IJG code don't use a palette
to support 8bits grayscale (it's handled as true color... euh, true
grayscale, I should probably say). And both true jpeg's and the IJG code
also support cmyk in 32bits/pixel and custom color spaces and additional
alpha channels and therefore can have any number of 8bit color channels
(up to 15 or 255, don't remember exactly). The jpeg spec also allows
12bits/channel, but I've never encountered such a jpeg.

But I'm probably being a terrible bore now; what you say is probably
very correct in the VCL encapsulation (TJpegImage, is it?), and if you
meant that jpegs can't cope with palettes, you're very right again. The
reason is of course the DCT compression algorithm, which needs to be fed
meaningfull true color and becomes quite useless when fed arbitrary
palette indexes.

As for the original question, if it is really necessary to save a
palette with the image, consider either
- using another file format, that can handle palettes, like eg bmp, gif
or (highly recommendable) png
- or, if you really need to read back the palette but don't mind a true
color storage that can actually contain colors not present in this
palette, you could write the palette with the jpeg in an app marker. The
reason that you should expect to read back colors that are not present
in the palette is of course the lossy nature of jpeg compression.

Joris

Re:How to set palette on JPEG and save that palette


Joris,

Perhaps I should have said "In my experience, only 256 Grey Scale JPegs
use a palette". Actually, the use is a bit wider than the VCL.
PaintShop Pro for instance produces a grey scale Jpeg with a palette.

Bob
----
Sent using Virtual Access 5.01 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:How to set palette on JPEG and save that palette


Quote
Bob Villiers wrote:
> Perhaps I should have said "In my experience, only 256 Grey Scale JPegs
> use a palette". Actually, the use is a bit wider than the VCL.
> PaintShop Pro for instance produces a grey scale Jpeg with a palette.

Hi Bob,
As I said, I don't know the first thing about the VCL encapsulation of
LibJpeg. But I can guess... Doesn't TJpegImage internally hold a TBitmap
to store the decompressed image? When using DIBs, the only way to avoid
using three times the memory needed for a grayscale image is indeed to
use a palette with entries (0,0,0),(1,1,1),...(255,255,255). So the
memory structures used to store the decompressed image might contain a
palette, but that doesn't mean this palette is in any way present in the
actual compressed jpeg image.

As to PSP... I haven't got a clue. It's hard to believe that a
professional app would use DIBs internally in their image object. And
even if it does, it would have been logical to hide this palette from
the user, since it has nothing to do with the actual compressed jpeg
image. But I do not know PSP at all, I can't even guess what's going on
here.

Joris

Re:How to set palette on JPEG and save that palette


Joris,

I had a play with reducing a colour jpeg to grayscale using both the
VCL and the Envision library. Both produce a 256 grayscale jpeg file
with a palette. (As assessed using PaintShop Pro).

Bob
----
Sent using Virtual Access 5.01 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:How to set palette on JPEG and save that palette


Quote
Bob Villiers wrote:
> I had a play with reducing a colour jpeg to grayscale using both the
> VCL and the Envision library. Both produce a 256 grayscale jpeg file
> with a palette. (As assessed using PaintShop Pro).

Bob,

'As assessed using' is the key here. What you observe in PSP is a PSP
issue, not a jpeg issue. Same thing goes for the palette you observe in
the VCL. The actual jpeg file does not contain a palette. Some quotes:

<quote from LibJpeg.doc>
JPEG files are always full-color
or full grayscale (or sometimes another colorspace such as CMYK).
</quote>

<quote from LibJpeg.doc>
(Again, a JPEG file is never
colormapped.  But you can ask the decompressor to perform on-the-fly
color quantization to deliver colormapped output.)
</quote>

<quote from the jpeg faq>
JPEG is designed for compressing either full-color or gray-scale images
of natural, real-world scenes.
</quote>

You probably have LibJpeg.doc on your Delphi CD, and the jpeg faq can be
obtained from either http://www.jpeg.org or http://www.ijg.org/, so you
can verify these quotes. To the best of my knowledge, there are no free
docs with more authority, so please do regard these quotes as my final
answer.

Joris

Re:How to set palette on JPEG and save that palette


Joris,

Thanks for the sources. The significant quote is:

"Again, a JPEG file is never colormapped.  But you can ask the
decompressor to perform on-the-fly color quantization to deliver
colormapped output."

This probably accounts for what I have observed.

Bob
---
Sent using Virtual Access 5.01 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:How to set palette on JPEG and save that palette


Quote
Bob Villiers wrote:
> This probably accounts for what I have observed.

Possibly... Hard to say, really.

This quantization is an IJG thing, not a JPEG thing. But there are only
a very limited number of truely independent jpeg codecs on this planet,
so it's very possible PSP uses the IJG code.

So it's possible this quantization is the source of the palette, if the
palette you observed has less than 256 entries. Otherwise, this palette
is not a result of any quantization at all.

Whatever the source of this palette you observed really is, that doesn't
answer the question why PSP wants to work with a palette when internally
handling grayscale jpegs... I can understand why palettes are used when
displaying grayscale images on 8bit displays, or when interfacing
internal grayscale image objects with windows DIBs, or when the internal
grayscale image objects use windows DIBs for storage... But either way,
it still seems like a cheap hack to me...

Joris

Re:How to set palette on JPEG and save that palette


On Mon, 26 Feb 2001 18:25:37 +0100, Joris Van Damme

Quote
<as.van.damme.jo...@planetinternet.be> wrote:
>Whatever the source of this palette you observed really is, that doesn't
>answer the question why PSP wants to work with a palette when internally
>handling grayscale jpegs...

in PSP6, if you try to do an "edit palette" on a grayscale jpeg, you
get this message:

---------------------------
Paint Shop Pro 6
---------------------------
Changing the palette of a greyscale image will force the image to be
converted to 8 bit indexed color.
---------------------------
OK  
---------------------------

- Asbj?rn

Re:How to set palette on JPEG and save that palette


Quote
Lord Crc wrote:
> in PSP6, if you try to do an "edit palette" on a grayscale jpeg, you
> get this message:
> Changing the palette of a greyscale image will force the image to be
> converted to 8 bit indexed color.

Hi Asborn!

Wow, talk about a cheap hack... And they obviously didn't even botter to
hide it either. So the image has a palette, but editing the palette will
force the image to be converted into... an image with a palette? Now,
how is a innocent user supposed to make sense of that?

The message you quote seems to indicate PSP handles all grayscale images
this way. I suppose with a lot of good will I could learn to live with
that, if I were a PSP user, but it still is very very wrong. Grayscale
is a color space, not a palette. And how does it handle image operations
on grayscale images? Suddenly the palette is no longer a palette and the
indexes become true quantity values? Or does PSP simply refuse? Or
perhaps it resolves the 'indexes' and turns the image into a 24bit RGB
image or something?

Pfffwwwweewwww.... What a mess, and what a waste!!!

Joris

Re:How to set palette on JPEG and save that palette


On Tue, 27 Feb 2001 03:14:24 +0100, Joris Van Damme

Quote
<as.van.damme.jo...@planetinternet.be> wrote:
>Wow, talk about a cheap hack... And they obviously didn't even botter to
>hide it either. So the image has a palette, but editing the palette will
>force the image to be converted into... an image with a palette? Now,
>how is a innocent user supposed to make sense of that?

Well, ive seen more confusing things in my life ;)

Quote
>The message you quote seems to indicate PSP handles all grayscale images
>this way.

Yes, i belive it does.

Perhaps PSP uses a DIB internally?

- Asbj?rn

Re:How to set palette on JPEG and save that palette


Quote
Lord Crc wrote:
> Perhaps PSP uses a DIB internally?

If that is indeed the case, it means PSP is restricted as to the size of
the images, and the colorspaces. And a lot more. I used to think PSP was
probably a professional app, but, clearly, I was wrong.

Joris

Other Threads