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

Author Topic: Pixel value from Image  (Read 2619 times)

0 Members and 1 Guest are viewing this topic.

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Pixel value from Image
« on: May 10, 2011, 02:55:10 am »
HI,
         I am trying to get the pixel value from  a .TGA file.
After reading the value it is stored in a buffer array. then the buffer array is manipulated to get the desired effect.

It is used for the 2d water ripple effect.

My problem is when I use
                      Image.GetPixel(i,j);
it returns value that is not numeric for eg: it sends value as r='L' g = '£'  b='A'

as a result i am not able to retrieve the numeric value of each pixel. So i cannot store proper value in BUFFER.

And i cannot use  the function     Image.SetPixel(i,j, sf::color( r,g,b))

since the value of (r,g,b)  cannot be properly set since its not retrieved properly from the GetPixel();

What should i do get the proper (r,g,b) value

All suggestions are welcome

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Pixel value from Image
« Reply #1 on: May 10, 2011, 07:40:11 am »
Quote
it returns value that is not numeric for eg: it sends value as r='L' g = '£' b='A'

They are numeric, you're just displaying them as characters instead of integers (because their type is sf::Uint8, which is a typedef for unsigned char).
Laurent Gomila - SFML developer

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Pixel value from Image
« Reply #2 on: May 10, 2011, 12:52:43 pm »
hi,
     I am trying this code for the pixel value but it crashes

Code: [Select]


#define RGB32(r,g,b) ((r << 16) + (g << 8) + b)

long* buffer;

buffer[0] = RGB32(0, 154, 191);



it compiles with no error but crashes at run time at the statement buffer[0] = RGB32(0, 154, 191);


A 'long' can store int value...so why is it crashing???

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Pixel value from Image
« Reply #3 on: May 10, 2011, 12:56:16 pm »
buffer is an unitialized pointer.

By the way, you should use functions instead of macros.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Pixel value from Image
« Reply #4 on: May 10, 2011, 12:59:18 pm »
Quote from: "Nexus"
buffer is an unitialized pointer.


if I initialize the the buffer in the beginning like

long* buffer = 0;


Still it crashes!!!!!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Pixel value from Image
« Reply #5 on: May 10, 2011, 01:04:43 pm »
You should really learn the C++ basics before you use pointers or arrays... Null pointers may not be dereferenced.

And don't use macros when you can use functions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Pixel value from Image
« Reply #6 on: May 10, 2011, 01:10:08 pm »
Quote from: "Nexus"
You should really learn the C++ basics before you use pointers or arrays... Null pointers may not be dereferenced.

And don't use macros when you can use functions.


ok..got it