Results 1 to 7 of 7

Thread: get_pixel() problem please help me !

  1. #1
    Lesser Knight
    Join Date
    Jan 2011
    Posts
    30

    Default get_pixel() problem please help me !

    CL_DisplayWindow window("", 640, 480);
    CL_GraphicContext &gc = window.get_gc();

    CL_Colorf c = gc.get_pixeldata().get_pixel(0, 0); // c must be black but .... !!!

    why doesnt work ?!!!

  2. #2
    Lesser Knight
    Join Date
    Jan 2011
    Posts
    30

    Default

    i think it has a bug

  3. #3
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    The fault is in
    Code:
    CL_Colorf CL_PixelBuffer_Impl::get_pixel(int x, int y)
    {
    ...
    	float max_value = 255.0f;
    	color = CL_Colorf (((value & red_mask) >> red_bits) / max_value,
    		((value & green_mask) >> green_bits) / max_value,
    		((value & blue_mask) >> blue_bits) / max_value,
    		((value & alpha_mask) >> alpha_bits) / max_value);
    
    }
    "red_bits, green_bits, blue_bits and alpha_bits" are the number of bits in the color component. The function expected them to be the shift value.

    The "*_bits" should be changed to "*_shift" as follows:

    Code:
    const int red_shift = CL_PixelFormat::get_mask_shift(red_mask);
    const int green_shift = CL_PixelFormat::get_mask_shift(green_mask);
    const int blue_shift = CL_PixelFormat::get_mask_shift(blue_mask);
    const int alpha_shift = CL_PixelFormat::get_mask_shift(alpha_mask);
    However ... I do not believe anyone should be using this function. I am not sure why it is even there, unless you are writing a paint package and need to obtain a floating point red, green, blue and alpha at a specified point.

    Maybe it is better to create your own function, optimised to your specific need.

    For example, if the pixel buffer is RGBA:

    cl_uint8* buf = static_cast<cl_uint8*>(pixelbuffer.get_data());
    unsigned int value = buf[y * pixelbuffer.get_pitch() + x * 4];
    if (value == 0x00000000) { ... }

    Note: "CL_PixelBuffer pbuff = gc.get_pixeldata();" is a slow function using OpenGL, as it has to wait until the graphic card has finished processing, then download the GPU RAM to the CPU RAM.

  4. #4
    Lesser Knight
    Join Date
    Jan 2011
    Posts
    30

    Default

    tnx for guidance. but i want to get one pixel of graphicContext as a cl_colorf ... !!!
    how can i do this ?!

  5. #5

    Default what is the problem?

    we have to help them fix it.

  6. #6
    Lesser Knight
    Join Date
    Jan 2011
    Posts
    30

    Default

    CL_Colorf c = gc.get_pixeldata().get_pixel(0, 0);

    doesnt work !!! it has a bug !

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Yeah, it is a bug. (See my reply above).

    A patch to fix the bug is very welcome

Similar Threads

  1. CL_PixelBuffer::get_pixel()
    By Tuisto in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-20-2011, 04:51 PM
  2. CL_PixelBuffer::get_pixel() weird results...
    By Otto (Strange) Halmén in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 12-06-2006, 07:36 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •