Transparent GIFs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Transparent GIFs

Charles A. Monteiro-2
We use Aragon's StoredImage which basically delegates to ImageReader to  
locate the appropriate reader for the file in question i.e. via:

ImageReader>>>readerClassFor: imageStream

essentially spins thru its subclasses ask each if it canRead: the  
imageStream blah, blah

we use ArborGIFReaderWriter because, well because it can handle  
transparent gifs whereas the stock gif reader GIFImageReader does not seem  
to i.e. at least the transparent GIFs that we have created using tools  
such as FireWorks and Photoshop.

So what I have to do is that I have to disconnect GIFImageReader by  
overriding canRead: to return false and then letting the next guy in line  
ArborGIFReaderWriter be selected.

Questions:

1. Can GIFImageReader handle transparent GIFs. If so, how are these made?  
i.e. alpha or index transparency etc.
2. If it can't, is this on the queue to be added anytime soon. Again, I  
should not have to "disconnect" kernel classes in order for something as  
fundamental as transparent GIFs to work. Transparent images are basically  
a "must" in any modern UI.
3. I should ask if there are now any other image formats that handle  
transparency and if the respective imageReaders exist in VW.


thanks

--
Charles A. Monteiro

Reply | Threaded
Open this post in threaded view
|

Re: Transparent GIFs

Runar Jordahl
Did you look at Graphics.PNGImageReader found in parcel ImageReaders?
PNG seems to be a better-fitted format for these types of tasks, given
that it supports more types of palettes and transparency. PNG is also
"open" and free to use.

I poked around using this class and found that I could send #mask to
the reader in order to obtain a Depth1Image containing the mask.
Sadly, for all images the mask was completely filled (all back).

Previously I have learned that VisualWorks currently only has proper
support for black/white (1-bit) masks, and therefore I looked more
deeply into how "Color Type 2" is supported. I did not try using alpha
samples for transparency. With color type 2, "each pixel is an R,G,B
triple." In addition, both 8 and 16-bit color values are supported. I
only looked at 8 bit support (16,7 million colors). With color type 2,
a single color value is specified as being the transparent color.

I then tried running image TBRN2C08 from the PNG test suite:
(ImageReader fromFile: 'TBRN2C08.PNG') mask
Still the image was totally black.

Looking at the code, I found that transparentPixelValue was wrong.
Method #processTransparencyChunk seems to have a bug, and I changed
the line
transparentPixelValue := ((65280 + red bitShift: 8) + green bitShift: 8) + blue.
into:
transparentPixelValue := ((red bitShift: 16) bitOr: (green bitShift:
8)) bitOr: blue.

Note that my change only corrects the scenario I describe. It might
introduce other problems. Maybe Cincom could look at it.

After doing the changes, I was able to obtain a correct Depth1Image
for the example. Using this I it is easy to create an OpaqueImage:
OpaqueImage
        figure: (ImageReader fromFile: 'TBRN2C08.PNG') image
        shape: (ImageReader fromFile: 'TBRN2C08.PNG') mask

Having succeeded with this, the task now is finding a paint program
that allows making "Color Type 2" PNG images. I did not look at this
yet.

PNG specifications are at http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html
Test suite are at http://www.schaik.com/pngsuite/

Runar Jordahl
http://www.cincomsmalltalk.com/userblogs/runarj/blogView

Reply | Threaded
Open this post in threaded view
|

Re: Transparent GIFs

Charles A. Monteiro-2
thanks, I was aware of the PNG reader but not that PNG could be used for  
creating transparent images, I thought it was like a higher end JPG.  
Unfortunaltey, it seems that at least as far as transparency the VW  
implementation is not ready for prime time.

When using tools like Photoshop etc there is a right way i.e. as far as VW  
is concerned to create transparent GIFs. More specifically, there is a way  
that will work with ArborGIFImageReader. I have not found a way of making  
the stock GIF reader work as far as transparency.

The good news is that the ArborGIFImageReader works fine and that as far  
as we are concerned GIF is a fine enough format for creating transparent  
images. The specific transparency option that we must use does not seem to  
be, as far as we are concerned, to be a big sacrifice. I'll share that  
when I recall what that is. Also GIF works fine for us. These images are  
used strictly for icons and sometimes some other embellishments.

