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

Author Topic: Textures are flipped when loaded  (Read 3763 times)

0 Members and 1 Guest are viewing this topic.

adborca

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Textures are flipped when loaded
« on: April 03, 2021, 04:16:55 pm »
Hi!

This topic is about a recent problem I'm having with texture loading, specifically with JPG's. I'll explain the problem keeping it as short as possible with both text and images.

One of the projects I'm currently working at requires me to load a series of image files, apply some processing to then export them.

The code I use to load the images is:
   
bool res = sfml_tex_->loadFromFile(path.c_str());
if(true == res) {
    sf::Vector2u _size = sfml_tex_->getSize();
    size_.x_ = _size.x; size_.y_ = _size.y;
    new_size_ = size_;
    extension_ = ext;
}
Where:
  • sfml_tex_ is a VALID pointer to sf::Texture
  • path is the path (in disk) to the texture to load

It is fair to assume that if loadFromFile returns false it is ALWAYS my fault. Assuming that the paths are everything correct, loadFromFile ALWAYS returns true, everything is fine up until this point.

The problem comes when trying to load a JPG file. The problem I'm encountering is that the loading function (loadFromFile) is flipping the width and the height of the image (I'm assuming it is because it makes the loading process faster).
In the following screenshot, it is clear that the size of the image is 1901x2852 pixels: https://i.imgur.com/EN8wBXp.png
But when debugging it, the values are stored the other way around (width is stored in height and viceversa): https://i.imgur.com/yemVuF2.png

The image IS EXACTLY THE SAME but with flipped width and height.
This presents a very important problem for me because I need to apply rotation to the images before exporting them (applying the rotation is not the problem).
I've also attached the images to this post.

Again the intention of this DOESN'T INCLUDE DRAWING THE TEXTURES, only loading them and applying processes to them, I'm using SFML because it provides the tools I need to draw them, but that is not the main point.

Please let me know if any extra information is needed, thanks in advance
« Last Edit: April 03, 2021, 05:07:01 pm by adborca »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Textures are flipped when loaded
« Reply #1 on: April 04, 2021, 09:30:14 am »
Maybe the JPEG image has an "orientation" EXIF field that the OS interprets when showing the properties? You can easily check that.

How is the image, once loaded into your program? Rotated 90°? What happens if you open the image into an image editor -- for example GIMP, which shows a popup when there's an EXIF rotation.
Laurent Gomila - SFML developer

adborca

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Textures are flipped when loaded
« Reply #2 on: April 04, 2021, 12:30:04 pm »
Hi Laurent, thanks for your response.
How is the image, once loaded into your program? Rotated 90°?
Yes, whenever I try to load a jpg image into my program it appears to be rotated by 90º to the left ONLY IF the EXIF field is activated within the image (realized and tested this after you mentioned it).

What happens if you open the image into an image editor -- for example GIMP, which shows a popup when there's an EXIF rotation.
GIMP shows that the image has this flag active. Do you know of a workaround for this case that doesn't include use of third-party libraries? If you know one but with third-party libraries, which one(s)? (the closest that seemed to solve this problem is ImageMagick)

Thanks in advance.








Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Textures are flipped when loaded
« Reply #3 on: April 04, 2021, 05:06:50 pm »
I'm afraid the only way to handle EXIF data correctly is to use a library. Maybe you can find one that just reads EXIF fields, instead of a full image processing library like ImageMagick.
Laurent Gomila - SFML developer

adborca

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Textures are flipped when loaded
« Reply #4 on: April 04, 2021, 06:56:40 pm »
Oh, okay, I'll have to research a bit more to see if that is possible, thanks!