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

Author Topic: Containers for sf::Uint8???  (Read 8555 times)

0 Members and 1 Guest are viewing this topic.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Containers for sf::Uint8???
« on: April 22, 2010, 03:04:38 am »
How do I store sf::Uint8 if arrays of type sf::Uint8 are unsigned chars?

I'm trying convert my sf::Volor arrays and the only thing I can think of is filling them with uint8 data and making the logic really long with 0,1,2,3 checks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Containers for sf::Uint8???
« Reply #1 on: April 22, 2010, 09:48:11 am »
Sorry, I don't understand what you want to do. Maybe you can show some code?
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Containers for sf::Uint8???
« Reply #2 on: April 22, 2010, 11:19:52 am »
Code: [Select]

sf::Uint8 *color[3];

*color[0]=0;
*color[1]=0;
*color[2]=0;
*color[3]=0;

 sf::Uint8 *container[1023];

*container[0]=*color; //cannot convert sf::Uint8* to unsigned char

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Containers for sf::Uint8???
« Reply #3 on: April 22, 2010, 12:01:41 pm »
Why do you have two levels of indirection (ie. arrays of pointers to sf::Uint8)?

To manipulate an array of pixels you just need to have an array of sf::Uint8s, no pointers.
Code: [Select]
sf::Uint8 pixels[WIDTH * HEIGHT * 4];

// or

std::vector<sf::Uint8> pixels(width * height * 4);
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Containers for sf::Uint8???
« Reply #4 on: April 22, 2010, 09:47:42 pm »
I know about *4, but I wanted to just work with the sf::Uint8 similar to sf::Color because I had arrays of sf::Color in my previous code.

Right now I am doing like you suggested, but with pointers.

I'm using pointers because GetPixelsPtr returns a pointer.

Is there a better way?

Code: [Select]
sf::Uint8* Get_Pixel(sf::Uint8* img_ptr,int w,int h,int x,int y)
{
    int index=(((y*h)-y)+(x))*4;
    sf::Uint8 *ptr=new sf::Uint8[3];

    ptr[0]=img_ptr[index];
    ptr[1]=img_ptr[index+1];
    ptr[2]=img_ptr[index+2];
    ptr[3]=img_ptr[index+3];

    return ptr;
}

sf::Uint8 *img_ptr=const_cast<sf::Uint8*>(img.GetPixelsPtr());

sf::Uint8 *ptr3=Get_Pixel(img_ptr,w,h,80,0);