thanks for the info on PNG.

-Charles

On Wed, 22 Mar 2006 05:07:12 -0500, Runar Jordahl  
<[hidden email]> wrote:

> Did you look at Graphics.PNGImageReader found in parcel ImageReaders?
> PNG seems to be a better-fitted format for these types of tasks, given
> that it supports more types of palettes and transparency. PNG is also
> "open" and free to use.
>
> I poked around using this class and found that I could send #mask to
> the reader in order to obtain a Depth1Image containing the mask.
> Sadly, for all images the mask was completely filled (all back).
>
> Previously I have learned that VisualWorks currently only has proper
> support for black/white (1-bit) masks, and therefore I looked more
> deeply into how "Color Type 2" is supported. I did not try using alpha
> samples for transparency. With color type 2, "each pixel is an R,G,B
> triple." In addition, both 8 and 16-bit color values are supported. I
> only looked at 8 bit support (16,7 million colors). With color type 2,
> a single color value is specified as being the transparent color.
>
> I then tried running image TBRN2C08 from the PNG test suite:
> (ImageReader fromFile: 'TBRN2C08.PNG') mask
> Still the image was totally black.
>
> Looking at the code, I found that transparentPixelValue was wrong.
> Method #processTransparencyChunk seems to have a bug, and I changed
> the line
> transparentPixelValue := ((65280 + red bitShift: 8) + green bitShift: 8)  
> + blue.
> into:
> transparentPixelValue := ((red bitShift: 16) bitOr: (green bitShift:
> 8)) bitOr: blue.
>
> Note that my change only corrects the scenario I describe. It might
> introduce other problems. Maybe Cincom could look at it.
>
> After doing the changes, I was able to obtain a correct Depth1Image
> for the example. Using this I it is easy to create an OpaqueImage:
> OpaqueImage
> figure: (ImageReader fromFile: 'TBRN2C08.PNG') image
> shape: (ImageReader fromFile: 'TBRN2C08.PNG') mask
>
> Having succeeded with this, the task now is finding a paint program
> that allows making "Color Type 2" PNG images. I did not look at this
> yet.
>
> PNG specifications are at  
> http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html
> Test suite are at http://www.schaik.com/pngsuite/
>
> Runar Jordahl
> http://www.cincomsmalltalk.com/userblogs/runarj/blogView



--
Charles A. Monteiro

Reply | Threaded
Open this post in threaded view
|

Re: Transparent GIFs

Andre Schnoor
One way to achieve "transparent" icons is to render an original image
(i.e. GIF or PNG) against the current background color of choice and use
that icon  from a cache. This results in "pseudo"-transparent images,
looking like transparent when displayed on a matching background.

Blending RGB + alpha with a background color is a piece of cake
(although I didn't yet implement it). I could imagine a class
TransparentImage that responds to #backgroundColor: and #image: and
maintains a cached image derivate until the background color changes.

HTH

Andre

Reply | Threaded
Open this post in threaded view
|

Re: Transparent GIFs

Vassili Bykov
In reply to this post by Charles A. Monteiro-2
How is the stock GIF reader not working for you? I've been using it for
a couple of years now to import all icons for VW from external
transparent GIFs.

See ImageReader class>>iconFromFile:toClass:selector:. Or using the
reader "by hand", you send #image to the reader to get the figure for
your opaque image and #mask to get the mask. (And then you'd probably
want to wrap those in CachedImage).

PNG reader doesn't handle transparency, that's true.


Charles A. Monteiro wrote:

> thanks, I was aware of the PNG reader but not that PNG could be used for
> creating transparent images, I thought it was like a higher end JPG.
> Unfortunaltey, it seems that at least as far as transparency the VW
> implementation is not ready for prime time.
>
> When using tools like Photoshop etc there is a right way i.e. as far as
> VW is concerned to create transparent GIFs. More specifically, there is
> a way that will work with ArborGIFImageReader. I have not found a way of
> making the stock GIF reader work as far as transparency.
>
> The good news is that the ArborGIFImageReader works fine and that as far
> as we are concerned GIF is a fine enough format for creating transparent
> images. The specific transparency option that we must use does not seem
> to be, as far as we are concerned, to be a big sacrifice. I'll share
> that when I recall what that is. Also GIF works fine for us. These
> images are used strictly for icons and sometimes some other embellishments.
>
> thanks for the info on PNG.
>
> -Charles


--
Vassili Bykov <[hidden email]>

[:s | s, s printString] value: '[s: | s, s printString] value: '

Reply | Threaded
Open this post in threaded view
|

Re: Transparent GIFs

Charles A. Monteiro-2
ah, so that perhaps the issue is with the definition of "supported". I  
feel it reasonable that one should be able to tell an ImageReader to load  
a file and return a readily displayable object i.e. an object that does  
not require any further manipulations in order for it to render as  
intended. ArborGIFImageReader finds it reasonable as well and its  
implementation will return a properly created OpaqueImage when loading a  
transparent gif.

Aragon.StoredImage, a nice convenience,  works on this expectation and  
basically expects to be able to do:

(ImageReader fromFile: aFilename) image

and nothing else.

-Charles


On Wed, 22 Mar 2006 12:17:24 -0500, Vassili Bykov <[hidden email]>  
wrote:

> How is the stock GIF reader not working for you? I've been using it for  
> a couple of years now to import all icons for VW from external  
> transparent GIFs.
>
> See ImageReader class>>iconFromFile:toClass:selector:. Or using the  
> reader "by hand", you send #image to the reader to get the figure for  
> your opaque image and #mask to get the mask. (And then you'd probably  
> want to wrap those in CachedImage).
>
> PNG reader doesn't handle transparency, that's true.
>
>
> Charles A. Monteiro wrote:
>> thanks, I was aware of the PNG reader but not that PNG could be used  
>> for creating transparent images, I thought it was like a higher end  
>> JPG. Unfortunaltey, it seems that at least as far as transparency the  
>> VW implementation is not ready for prime time.
>>  When using tools like Photoshop etc there is a right way i.e. as far  
>> as VW is concerned to create transparent GIFs. More specifically, there  
>> is a way that will work with ArborGIFImageReader. I have not found a  
>> way of making the stock GIF reader work as far as transparency.
>>  The good news is that the ArborGIFImageReader works fine and that as  
>> far as we are concerned GIF is a fine enough format for creating  
>> transparent images. The specific transparency option that we must use  
>> does not seem to be, as far as we are concerned, to be a big sacrifice.  
>> I'll share that when I recall what that is. Also GIF works fine for us.  
>> These images are used strictly for icons and sometimes some other  
>> embellishments.
>>  thanks for the info on PNG.
>>  -Charles
>
>



--
Charles A. Monteiro

Reply | Threaded
Open this post in threaded view
|

Re: Transparent GIFs

Vassili Bykov
Charles A. Monteiro wrote:
> ah, so that perhaps the issue is with the definition of "supported". I
> feel it reasonable that one should be able to tell an ImageReader to
> load a file and return a readily displayable object i.e. an object that
> does not require any further manipulations in order for it to render as
> intended.

The issue is actually with the definition of "image". VW understanding
of it does not include transparency. You cannot have Images with
transparent pixels that you could just read from a file and display.

OpaqueImages are not Images. They are not even PixelArrays. They are
displayable, but anything you can do to an image, like change the color
of a pixel, you can't do to an OpaqueImage. This is the point of view of
GIFImageReader--it preserves the protocol of #image as something that
answers an Image, and adds an extra method for the opacity information,
as something that doesn't fit in the pure Image model.

I do think GIFImageReader is missing an #opaqueImage method. But,
redefining #image to be "smart" and return OpaqueImage when image has
transparency is actually a rather misguided hack that dilutes the
protocol of #image. It should be a different method instead, something
like #displayableObject. As it is, all you can expect from the result
now is that you can send #displayOn: to it--but you no longer know it's
an Image, with pixels, palette and all those other things. And, whether
you get a real image or not depends only on the input.


