3.2.7 readImage seems not to work

super, thanks! i hope something got added to the automated test suite that’s run before all releases.

@RonJeffries sorry about the bug, there were changes (optimisations) made the image class for Shade that got merged into Codea’s codebase. We’ve now fixed them in 3.2.8 while maintaining the optimisations from Shade (just preventing unnecessary copies into/out of GPU memory where possible, allowing better use of RAM)

Super. I look forward to seeing an updates soon. Optimizations are tricky: my experience is that they break things rather often. The only thing I’ve found really useful, since I don’t really get smarter over time, is automated tests, which are often possible.

Typically our approach is don’t optimise unless there’s an actual problem.

Unfortunately, that happened with Shade. Very large graphs were not able to load on older devices due to limited RAM, and would just crash. We were able to cut down memory use by 30-40% or so by optimising the image class backing store to reduce copying. Apple should approve 3.2.8 with the fix shortly

Yes, i had no doubt that it was needed. Just lecturing, as is my wont. Thanks!

@Simeon I’m guessing this issue is related to the image copy problem - but saveImage is not working correctly - It just seems to save a completely transparent image. Hopefully solved in 3.2.8

Edit: 3.2.8 just arrived and problem solved. Thanks

Maybe a related issue. I have a simple image as a PNG file. If I use image:copy() the new image is distorted (colour, transparency etc… not shape). Whereas if I set up a loop to copy every pixel - the result is as it should be. The attached picture shows the original image at the top, a pixel by pixel copy on the left and the image:copy() on the right.

@timber that looks like the copy has a premultiplied alpha channel. I’ll look into it

@timber for now, try setting this blendMode prior to rendering your copied version of the image:

blendMode(ONE, ONE_MINUS_SRC_ALPHA)
-- render your image copy

blendMode(NORMAL)
-- render the non-copy version 

@timber oh, actually it looks like the issue is that img:copy fails to copy the premultiplied flag of the original image.

So on your image copy do the following:

imgCopy.premultiplied = true

Then Codea will know to render your image with a premultiplied blend mode already set up

I’ve fixed this for the next version of Codea so that the premultiplied flag is correctly copied on using image:copy

@Simeon thanks for helping, your suggestion

imgCopy.premultiplied = true

works for the copied image, but not if you save and subsequently reload the image. See code below:

 -- ImageCopy

function setup()
    img=readImage(asset.documents.a1)
    img.premultiplied=true
end

function draw()
    background(40, 40, 50)
    sprite(img,WIDTH/2,HEIGHT/2)
end

function touched(touch)
    if touch.state==BEGAN then
        saveImage(asset.documents.."test",img)
        img=readImage(asset.documents.."test")
        img.premultiplied=true
        
    end
end

Tapping the screen saves and reloads the image, the result gets worse and worse - the attached screen prints show initial screen and then 5 iterations later. Maybe the changes you are making solve this too, but thought I should share.

@timber looks like we have an internal, undocumented flag on the saveImage function which fixes this behaviour

For now, please use:

saveImage(asset.documents.."test", img, 0)

The 0 at the end tells Codea to save the image assuming it is a premultiplied type. We should be checking the premultiplied flag in this case, but it’s not and it’s a change I will make. (Using 1 saves as non-premultiplied, the default.)

@timber this will be fixed in 3.2.9 to respect the image premultiply flag on saveImage

@Simeon. Fixed - thanks for your quick response to solving this. Cheers

@dave1707 @Simeon - couple of things in 3.2.8 both may have been there a while.

First tried to record video on a number of projects, including mesh example, when the dialogue for allow don’t allow access to photos/videos popped up, selected don’t allow and Codea crashed.

Secondly the cursor positioning and scrolling when a a selection is being made, while the keyboard is present is problematic - slow dodgy near the keyboard and sometimes scrolls in the wrong direction.

.