Lisp HUG Maillist Archive

pixmaps, images, and transparency

Hi,

I am building an application using LW and CAPI. This is my first in 
lisp, and so also LW.

The UI for the application requires me to draw a fairly complex diagram 
on the screen. There will be dozens, potentially hundreds of these 
things on the screen at the same time, so they will overlap. There is 
also a fairly high computational overhead to determine the layout of 
these things (not so much drawing time, but figuring out *what* to draw 
can be time consuming).

Normally there is an opaque background. We were playing around with 
dragging them around and found that there is a real usability 
improvement if we change the alpha channel to about .5 giving us a 
degree of transparency.

Out of concern for performance I am now drawing each thing to a pixmap, 
once in 'normal' rendering, once in 'drag' rendering (i.e. with a 
transparent background), then converting the pixmaps to images and 
caching the images. If the thing changes then I create a new image. 
Pretty standard I suppose.

First questions. It is quite possible that the pixmap graphics ports 
were introduced as a way of double buffering, and that the conversion 
of a pixmap to an image for cached display, like I'm doing, was a 
secondary concern.
	- Is this approach that I've taken reasonable?
	- Obviously I'm 'spending' memory to 'buy' time, what is this actually 
costing me in memory?
	- How efficient are the internal images?
	- Is there a better way to do this?

An alternative approach is to record, somehow, the drawing instructions 
rather than keeping the image around. It may well use less memory, and 
I already know that drawing won't be an issue (as I say, it is figuring 
out what to draw...), and I can avoid the next questions....

Second questions. Are transparent backgrounds supported in images? I 
don't know if I'm doing something wrong, but the image (as a whole) has 
a background exactly the same as if there was an opaque white 
background behind my transparent background. I tried setting the 
background of the pixmap (0 0 0 0) and clearing the pixmap but this 
does not appear to have any affect. I can set the background to, blue 
say, and it will affect the background colour, but the image is still 
opaque). I've also tried setting the background in the draw-image call 
to (0 0 0 0), with no visible effect at all. Is there some colour model 
stuff I need to be aware of?

Thanks,
Bob


Re: pixmaps, images, and transparency

On Tuesday 09 December 2003 10:17 am, Bob Hutchison wrote:

Only a partial answer to one of your questions:

> I am building an application using LW and CAPI. This is my first in
> lisp, and so also LW.
....
> An alternative approach is to record, somehow, the drawing instructions
> rather than keeping the image around. It may well use less memory, and

This part, in lisp, is trivial.  You simply "record" the drawing instruction 
using a closure - #'(lambda...).  I have a drawing tool that keeps a "display 
list".  I add capi/gp things to the display list like this:

(push #'(lambda () 
    (gp:draw-rectangle pane x y w h :filled nil)) 
  display-list)

and at drawing time, the pane-display-callback contains code that simply 
funcalls each item on the display list, like this:

(dolist (func display-list)
    (funcall func))

I benchmarked this - for speed, not size - in LW - against a more traditional 
data-contained-in-a-display-list algorithm and found that the closure method, 
above, ran faster.  YMMV.

pt


Re: pixmaps, images, and transparency

Oh, that's nice! CL is getting better every time I sit down with it.

Thank you.

I'll give this a shot this afternoon.

Cheers,
Bob

On Tuesday, December 9, 2003, at 11:04  AM, tarvydas wrote:

> On Tuesday 09 December 2003 10:17 am, Bob Hutchison wrote:
>
> Only a partial answer to one of your questions:
>
>> I am building an application using LW and CAPI. This is my first in
>> lisp, and so also LW.
> ...
>> An alternative approach is to record, somehow, the drawing 
>> instructions
>> rather than keeping the image around. It may well use less memory, and
>
> This part, in lisp, is trivial.  You simply "record" the drawing 
> instruction
> using a closure - #'(lambda...).  I have a drawing tool that keeps a 
> "display
> list".  I add capi/gp things to the display list like this:
>
> (push #'(lambda ()
>     (gp:draw-rectangle pane x y w h :filled nil))
>   display-list)
>
> and at drawing time, the pane-display-callback contains code that 
> simply
> funcalls each item on the display list, like this:
>
> (dolist (func display-list)
>     (funcall func))
>
> I benchmarked this - for speed, not size - in LW - against a more 
> traditional
> data-contained-in-a-display-list algorithm and found that the closure 
> method,
> above, ran faster.  YMMV.
>
> pt
>
>