Reply | Threaded
Open this post in threaded view
|

Re: Transparent GIFs

Charles A. Monteiro-2
call it by whatever name you want to call it, build whatever you want to  
build :)

What I am saying is that I should very simply be able to ask some animal  
to load a file which persists a GIF and I should not care about whether it  
uses transparency at all and should just be able to then display it. For  
that matter I shold be able to spin through a directory of files which  
persist imsages and not care about the image format they were persisted in.

I want to transparently load any image. All pun intended.

That is the "ease of use" I expect from my development environment with  
regards to this scenario. Now I fully expect that I won't get my way  
anytime soon so until I do , if I do, I'll just have to be glad that the  
"hackers" at Arbor were on the aame brain wave-length.

later,

Charles

On Wed, 22 Mar 2006 19:45:04 -0500, Vassili Bykov <[hidden email]>  
wrote:

> Charles A. Monteiro wrote:
>> ah, so that perhaps the issue is with the definition of "supported". I  
>> feel it reasonable that one should be able to tell an ImageReader to  
>> load a file and return a readily displayable object i.e. an object that  
>> does not require any further manipulations in order for it to render as  
>> intended.
>
> The issue is actually with the definition of "image". VW understanding  
> of it does not include transparency. You cannot have Images with  
> transparent pixels that you could just read from a file and display.
>
> OpaqueImages are not Images. They are not even PixelArrays. They are  
> displayable, but anything you can do to an image, like change the color  
> of a pixel, you can't do to an OpaqueImage. This is the point of view of  
> GIFImageReader--it preserves the protocol of #image as something that  
> answers an Image, and adds an extra method for the opacity information,  
> as something that doesn't fit in the pure Image model.
>
> I do think GIFImageReader is missing an #opaqueImage method. But,  
> redefining #image to be "smart" and return OpaqueImage when image has  
> transparency is actually a rather misguided hack that dilutes the  
> protocol of #image. It should be a different method instead, something  
> like #displayableObject. As it is, all you can expect from the result  
> now is that you can send #displayOn: to it--but you no longer know it's  
> an Image, with pixels, palette and all those other things. And, whether  
> you get a real image or not depends only on the input.
>



--
Charles A. Monteiro

Reply | Threaded
Open this post in threaded view
|

[7.4][Pollock]Checkboxes and radiobuttons

Carl Gundel
In reply to this post by Vassili Bykov
What's the best way to add a label to a CheckBox or RadioButton in
Pollock 7.4?

Should I still be calling it Pollock?  ;-)

-Carl Gundel, author of Liberty BASIC
http://www.libertybasic.com

Reply | Threaded
Open this post in threaded view
|

Re: [7.4][Pollock]Checkboxes and radiobuttons

Carl Gundel
On Mar 22, 2006, at 8:34 PM, Carl Gundel wrote:
> What's the best way to add a label to a CheckBox or RadioButton in
> Pollock 7.4?

Oh, I figured it out myself by searching this list.  Here how I did it.

        button := CheckBox new.
        button
                addComponent: (Panda.DisplayLabel string: 'testing').

> Should I still be calling it Pollock?  ;-)

This question will stands.

-Carl

Reply | Threaded
Open this post in threaded view
|

Re: [7.4][Pollock]Checkboxes and radiobuttons

Samuel S. Shuster <sames@interaccess.com>
In reply to this post by Carl Gundel
Carl,

> What's the best way to add a label to a CheckBox or RadioButton in  
> Pollock 7.4?

For version 7.4.0, the answer is addComponent: <aLabel>

However that is changing in the next publish of Pollock.

> Should I still be calling it Pollock?  ;-)

Yes. Pollock is the framework, Panda is the Namespace and also the  
larger Plan (the Panda Plan) that includes Pollock, Corona, Chagall,  
Peaches and Cheyenne.



                                 And So It Goes
                                      Sames
______________________________________________________________________

Samuel S. Shuster [|]
VisualWorks Engineering, GUI Project
Smalltalk Enables Success -- What Are YOU Using?