Skip to main content

[JAI] PNG file size after using JAI to convert from GIF

5 replies [Last post]
Anonymous

All,

I write a small program which uses JAI to convert GIF (125.gif) to PNG
(125.png).
My question is why the result PNG file size is twice as big as the
original GIF file size.

I appreciate if anyone can help me. I expect the result PNG file size
should be very close to the original GIF.

Thank you.
Sam

The code:
try {
InputStream is = new BufferedInputStream(new FileInputStream(
srcFile));
RenderedImage srcImage = ImageIO.read(is);

File outputFile = new File(destFile);
OutputStream os = new FileOutputStream(outputFile);

PNGEncodeParam param = new PNGEncodeParam.Palette();

ImageEncoder enc = ImageCodec.createImageEncoder("PNG", os, param);
enc.encode(srcImage);
os.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
[125.gif]
[125.png]
---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
James Howlett

I have tried setting the bitDepth to 8, by doing this:
param.setBitDepth(8);

But the file size still does not decrease and when I view the result
png in windows, it still said it is 32 bitdepth.

Thanks in advance for any help.
Sam

On 5/20/05, James Howlett wrote:
> All,
>
> I write a small program which uses JAI to convert GIF (125.gif) to PNG
> (125.png).
> My question is why the result PNG file size is twice as big as the
> original GIF file size.
>
> I appreciate if anyone can help me. I expect the result PNG file size
> should be very close to the original GIF.
>
> Thank you.

>
>
> The code:
> try {
> InputStream is = new BufferedInputStream(new FileInputStream(
> srcFile));
> RenderedImage srcImage = ImageIO.read(is);
>
> File outputFile = new File(destFile);
> OutputStream os = new FileOutputStream(outputFile);
>
> PNGEncodeParam param = new PNGEncodeParam.Palette();
>
> ImageEncoder enc = ImageCodec.createImageEncoder("PNG", os, param);
> enc.encode(srcImage);
> os.close();
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Marco Jacob

I'm not quite sure but isn't GIF a compressed format?
Does PNG also support compression? Maybe that's the
difference.

James Howlett wrote:
> I have tried setting the bitDepth to 8, by doing this:
> param.setBitDepth(8);
>
> But the file size still does not decrease and when I view the result
> png in windows, it still said it is 32 bitdepth.
>
> Thanks in advance for any help.
> Sam
>
>
> On 5/20/05, James Howlett wrote:
>
>>All,
>>
>>I write a small program which uses JAI to convert GIF (125.gif) to PNG
>>(125.png).
>>My question is why the result PNG file size is twice as big as the
>>original GIF file size.
>>
>>I appreciate if anyone can help me. I expect the result PNG file size
>>should be very close to the original GIF.
>>
>>Thank you.
>
>
>>
>>The code:
>>try {
>> InputStream is = new BufferedInputStream(new FileInputStream(
>> srcFile));
>> RenderedImage srcImage = ImageIO.read(is);
>>
>> File outputFile = new File(destFile);
>> OutputStream os = new FileOutputStream(outputFile);
>>
>> PNGEncodeParam param = new PNGEncodeParam.Palette();
>>
>> ImageEncoder enc = ImageCodec.createImageEncoder("PNG", os, param);
>> enc.encode(srcImage);
>> os.close();
>> } catch (FileNotFoundException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> } catch (IOException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>

--
Marco Jacob
picturesafe GmbH
Software Development
Lüerstraße 3
D-30175 Hannover
GERMANY

Fon: +49 511 - 856 20 54
Fax: +49 511 - 856 20 10
mailto:mjacob@picturesafe.de

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

GIF uses LZW compression and PNG uses Deflate compression. The ImageWriteParam
of the JAI-Image I/O PNG writer may be used to set the deflate compression
level via the setCompressionQuality() method.

I tried converting a sample GIF image to an index-color PNG and got images of
similar size.

Brian

On Mon, 23 May 2005, Marco Jacob wrote:

> I'm not quite sure but isn't GIF a compressed format?
> Does PNG also support compression? Maybe that's the
> difference.
>
> James Howlett wrote:
> > I have tried setting the bitDepth to 8, by doing this:
> > param.setBitDepth(8);
> >
> > But the file size still does not decrease and when I view the result
> > png in windows, it still said it is 32 bitdepth.
> >
> > Thanks in advance for any help.
> > Sam
> >
> >
> > On 5/20/05, James Howlett wrote:
> >
> >>All,
> >>
> >>I write a small program which uses JAI to convert GIF (125.gif) to PNG
> >>(125.png).
> >>My question is why the result PNG file size is twice as big as the
> >>original GIF file size.
> >>
> >>I appreciate if anyone can help me. I expect the result PNG file size
> >>should be very close to the original GIF.
> >>
> >>Thank you.
> >
> >
> >>
> >>The code:
> >>try {
> >> InputStream is = new BufferedInputStream(new FileInputStream(
> >> srcFile));
> >> RenderedImage srcImage = ImageIO.read(is);
> >>
> >> File outputFile = new File(destFile);
> >> OutputStream os = new FileOutputStream(outputFile);
> >>
> >> PNGEncodeParam param = new PNGEncodeParam.Palette();
> >>
> >> ImageEncoder enc = ImageCodec.createImageEncoder("PNG", os, param);
> >> enc.encode(srcImage);
> >> os.close();
> >> } catch (FileNotFoundException e) {
> >> // TODO Auto-generated catch block
> >> e.printStackTrace();
> >> } catch (IOException e) {
> >> // TODO Auto-generated catch block
> >> e.printStackTrace();
> >> }
> >>
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
> >
>
> --
> Marco Jacob
> picturesafe GmbH
> Software Development
> Lüerstraße 3
> D-30175 Hannover
> GERMANY
>
> Fon: +49 511 - 856 20 54
> Fax: +49 511 - 856 20 10
> mailto:mjacob@picturesafe.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

James Howlett

Brain,

Thank you for your response. I can only get the index-color PNG of
similar size if the original GIF image does not has alpha channel. If
the original GIF image has alpha channel (see attached), the result
PNG image I got is double the size.

Can you please tell me why?

Thank you.
Sam

On 5/23/05, Brian Burkhalter wrote:
> GIF uses LZW compression and PNG uses Deflate compression. The ImageWriteParam
> of the JAI-Image I/O PNG writer may be used to set the deflate compression
> level via the setCompressionQuality() method.
>
> I tried converting a sample GIF image to an index-color PNG and got images of
> similar size.
>
> Brian
>
> On Mon, 23 May 2005, Marco Jacob wrote:
>
> > I'm not quite sure but isn't GIF a compressed format?
> > Does PNG also support compression? Maybe that's the
> > difference.
> >
> > James Howlett wrote:
> > > I have tried setting the bitDepth to 8, by doing this:
> > > param.setBitDepth(8);
> > >
> > > But the file size still does not decrease and when I view the result
> > > png in windows, it still said it is 32 bitdepth.
> > >
> > > Thanks in advance for any help.
> > > Sam
> > >
> > >
> > > On 5/20/05, James Howlett wrote:
> > >
> > >>All,
> > >>
> > >>I write a small program which uses JAI to convert GIF (125.gif) to PNG
> > >>(125.png).
> > >>My question is why the result PNG file size is twice as big as the
> > >>original GIF file size.
> > >>
> > >>I appreciate if anyone can help me. I expect the result PNG file size
> > >>should be very close to the original GIF.
> > >>
> > >>Thank you.
> > >
> > >
> > >>
> > >>The code:
> > >>try {
> > >> InputStream is = new BufferedInputStream(new FileInputStream(
> > >> srcFile));
> > >> RenderedImage srcImage = ImageIO.read(is);
> > >>
> > >> File outputFile = new File(destFile);
> > >> OutputStream os = new FileOutputStream(outputFile);
> > >>
> > >> PNGEncodeParam param = new PNGEncodeParam.Palette();
> > >>
> > >> ImageEncoder enc = ImageCodec.createImageEncoder("PNG", os, param);
> > >> enc.encode(srcImage);
> > >> os.close();
> > >> } catch (FileNotFoundException e) {
> > >> // TODO Auto-generated catch block
> > >> e.printStackTrace();
> > >> } catch (IOException e) {
> > >> // TODO Auto-generated catch block
> > >> e.printStackTrace();
> > >> }
> > >>
> > >>
> > >>
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > > For additional commands, e-mail: interest-help@jai.dev.java.net
> > >
> > >
> > >
> >
> > --
> > Marco Jacob
> > picturesafe GmbH
> > Software Development
> > Lüerstraße 3
> > D-30175 Hannover
> > GERMANY
> >
> > Fon: +49 511 - 856 20 54
> > Fax: +49 511 - 856 20 10
> > mailto:mjacob@picturesafe.de
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Advanced Development, Graphics and Media
> Software Chief Technology Office
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended recipient(s)
> and may contain confidential and privileged information. Any
> unauthorized review, use, disclosure or distribution is prohibited.
> If you are not the intended recipient, please contact the sender by
> reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
[125.gif]
[125-jai.png]
---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

James/Sam,

I observe similar results whether I use the JAI encoder, the core J2SE PNG
writer or the JAI-Image I/O Tools PNG writer: the output when the alpha
channel is removed is significantly smaller than if the alpha channel is
present. My best guess as to the reason is that the present of the
constant-valued alpha channel has a deleterious effect on the performance of
the Defalte compression algorithm.

Brian

On Mon, 23 May 2005, James Howlett wrote:

> Brain,
>
> Thank you for your response. I can only get the index-color PNG of
> similar size if the original GIF image does not has alpha channel. If
> the original GIF image has alpha channel (see attached), the result
> PNG image I got is double the size.
>
> Can you please tell me why?
>
> Thank you.
> Sam
>
>
>
> On 5/23/05, Brian Burkhalter wrote:
> > GIF uses LZW compression and PNG uses Deflate compression. The ImageWriteParam
> > of the JAI-Image I/O PNG writer may be used to set the deflate compression
> > level via the setCompressionQuality() method.
> >
> > I tried converting a sample GIF image to an index-color PNG and got images of
> > similar size.
> >
> > Brian
> >
> > On Mon, 23 May 2005, Marco Jacob wrote:
> >
> > > I'm not quite sure but isn't GIF a compressed format?
> > > Does PNG also support compression? Maybe that's the
> > > difference.
> > >
> > > James Howlett wrote:
> > > > I have tried setting the bitDepth to 8, by doing this:
> > > > param.setBitDepth(8);
> > > >
> > > > But the file size still does not decrease and when I view the result
> > > > png in windows, it still said it is 32 bitdepth.
> > > >
> > > > Thanks in advance for any help.
> > > > Sam
> > > >
> > > >
> > > > On 5/20/05, James Howlett wrote:
> > > >
> > > >>All,
> > > >>
> > > >>I write a small program which uses JAI to convert GIF (125.gif) to PNG
> > > >>(125.png).
> > > >>My question is why the result PNG file size is twice as big as the
> > > >>original GIF file size.
> > > >>
> > > >>I appreciate if anyone can help me. I expect the result PNG file size
> > > >>should be very close to the original GIF.
> > > >>
> > > >>Thank you.
> > > >
> > > >
> > > >>
> > > >>The code:
> > > >>try {
> > > >> InputStream is = new BufferedInputStream(new FileInputStream(
> > > >> srcFile));
> > > >> RenderedImage srcImage = ImageIO.read(is);
> > > >>
> > > >> File outputFile = new File(destFile);
> > > >> OutputStream os = new FileOutputStream(outputFile);
> > > >>
> > > >> PNGEncodeParam param = new PNGEncodeParam.Palette();
> > > >>
> > > >> ImageEncoder enc = ImageCodec.createImageEncoder("PNG", os, param);
> > > >> enc.encode(srcImage);
> > > >> os.close();
> > > >> } catch (FileNotFoundException e) {
> > > >> // TODO Auto-generated catch block
> > > >> e.printStackTrace();
> > > >> } catch (IOException e) {
> > > >> // TODO Auto-generated catch block
> > > >> e.printStackTrace();
> > > >> }
> > > >>
> > > >>
> > > >>
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > > > For additional commands, e-mail: interest-help@jai.dev.java.net
> > > >
> > > >
> > > >
> > >
> > > --
> > > Marco Jacob
> > > picturesafe GmbH
> > > Software Development
> > > Lüerstraße 3
> > > D-30175 Hannover
> > > GERMANY
> > >
> > > Fon: +49 511 - 856 20 54
> > > Fax: +49 511 - 856 20 10
> > > mailto:mjacob@picturesafe.de
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > > For additional commands, e-mail: interest-help@jai.dev.java.net
> > >
> > >
> >
> > ----------------
> > Brian Burkhalter
> > Advanced Development, Graphics and Media
> > Software Chief Technology Office
> > Sun Microsystems, Inc.
> >
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > This email message is for the sole use of the intended recipient(s)
> > and may contain confidential and privileged information. Any
> > unauthorized review, use, disclosure or distribution is prohibited.
> > If you are not the intended recipient, please contact the sender by
> > reply email and destroy all copies of the original message.
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net