Re: pixmaps, images, and transparency

The display list technique from pt works beautifully. Thanks again for 
the suggestion.

Unfortunately, I still need to know about transparency in images. Is it 
supported?

Also, what external image types are supported? I can't seem to find 
anything documented, though it seems that compressed bmp files work.

Thanks,
Bob

On Tuesday, December 9, 2003, at 11:17  AM, Bob Hutchison wrote:

> Oh, that's nice! CL is getting better every time I sit down with it.
>
> Thank you.
>
> I'll give this a shot this afternoon.
>
> Cheers,
> Bob
>
> On Tuesday, December 9, 2003, at 11:04  AM, tarvydas wrote:
>
>> On Tuesday 09 December 2003 10:17 am, Bob Hutchison wrote:
>>
>> Only a partial answer to one of your questions:
>>
>>> I am building an application using LW and CAPI. This is my first in
>>> lisp, and so also LW.
>> ...
>>> An alternative approach is to record, somehow, the drawing 
>>> instructions
>>> rather than keeping the image around. It may well use less memory, 
>>> and
>>
>> This part, in lisp, is trivial.  You simply "record" the drawing 
>> instruction
>> using a closure - #'(lambda...).  I have a drawing tool that keeps a 
>> "display
>> list".  I add capi/gp things to the display list like this:
>>
>> (push #'(lambda ()
>>     (gp:draw-rectangle pane x y w h :filled nil))
>>   display-list)
>>
>> and at drawing time, the pane-display-callback contains code that 
>> simply
>> funcalls each item on the display list, like this:
>>
>> (dolist (func display-list)
>>     (funcall func))
>>
>> I benchmarked this - for speed, not size - in LW - against a more 
>> traditional
>> data-contained-in-a-display-list algorithm and found that the closure 
>> method,
>> above, ran faster.  YMMV.
>>
>> pt
>>
>>
>
>


Re: pixmaps, images, and transparency

I've convinced myself that I'm wrong about the compressed bmp file. I 
had been tempted to write "some kind of compressed bmp file", probably 
should have. Bmp appears to be as bad as they've always been.

Bob

On Tuesday, December 9, 2003, at 07:56  PM, Bob Hutchison wrote:

> The display list technique from pt works beautifully. Thanks again for 
> the suggestion.
>
> Unfortunately, I still need to know about transparency in images. Is 
> it supported?
>
> Also, what external image types are supported? I can't seem to find 
> anything documented, though it seems that compressed bmp files work.
>
> Thanks,
> Bob
>
> On Tuesday, December 9, 2003, at 11:17  AM, Bob Hutchison wrote:
>
>> Oh, that's nice! CL is getting better every time I sit down with it.
>>
>> Thank you.
>>
>> I'll give this a shot this afternoon.
>>
>> Cheers,
>> Bob
>>
>> On Tuesday, December 9, 2003, at 11:04  AM, tarvydas wrote:
>>
>>> On Tuesday 09 December 2003 10:17 am, Bob Hutchison wrote:
>>>
>>> Only a partial answer to one of your questions:
>>>
>>>> I am building an application using LW and CAPI. This is my first in
>>>> lisp, and so also LW.
>>> ...
>>>> An alternative approach is to record, somehow, the drawing 
>>>> instructions
>>>> rather than keeping the image around. It may well use less memory, 
>>>> and
>>>
>>> This part, in lisp, is trivial.  You simply "record" the drawing 
>>> instruction
>>> using a closure - #'(lambda...).  I have a drawing tool that keeps a 
>>> "display
>>> list".  I add capi/gp things to the display list like this:
>>>
>>> (push #'(lambda ()
>>>     (gp:draw-rectangle pane x y w h :filled nil))
>>>   display-list)
>>>
>>> and at drawing time, the pane-display-callback contains code that 
>>> simply
>>> funcalls each item on the display list, like this:
>>>
>>> (dolist (func display-list)
>>>     (funcall func))
>>>
>>> I benchmarked this - for speed, not size - in LW - against a more 
>>> traditional
>>> data-contained-in-a-display-list algorithm and found that the 
>>> closure method,
>>> above, ran faster.  YMMV.
>>>
>>> pt
>>>
>>>
>>
>>
>
>


Re: pixmaps, images, and transparency

Unable to parse email body. Email id is 1689

Re: pixmaps, images, and transparency

