High Resolution Images

Hi, so I have an image that is 3200 x 2000 and I imported it into documents, but when I try to use it as a sprite, Codea crashes. I was wondering if this is because it is so high res. I am using an iPad 1

@JakAttak - Can you post some code please?
Thanks!

@Zoyt, here is the URL

http://gdeluxe.com/wp-content/uploads/2011/08/osx-lion-wallpaper-andromeda.jpg

I use http.request to download it and save it

Then when I try to draw it it is either black or Codea crashes

@Zoyt, here is some example code


--# Main
-- badImage

-- Use this function to perform your initial setup
function setup()
    getImage()
end

function getImage()
    http.request("http://gdeluxe.com/wp-content/uploads/2011/08/osx-lion-wallpaper-andromeda.jpg", gotImage)
end

function gotImage(img)
    saveImage("Documents:Galaxy",img)
    sound(SOUND_PICKUP, 16598)
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    sprite("Documents:Galaxy", WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
end

Run it once for the image to download (you’ll hear a beep) and then a second time to see the error

As per v1.5.3, Maximum imported image size increased to 2048px. So you are over the image size that Codea can handle.

Try this for see if it’s the size of image, or the fact that you try to access an image not load when draw function begin :

--# Main
-- badImage

-- Use this function to perform your initial setup
function setup()
    image = false
    getImage()
end

function getImage()
    http.request("http://gdeluxe.com/wp-content/uploads/2011/08/osx-lion-wallpaper-andromeda.jpg", gotImage)
end

function gotImage(img)
    saveImage("Documents:Galaxy",img)
    sound(SOUND_PICKUP, 16598)
    image = true
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    if (image) then
        sprite("Documents:Galaxy", WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
    end
end


```

The image definitely downloads correctly. It is simply too big. Check out the roadmap thread and you can see the documentation for v1.5.3 says Codea only supports images up to 2048px.

I think there is an other way to display big image… that’s to split it with a mesh and texCoords.

@Slashin8r that only applies to those imported via the photo library.

However it does sound like your iPad 1 is simply running out of memory due to downloading and attempting to render the image (this would probably end up making about 3 copies of the image to get it into the GPU, and you have 256mb ram, of which Codea can probably use 40)

I would like to know if Codea can read PNG 8bits, I have a lot of images of that type but it wont appear in the Sprite explorer when I copy them

@Simeon - the 2048 pixel limit also applies to images created by Codea itself, because I ran into that wall recently. Exceeding the limit produces a black result.

@Simeon, I have tried it also on my iPad Mini and simply get a black screen. I believe that @Ignatz is correct

Update: Saved it to my Camera Roll and added to Codea through there. It automatically made it 2048. Now everything works as it should.

@Ignatz I imagine that is hardware dependent. A 2048px image (i.e., image(2048,2048)) on a retina device is really 4096 pixels — which happens to be the upper limit on texture resolution for iPad 3 and iPad 4. (2048 pixels is the limit for other models of iPad.)

@Simeon, ah I see, I assumed imported meant any image we add other than those supplied by Codea.

I’m running this with the Ipad4 and it crashes every time. I can manually save the image to my Dropbox and the same result. When I use Codea to paste it into Documents or Dropbox it automatically converts it to 2048x1280 non-retina and 1024x640 retina. Only then the image works.

@JakAttak, ok I found the true culprit. It is the sprite call in draw() causing all the problems. Store the image first and then call that stored image in draw() using sprite. Now the original 3200x2000 image is working.

--# Main
-- badImage
 
-- Use this function to perform your initial setup
function setup()
    done = false
    image = image(3200,2000)
    getImage()
end

function storeImage()
    image = readImage("Documents:Galaxy")
end
 
function getImage()
    http.request("http://gdeluxe.com/wp-content/uploads/2011/08/osx-lion-wallpaper-andromeda.jpg", gotImage)
end
 
function gotImage(img)
    saveImage("Documents:Galaxy",img)
    sound(SOUND_PICKUP, 16598)
    done = true
end
 
-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
 
    -- This sets the line thickness
    strokeWidth(5)
 
    -- Do your drawing here
    if (done) then
        storeImage()
    end
    
    sprite(image, WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
end

Edit: let me know if this is also working on older devices. I think I will definitely start storing every image from now on, hehe.

Crashes ipad1, ios5.1