Lisp HUG Maillist Archive

externalize-image

I'm trying to use externalize-image to move an image between windows.
I have the following test:

(defun externalize-test (file)
  (let* ((b (capi:contain (make-instance 'capi:pinboard-layout)))
         (orig (gp:load-image b file :editable :with-alpha)))
    (capi:manipulate-pinboard
     b
     (make-instance 'capi:image-pinboard-object
         :image orig :x 10 :y 10)
     :add-top)
    (let* ((ext (gp:externalize-image b orig))
           (copy (gp:load-image b ext :editable :with-alpha)))
      (capi:manipulate-pinboard
       b
       (make-instance 'capi:image-pinboard-object
           :image copy :x 100 :y (gp:image-height orig))
       :add-top))))


If I call this with a .jpg file, it works as expected, showing two
identical copies of the image from the file.  But if I call it with a
..png file, the second copy gets a black background.  What am I doing
wrong?


Re: externalize-image


On Aug 23, 2010, at 10:25 PM, Gail Zacharias wrote:

>  But if I call it with a
> .png file, the second copy gets a black background.  What am I doing
> wrong?

I get funky drawing (i.e., a blank background - did you mean "black" or "blank?") even with a jpeg unless I call gp:invalidate-rectangle on the pinboard-layout (i.e., b) after the second call to capi:manipulate-pinboard, though this may not be the underlying issue.

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Re: externalize-image

Unable to parse email body. Email id is 10488

Re: externalize-image

On Tue, Aug 24, 2010 at 12:25 AM, Raffael Cavallaro
<raffaelcavallaro@mac.com> wrote:
>
> On Aug 23, 2010, at 10:25 PM, Gail Zacharias wrote:
>
>>  But if I call it with a
>> .png file, the second copy gets a black background.  What am I doing
>> wrong?
>
> I get funky drawing (i.e., a blank background - did you mean "black" or "blank?") even with a jpeg unless I call gp:invalidate-rectangle on the pinboard-layout (i.e., b) after the second call to capi:manipulate-pinboard, though this may not be the underlying issue.

I meant black, at least that's what happens with the images I have.

It seems to have something to do with transparency.  If I set the
pinboard background to green so I can see which bits in the original
image are transparent and which are just white, I notice that the
round trip through externalize-image turns the transparent bits to
black.  In my jpg images  the background was plain white, and that
worked fine through the round trip.

So maybe externalize-image doesn't preserve the alpha values?  Is
there any way to make it do so?

>
> warmest regards,
>
> Ralph
>
>
> Raffael Cavallaro
> raffaelcavallaro@me.com
>
>
>
>
>
>


Re: externalize-image

>>>>> On Tue, 24 Aug 2010 11:21:16 -0400, Gail Zacharias said:
> 
> On Tue, Aug 24, 2010 at 12:25 AM, Raffael Cavallaro
> <raffaelcavallaro@mac.com> wrote:
> >
> > On Aug 23, 2010, at 10:25 PM, Gail Zacharias wrote:
> >
> >>  But if I call it with a
> >> .png file, the second copy gets a black background.  What am I doing
> >> wrong?
> >
> > I get funky drawing (i.e., a blank background - did you mean "black" or
> > "blank?") even with a jpeg unless I call gp:invalidate-rectangle on the
> > pinboard-layout (i.e., b) after the second call to
> > capi:manipulate-pinboard, though this may not be the underlying issue.
> 
> I meant black, at least that's what happens with the images I have.
> 
> It seems to have something to do with transparency.  If I set the
> pinboard background to green so I can see which bits in the original
> image are transparent and which are just white, I notice that the
> round trip through externalize-image turns the transparent bits to
> black.  In my jpg images  the background was plain white, and that
> worked fine through the round trip.
> 
> So maybe externalize-image doesn't preserve the alpha values?  Is
> there any way to make it do so?

Yes, that's the problem.  Externalize-image always generates a bmp file, but
there is no standard definition for bmp files with transparency.

Can you use the image access APIs (in particular,
gp:image-access-pixels-from-bgra, gp:image-access-pixels-to-bgra and
gp:make-image) instead of externalize-image?

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/


Re: externalize-image

On Tue, Aug 24, 2010 at 11:38 AM, Martin Simmons <martin@lispworks.com> wrote:
>>>>>> On Tue, 24 Aug 2010 11:21:16 -0400, Gail Zacharias said:
>>
>> On Tue, Aug 24, 2010 at 12:25 AM, Raffael Cavallaro
>> <raffaelcavallaro@mac.com> wrote:
>> >
>> > On Aug 23, 2010, at 10:25 PM, Gail Zacharias wrote:
>> >
>> >>  But if I call it with a
>> >> .png file, the second copy gets a black background.  What am I doing
>> >> wrong?
>> >
>> > I get funky drawing (i.e., a blank background - did you mean "black" or
>> > "blank?") even with a jpeg unless I call gp:invalidate-rectangle on the
>> > pinboard-layout (i.e., b) after the second call to
>> > capi:manipulate-pinboard, though this may not be the underlying issue.
>>
>> I meant black, at least that's what happens with the images I have.
>>
>> It seems to have something to do with transparency.  If I set the
>> pinboard background to green so I can see which bits in the original
>> image are transparent and which are just white, I notice that the
>> round trip through externalize-image turns the transparent bits to
>> black.  In my jpg images  the background was plain white, and that
>> worked fine through the round trip.
>>
>> So maybe externalize-image doesn't preserve the alpha values?  Is
>> there any way to make it do so?
>
> Yes, that's the problem.  Externalize-image always generates a bmp file, but
> there is no standard definition for bmp files with transparency.
>
> Can you use the image access APIs (in particular,
> gp:image-access-pixels-from-bgra, gp:image-access-pixels-to-bgra and
> gp:make-image) instead of externalize-image?

I'll give it a try.  Thanks.

>
> --
> Martin Simmons
> LispWorks Ltd
> http://www.lispworks.com/
>


Re: externalize-image

I was able to get this to work, but then I got a new set of images
from the client and it doesn't work with them.   I've attached a
sample image file.  I may be misunderstanding something about
gp:load-image.  How can I load an image that works with
make-image-access?

CL-USER 7 > (setq b (capi:contain (make-instance 'capi:output-pane)))
#<CAPI:OUTPUT-PANE  200E1B87>

CL-USER 8 > (setq im (gp:load-image b "around_small.png" :editable :with-alpha))
#<GRAPHICS-PORTS:IMAGE 200FC0D3>

CL-USER 9 > (gp:make-image-access b im)

Error: MAKE-IMAGE-ACCESS called on a non-editable image :
#<GRAPHICS-PORTS:IMAGE 200FC0D3>


On Tue, Aug 24, 2010 at 11:41 AM, Gail Zacharias <gz@clozure.com> wrote:
> On Tue, Aug 24, 2010 at 11:38 AM, Martin Simmons <martin@lispworks.com> wrote:
>>>>>>> On Tue, 24 Aug 2010 11:21:16 -0400, Gail Zacharias said:
>>>
>>> On Tue, Aug 24, 2010 at 12:25 AM, Raffael Cavallaro
>>> <raffaelcavallaro@mac.com> wrote:
>>> >
>>> > On Aug 23, 2010, at 10:25 PM, Gail Zacharias wrote:
>>> >
>>> >>  But if I call it with a
>>> >> .png file, the second copy gets a black background.  What am I doing
>>> >> wrong?
>>> >
>>> > I get funky drawing (i.e., a blank background - did you mean "black" or
>>> > "blank?") even with a jpeg unless I call gp:invalidate-rectangle on the
>>> > pinboard-layout (i.e., b) after the second call to
>>> > capi:manipulate-pinboard, though this may not be the underlying issue..
>>>
>>> I meant black, at least that's what happens with the images I have.
>>>
>>> It seems to have something to do with transparency.  If I set the
>>> pinboard background to green so I can see which bits in the original
>>> image are transparent and which are just white, I notice that the
>>> round trip through externalize-image turns the transparent bits to
>>> black.  In my jpg images  the background was plain white, and that
>>> worked fine through the round trip.
>>>
>>> So maybe externalize-image doesn't preserve the alpha values?  Is
>>> there any way to make it do so?
>>
>> Yes, that's the problem.  Externalize-image always generates a bmp file, but
>> there is no standard definition for bmp files with transparency.
>>
>> Can you use the image access APIs (in particular,
>> gp:image-access-pixels-from-bgra, gp:image-access-pixels-to-bgra and
>> gp:make-image) instead of externalize-image?
>
> I'll give it a try.  Thanks.
>
>>
>> --
>> Martin Simmons
>> LispWorks Ltd
>> http://www.lispworks.com/
>>
>

(unknown)

Unable to parse email body. Email id is 10593

Re: externalize-image


On Sep 23, 2010, at 1:40 PM, Gail Zacharias wrote:

> I was able to get this to work, but then I got a new set of images
> from the client and it doesn't work with them.   I've attached a
> sample image file.  I may be misunderstanding something about
> gp:load-image.  How can I load an image that works with
> make-image-access?
> 
> CL-USER 7 > (setq b (capi:contain (make-instance 'capi:output-pane)))
> #<CAPI:OUTPUT-PANE  200E1B87>
> 
> CL-USER 8 > (setq im (gp:load-image b "around_small.png" :editable :with-alpha))
> #<GRAPHICS-PORTS:IMAGE 200FC0D3>

Does "around_small.png" actually have an alpha channel? Does (gp:load-image b "around_small.png" :editable t) work?

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Re: externalize-image


On Sep 23, 2010, at 2:51 PM, Raffael Cavallaro wrote:

> Does "around_small.png" actually have an alpha channel?

Didn't realize you'd attached it. It appears not to have an alpha cannel. I don't think :editable :with-alpha will work unless the image already has an alpha channel.

Just add an alpha channel with an image editor (I did it with GraphicConverter - Picture:Alpha Channel:Add Alpha Channel) and then it works.

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Re: externalize-image

On Thu, Sep 23, 2010 at 3:15 PM, Raffael Cavallaro
<raffaelcavallaro@mac.com> wrote:
>
> On Sep 23, 2010, at 2:51 PM, Raffael Cavallaro wrote:
>
>> Does "around_small.png" actually have an alpha channel?
>
> Didn't realize you'd attached it. It appears not to have an alpha cannel. I don't think :editable :with-alpha will work unless the image already has an alpha channel.

How can I know whether it has an alpha channel or not before I open
it?  I do want the alpha channel if the image has one.  I am going to
be opening arbitrary image files selected by the user.


> Just add an alpha channel with an image editor (I did it with GraphicConverter - Picture:Alpha Channel:Add Alpha Channel) and then it works.
>
> warmest regards,
>
> Ralph
>
>
> Raffael Cavallaro
> raffaelcavallaro@me.com
>
>
>
>
>
>


Re: externalize-image


On Sep 23, 2010, at 3:53 PM, Gail Zacharias wrote:

> How can I know whether it has an alpha channel or not before I open
> it?

(defun image-has-alpha-p (path)
  #+mac (objc:with-autorelease-pool ()
          (objc:invoke-bool
           (objc:invoke "NSBitmapImageRep"
                        "imageRepWithData:"
                        (objc:invoke "NSData" "dataWithContentsOfFile:"
                                     (objc:invoke
                                      (objc:string-to-ns-string path)
                                      "stringByStandardizingPath")))
           "hasAlpha"))
  #+windows :no-idea)

:)

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Re: externalize-image

Unable to parse email body. Email id is 10594

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