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

Author Topic: Loading an image from a .rc file  (Read 14744 times)

0 Members and 3 Guests are viewing this topic.

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Loading an image from a .rc file
« Reply #15 on: January 30, 2011, 04:54:18 pm »
Quote from: "Laurent"
LoadFromMemory takes a pointer to a bitmap file in memory (the same thing that you would have on your hard drive).


This is what I was thinking.  If that's the case, then the size of the resource will almost certainly not be equal to width*height*4

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Loading an image from a .rc file
« Reply #16 on: January 30, 2011, 05:02:17 pm »
LoadFromMemory wants the bytes of a normal BMP file, not a Windows DIB.

Quote
This is what I was thinking. If that's the case, then the size of the resource will almost certainly not be equal to width*height*4

Sorry, was thinking of LoadFromPixels.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Loading an image from a .rc file
« Reply #17 on: January 30, 2011, 05:54:36 pm »
Quote
LoadFromMemory wants the bytes of a normal BMP file, not a Windows DIB.

I'm just wondering, isn't DIB the same thing that is inside bitmap files?
Laurent Gomila - SFML developer

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Loading an image from a .rc file
« Reply #18 on: January 30, 2011, 06:00:24 pm »
Quote from: "Laurent"
Quote
LoadFromMemory wants the bytes of a normal BMP file, not a Windows DIB.

I'm just wondering, isn't DIB the same thing that is inside bitmap files?

As far as I know they use a modified header.

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Loading an image from a .rc file
« Reply #19 on: January 30, 2011, 07:27:20 pm »
I wasn't aware there was any difference, either

Prominence256

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://GameMakerStation.110mb.com/
Loading an image from a .rc file
« Reply #20 on: January 30, 2011, 07:35:26 pm »
Okay, I replaced
Code: [Select]
zeroimg.LoadFromMemory((const char*) lpvoid, SizeofResource(GetModuleHandle(NULL), hresource));with
Code: [Select]
zeroimg.LoadFromPixels(128, 128, (const Uint8*) lpvoid);
Now it shows a messed up version of the picture:

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Loading an image from a .rc file
« Reply #21 on: January 30, 2011, 07:49:18 pm »
So the image is flipped? That's not messed up, your just a step away from having it working :)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Prominence256

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://GameMakerStation.110mb.com/
Loading an image from a .rc file
« Reply #22 on: January 30, 2011, 08:39:13 pm »
It's not that it's flipped it's that it attached part of the right side to the left edge of the image. This, is what's getting drawn to the screen:

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Loading an image from a .rc file
« Reply #23 on: January 30, 2011, 09:06:38 pm »
Seems to me you have a 10-40 byte (depending on bitdepth) header you're not removing before sending it to LoadFromPixels. It's not the stride or it would be diagonal.

Prominence256

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://GameMakerStation.110mb.com/
Loading an image from a .rc file
« Reply #24 on: January 30, 2011, 10:20:09 pm »
How do I get rid of the header?

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Loading an image from a .rc file
« Reply #25 on: January 30, 2011, 10:23:17 pm »
Well, you could try it the hackish way and do:

zeroimg.LoadFromPixels(128, 128, ((const Uint8*) lpvoid) + 10); // or rather +30/+40 depending on bitdepth.

Prominence256

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://GameMakerStation.110mb.com/
Loading an image from a .rc file
« Reply #26 on: January 31, 2011, 01:54:34 am »
I'm using 40 as the color depth, and that problems fixed. But now it's still upside down:

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Loading an image from a .rc file
« Reply #27 on: January 31, 2011, 10:18:51 am »
Yes, that is normal for DIBs.

From Wikipedia:
Quote
The Pixel Array is a block of 32-bit DWORDs, that describes the image pixel by pixel. Normally pixels are stored "upside-down" with respect to normal image raster scan order, starting in the lower left corner, going from left to right, and then row by row from the bottom to the top of the image.[1]
Uncompressed Windows bitmaps also can be stored from the top to bottom, when the Image Height value is negative.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Loading an image from a .rc file
« Reply #28 on: January 31, 2011, 11:48:18 am »
You could before passing the pointer to the image create a temporary array where you copy each pixel but just make sure that you flip them. Then pass the array to the image and your done :)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Loading an image from a .rc file
« Reply #29 on: January 31, 2011, 04:40:12 pm »
Wait... why did you switch to LoadFromPixels?  Was LoadFromMemory not working?

Loading from pixels seems like a really bad idea here.  I mean you already have a header and everything -- why not just load the image normally?