Image Masking Mystery

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: Image Masking Mystery

Post by RCozens » Wed Aug 11, 2021 7:34 am

Evening All,

Mystery Solved!...mea culpa (as usual)

In the end it turns out the root of my problem was the alphaData was not being set.

I scripted:

if maskData then
set the aplhaData of image id newIdNumber to alphaPixels
set the maskData of image id newIdNumber to maskPixels
end if

instead of :

if maskColor then......

Now my image is mostly transparent, and that has raised a new issue. Before scripting Serendipity Editors I read what I could find in the documentation and on the forum on exporting/saving images. [I would note here that the User Guide I downloaded from the LiveCode website and the Guide tab of the LiveCode Dictionary present somewhat different (& conflicting?) information regarding the export command.] Regarding imageData I read very explicit warnings not to modify the first 10 pixels. In all my handlers referencing imageData I have started with the 11th pixel. Now that I have achieved transparency, I find the first 10 pixels are still opaque. I modified the scanImage handler to begin with pixel 1, and, low and behold, the first 10 pixels are still showing 255 in the alphaByte. The examples Bernd sent me start processing with the first byte; so I have come to believe the info I found on the forum is incorrect. But before I change more code I am hoping to get confirmation of that belief from the forum.

Once I'm sure I'm processing the correct pixels I have only one small issue to finish up my image editor and concentrate on the icon editor. I would like the editor to be able to export all images in any format LiveCode supports. I allow all those image types in my ask file command and put word 1 of the result into imageType and the file path into exportFile.

But

--set the selected of image id imageNumber to true
-- export image to file exportFile as imageType

will not compile (thus the --s in my handler) because the Script Editor says there is a syntax error in the second line.

So I'm substituting

put image id imageIdNumber into URL ("binfile:" & exportFile)

but that does not allow the user to save an image of one format to another format.

Instructions on how to get the export command to work would be most appreciated. (I presume one can export an image in it's original format using the same syntax?)

Cheers!
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Image Masking Mystery

Post by jacque » Wed Aug 11, 2021 5:14 pm

Have you looked at the "export snapshot" command? It's a bit newer and has more options.

The original command should also work if you specify the image more precisely. No need to select it first.

Code: Select all

export image id imageIdNumber to file exportFile as imageType
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4002
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Image Masking Mystery

Post by bn » Wed Aug 11, 2021 5:51 pm

Regarding imageData I read very explicit warnings not to modify the first 10 pixels.
This baffles me. The only explanation I could think of is that the raw jpeg binary is meant. Maybe that part contains special information like EXIF data or so.
ImageData on the other hand is provided by LC and is a complete representation of the pixels on screen not more and not less. Four bytes for each pixel. Byte one for transparency or alpha (although that does not work for me and I tend to ignore byte one) byte two to four for color information as Red Green and Blue.
(I know you know this but I wanted to state it explicitely here for anyone who is not familiar with imageData)

Kind regards
Bernd

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: Image Masking Mystery

Post by RCozens » Thu Aug 12, 2021 6:22 pm

Jacque wrote, "Have you looked at the "export snapshot" command? It's a bit newer and has more options." Thank you for the suggestion, Jacque. Note: the maskFile argument of export snapshot only applies to PMB format images.

The export snapshot command was one of the two issues that started me working on Serendipity Editors: when I took a snapshot of an image with transparent pixels the effective background color replaced the transparency; so I needed a way to mask out the background color. Thus Serendipity Image Editor. (The other issue was I couldn't find the GIF editor I used before my hiatus from programming, and the two editors I downloaded didn't give me the capabilities I wanted. Thus Serendipity Icon Editor.)

So if I were to use export screenshot, I would still have to import the resulting image file and mask it. As noted, I can export the masked image in its original format; but I wanted the capability for the user to import an image in one format and export it in another (or several) formats. I've tried various formats for the export command which seem to replicate examples from the User Manual and/or the Guide tab of the Dictionary, but none of my efforts have been successful.
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: Image Masking Mystery

Post by RCozens » Thu Aug 12, 2021 6:33 pm

Thanks for your comments here and the examples you sent me, Bernd. It was pretty obvious from your examples and my results that I need to address all pixels in the imageData. My message was basically a heads up to others who might read what I read and interpret it (incorrectly?) as I did. As you noted, perhaps the reference was to something other than the imageData. There were some confusing references that indicated the first pixel mentioned was pixel #0, not #1.
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: Image Masking Mystery

Post by RCozens » Thu Aug 12, 2021 7:49 pm

A special good morning to SparkOut,

I have not responded to your post because I have been considering whether I, as a new participant, had the audacity to post a mild rant. Knowing there was one more person here who remembers me (and being vain enough to believe my former presence was more notable than notorious) has tipped the scale to respond to a hot button of mine that was pushed when the forum's robo monitor informed me that ".livecode" is not a valid file extension.

Following is an off-topic rant... read on at your own discretion:

The first computer I operated was Oakland CA Police Department's HP2100a. To turn it on one had to set sixteen front panel switches and feed it a punched paper tape. That was 1974. Over the next 30 years I watched the development of both the hardware technology and programming platforms as computers became more and more useful at doing the jobs we wanted them to do. Since then I perceive a growing disparity between the world as I see it and the world as the computer presents it, and I believe that, if that trend continues, societal irritation sparked by this disparity will eventually eclipse that experienced during COVID lockdown.

If the forum robot wants to screen attachment names and exclude certain ones, then it should tell me so, not tell me the file I just selected from the OS's file picker is invalid. What would your response be if you clicked on a particular day on a visual calendar and the computer respond "The date you selected is not legal"?

And these sources of small irritations abound.

Since Google's last update, every time I enter my valid user name and password I'm asked whether my current account information should be used. I have a current account, and I'm logging in; why is it a mystery to Google what I want? And so it goes, and admittedly I've become hyper sensitive to it.

Obviously this falls back on system designers and programmers, and computers as well as computer AI can only be as smart as the people who program them. Try watching YouTube with auto-generated captioning and tell me you're ready to replace the world as you know it with the one your computer mandates.

End of rant.

Cheers!
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Image Masking Mystery

Post by PaulDaMacMan » Fri Aug 13, 2021 2:33 am

You probably already understand this, but I'd just like to note that not all graphics file formats support alpha channels, you need to use PNG ( I guess PBM works too but it's a lot less popular format). JPEG File format does not support Alpha/Mask channels.

