Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Loading images from memory — Gideros Forum

Loading images from memory

JaviJavi Member
edited June 2012 in Suggestions & requests
Hi,

Is there any way in Gideros to load images from memory?

It'd be great, for example, to load encrypted PNGs:
texture = Texture.new(loadAndDecrypt("image.png"))
(...)
pack = TexturePack.new("pack.txt", loadAndDecrypt("pack.png"))
(...)
It'd be easy to check if "filename" param in Texture.new(...) starts with the PNG 8-bytes signature.

Dislikes: zakkwylde666, camelot10

+1 -1 (+0 / -2 )Share on Facebook

Comments

  • You could also "embed" your images in the app to help protect resources, I make a point of always embedding the images in my PC apps as I think it looks better when you can just distribute a single .exe without having to have lot's of messy data files hanging around.

    Likes: atilim

    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
    +1 -1 (+1 / -0 )Share on Facebook
  • atilimatilim Maintainer
    edited June 2012
    I'm planning to add an Image class to:
    - load png/jpg files
    - get/set pixels on it
    - create a Texture object from an Image object

    So that the code
    local image = Image.new("image.png")
    local texture = Texture.new(image)
    will be (almost) same as
    local texture = Texture.new("image.png")
    On the other hand, I'm still thinking about whether Image class should load @2x or @half image files automatically. Most probably, it will also accept an additional parameter to control this behavior.

    And then we'll have Bitmap, Image and Texture classes to confuse people more :)
  • JaviJavi Member
    edited June 2012
    Hi Atilim,

    I made these suggestions about PNGs because I'm working on a project that needs to create textures loading pngs from memory and render sprites (and its children) as png memory streams (to save/send).
    Just a new method in sprite class and a modification in the Texture class constructor to accept also the pngs directly as a string.
    local png_stream = sprite:getPng()
    (...)
    local texture = Texture.new(png_stream)
    (...)
    BTW, instead of adding Image class, did you consider using RGBA arrays? just two new functions:
    -- Get a RGBA array from a PNG stream
    local rgba = pngToRgba(png)
    (...) -- read/write directly any pixel, for example: rgba.red[x] = 123; etc
     
    -- Get a PNG stream from a RGBA array
    local png = rgbaToPng(rgba)
    (...) -- now you can save it, send it, make a texture...
    I think Gideros would be really good managing graphics with these additions.
  • Bitmap, Texture is confusing already. Bitmap, Texture, and Image classes would certainly be confusing. What would be the difference between a Texture and Image?

    If I understand the differences correctly I'd name them ImageSprite, ImageTexture, and ImageBuffer. It's kinda late to change the API that much though I think.
  • atilimatilim Maintainer
    @Javi I understand now. For this, you need to wait for render to texture and I'm not sure when we'll support saving as png files.

    @Magnusviri agree. Image and Texture are mostly similar. The main difference is the data of Image is stored at CPU memory but the data of Texture is stored at GPU memory. And it's easy/fast to modify the contents of an Image but finally you need to create a Texture to display it.
  • I see. Maybe using TextureRep or ImageRep instead of Bitmap would clarify what it is.
  • oliverhuntoliverhunt Member
    edited March 2014
    I do not know whether you are the same person, but there is a similar post for with a suggested answer. Maybe you can have a look.

    But I can not post the link.

    stackoverflow.com/questions/17912415/gideros-image-dinamic-load-and-delete-from-memory
Sign In or Register to comment.