Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Image::SaveToMemory  (Read 3298 times)

0 Members and 2 Guests are viewing this topic.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
sf::Image::SaveToMemory
« on: February 09, 2010, 01:01:23 pm »
There is a LoadFromFile, loadFromPixelsPtr and LoadFromMemory.
There is a SaveToFile, GetPixelsPtr, but no "SaveToMemory" method.

I use my own file protocols, saving and loading images along with other data in the same file. I can load them with loadFromMemory, but I can't save them that way. I have to use GetPixelsPtr to send it to a (file) stream, and loadFromPixelsPtr when loading.
But I guess load/save from/to file/memory uses specific image format compression, and so, better than saving the pixels full data.
A SaveToMemory should receive an indication about image format (png, jpg, etc)


I have another question:
 - When using LoadFromPixelsPtr, do I have to keep my pointer and free it when the image isn't in use anymore? I would like to just send the pointer to sf::Image and let it take care of it, as I don't need the pointer for anything else (but better would be using the Load & SaveToMemory instead :P)

Thanks,
G
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Image::SaveToMemory
« Reply #1 on: February 09, 2010, 01:55:18 pm »
Quote
There is a LoadFromFile, loadFromPixelsPtr and LoadFromMemory.
There is a SaveToFile, GetPixelsPtr, but no "SaveToMemory" method.

I wouldn't be able to implement this feature at 100%, because not all the underlying libraries I use provide a way to do it. For example, libsndfile looks ok for audio files, but it seems to be impossible with SOIL for image files.

Quote
I have another question:
- When using LoadFromPixelsPtr, do I have to keep my pointer and free it when the image isn't in use anymore? I would like to just send the pointer to sf::Image and let it take care of it, as I don't need the pointer for anything else (but better would be using the Load & SaveToMemory instead)

You can do whatever you want with the pointer, sf::Image copies everything that it needs and does not rely on pointers to external data.
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
sf::Image::SaveToMemory
« Reply #2 on: February 09, 2010, 02:06:31 pm »
I see. I needed it just for png format, since it's better for RGBA.
I'll keep saving and loading width, height and pixels pointer then. Using zlib compression over my files should reduce size significantly.

Quote from: "Laurent"

You can do whatever you want with the pointer, sf::Image copies everything that it needs and does not rely on pointers to external data.

Ah, ok thanks. I just free it after loading sf::Image :P
Pluma - Plug-in Management Framework