Before reading this thread I was completely unaware that there are two different LC keywords for Alpha and Mask!
I don't see what the point of that is though, unless it's for backward compatibility or something.
Does this mean we get to use two masks/alpha channels, one being 1-bit pixels (0-1) and the other being 8 bit (0-255) pixels?
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Image Masking Mystery

Post by jacque » Fri Aug 13, 2021 6:10 pm

@Rob: As far as I know, the only extensions allowed in this off-the-shelf forum software are txt and zip. This is presumably for security reasons, though if I were to download a zip file and expand it, I wouldn't be any more secure than not.

But you're right, the error message should at least tell you why and how to fix it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Image Masking Mystery

Post by stam » Fri Aug 13, 2021 6:12 pm

jacque wrote:
Fri Aug 13, 2021 6:10 pm
@Rob: As far as I know, the only extensions allowed in this off-the-shelf forum software are txt and zip.
I think .jpg and possibly other image formats as well?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Image Masking Mystery

Post by jacque » Sat Aug 14, 2021 5:28 pm

Oh right. I should have remembered images given the number of them posted here.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: Image Masking Mystery

Post by RCozens » Sat Aug 14, 2021 7:21 pm

PaulDaMacMan wrote:
Fri Aug 13, 2021 2:33 am
You probably already understand this, but I'd just like to note that not all graphics file formats support alpha channels, you need to use PNG ( I guess PBM works too but it's a lot less popular format). JPEG File format does not support Alpha/Mask channels.

Before reading this thread I was completely unaware that there are two different LC keywords for Alpha and Mask!
I don't see what the point of that is though, unless it's for backward compatibility or something.
Does this mean we get to use two masks/alpha channels, one being 1-bit pixels (0-1) and the other being 8 bit (0-255) pixels?
Hi Paul,

Add GIF to that list...and gifs can be animated too.

Here's my understanding of the relationship between imageData, alphaData, and maskData:

* imageData has four bytes per pixel: alpha, red, green, blue. alphaData & maskData have one byte per pixel: alpha.

* Any change you make to the imageData's alpha byte for a pixel is overridden by the alphaData's setting for that pixel.

* The alphaData determines the blend level of the image. If the alphaData for a pixel is 0, that pixel is transparent.

* The maskData for a pixel overrides the alpha data. If it is 0 the pixel is transparent regardless of the alphaData setting.

Cheers!
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

Post Reply

Return to “Talking LiveCode”