SFML community forums

Help => Graphics => Topic started by: Psychohyena on May 04, 2011, 02:21:19 pm

Title: Complex Image Handling
Post by: Psychohyena on May 04, 2011, 02:21:19 pm
Hi Guys,

So cutting to the chase and avoiding beating around the bush here is what I want to do:

I have created a .dat file (binary) which contains the Uint8 information for a jpg. What I want to do is using iostream load that file into my application and then load it into an sf::Image.

So far I can restore the information into the application as Data (void*) where I get stuck is the converting this information back into Uint8. Does anyone have any ideas as to how I might do this?

Cheers,

Aaron
Title: Complex Image Handling
Post by: Laurent on May 04, 2011, 02:37:49 pm
What does "Uint8" refer to? Pixel components, or bytes of a JPG file? In other words, what kind of information is there in the data that you load from your file?
Title: Complex Image Handling
Post by: Psychohyena on May 04, 2011, 03:11:45 pm
Quote from: "Laurent"
What does "Uint8" refer to? Pixel components, or bytes of a JPG file? In other words, what kind of information is there in the data that you load from your file?


I'm using the GetPixelPtr function to fill the dat file through the ofstream and then using the ifstream to pull it back. It appears to be working up until I'm pulling the data back through the ifstream and then it crashes.

The code looks something like this:
Code: [Select]

sf::Uint8* myImageArray;
sf::Image test;
void myFunction()
{
  test.LoadFromFile("Image1.jpg");
 
  ofstream arrayData("C:\\array.dat", ios::out);
  ifstream inData("C:\\array.dat", ios::in);

  arrayData << test.GetPixelsPtr() << endl;
  arrayData.close();

  inData >> myImageArray;
  test.LoadFromPixels(600, 600, myImageArray);
};

It's changed slightly as I've been experimenting while waiting, so now what happens is the application crashes on the inData >> myImageArray. Rather than getting an error at compile about being unable to convert to sf::Uint8.

I feel what I have is possibly close to what I need.
Title: Complex Image Handling
Post by: Laurent on May 04, 2011, 03:35:06 pm
With this code, what you write/read is the value of a pointer. If you want to write the actual values that are pointed by this pointer, you have to write them one by one in the output stream.
And you also need to write the width and height to know how many elements are stored in the file.
Title: Complex Image Handling
Post by: Psychohyena on May 04, 2011, 10:36:44 pm
Quote from: "Laurent"
With this code, what you write/read is the value of a pointer. If you want to write the actual values that are pointed by this pointer, you have to write them one by one in the output stream.
And you also need to write the width and height to know how many elements are stored in the file.


Ahhh righto then. I'll get onto that, thanks for your help mate.