Thanks Dave, this helps a lot. Too bad about other image types, but I 
can live with BMPs (I'm pretty sure anyway).

Cheers,
Bob

On Wednesday, December 10, 2003, at 10:57  AM, davef@xanalys.com wrote:

>
>    Unfortunately, I still need to know about transparency in images. 
> Is it
>    supported?
>
> GP:EXTERNAL-IMAGE has a TRANSPARENT-COLOR-INDEX slot. Should be
> documented, but isn't. You can set this slot when calling
> GP:READ-EXTERNAL-IMAGE.
>
> For an illustration, play with
> examples/capi/graphics/images.lisp. Specify a non-white :BACKGROUND
> for the VIEWER pane, and change the call to READ-EXTERNAL-IMAGE like
> this:
>
>  (gp:read-external-image file :transparent-color-index 183)
>
> I used the Gimp to figure out the transparent color index.
>
> Then compile and run the example, click the "Change..." button and
> select the lwsplash.bmp file.
>
>
> TRANSPARENT-COLOR-INDEX works only for images with a color map - those
> with 256 colors or less.
>
>
>    Also, what external image types are supported?
>
> Bitmaps, only.
>
>                                                  I can't seem to find
>    anything documented, though it seems that compressed bmp files work.
>
> Yes, compressed bitmaps are supported.
>
> --
> Dave Fox			
>
> Xanalys                 http://www.lispworks.com
> Compass House
> Vision Park, Chivers Way
> Histon
> Cambridge, CB4 9AD
> England
>
>


Alpha Channels (was: pixmaps, images, and transparency)

Hi,

The transparency responses have been helpful (and I'll be using the 
information), but I really meant alpha channel values less than 1.0 -- 
do images in LW support alpha channels?

Thanks,
Bob

On Wednesday, December 10, 2003, at 11:43  AM, Bob Hutchison wrote:

> Thanks Dave, this helps a lot. Too bad about other image types, but I 
> can live with BMPs (I'm pretty sure anyway).
>
> Cheers,
> Bob
>
> On Wednesday, December 10, 2003, at 10:57  AM, davef@xanalys.com wrote:
>
>>
>>    Unfortunately, I still need to know about transparency in images. 
>> Is it
>>    supported?
>>
>> GP:EXTERNAL-IMAGE has a TRANSPARENT-COLOR-INDEX slot. Should be
>> documented, but isn't. You can set this slot when calling
>> GP:READ-EXTERNAL-IMAGE.
>>
>> For an illustration, play with
>> examples/capi/graphics/images.lisp. Specify a non-white :BACKGROUND
>> for the VIEWER pane, and change the call to READ-EXTERNAL-IMAGE like
>> this:
>>
>>  (gp:read-external-image file :transparent-color-index 183)
>>
>> I used the Gimp to figure out the transparent color index.
>>
>> Then compile and run the example, click the "Change..." button and
>> select the lwsplash.bmp file.
>>
>>
>> TRANSPARENT-COLOR-INDEX works only for images with a color map - those
>> with 256 colors or less.
>>
>>
>>    Also, what external image types are supported?
>>
>> Bitmaps, only.
>>
>>                                                  I can't seem to find
>>    anything documented, though it seems that compressed bmp files 
>> work.
>>
>> Yes, compressed bitmaps are supported.
>>
>> --
>> Dave Fox			
>>
>> Xanalys                 http://www.lispworks.com
>> Compass House
>> Vision Park, Chivers Way
>> Histon
>> Cambridge, CB4 9AD
>> England
>>
>>
>
>


Re: Alpha Channels (was: pixmaps, images, and transparency)

Unable to parse email body. Email id is 1703

Re: Alpha Channels (was: pixmaps, images, and transparency)

On Thursday, December 11, 2003, at 11:26  AM, davef@xanalys.com wrote:

>
>    The transparency responses have been helpful (and I'll be using the
>    information), but I really meant alpha channel values less than 1.0 
> --
>    do images in LW support alpha channels?
>
> Yes.
>
> But bitmaps don't support alpha channels, right? So you will need some
> way to load your non-bitmap image.
>
> One possibility is GP:MAKE-IMAGE-FROM-PORT.

This is how I got onto all this in the first place. I was drawing to a 
pixmap then making an image from that drawing. When I tried to use the 
image later it was opaque.

>
> Another possibility is this code which exploits the fact that, in
> LispWorks for Macintosh (only),

I'm using OS/X but I need this to be cross platform, so as tempting as 
this is I'll have to pass on it.

Cheers,
Bob


Updated at: 2020-12-10 08:58 UTC