
This is my first post in any mailinglist ever so i hope i am doing this right. I successfully integrated the boost::gil module into my code to load some images and process their content so that I can display it as a texture in OpenGL. My problem right now is the massive performance issue in retrieving the color information from the loaded image. I am looping through every row and column and retrieve the red, green, blue and alpha color with the get_color method and push those values to a char array. So I was wondering what the best approach would be to get the color information from the gil image into OpenGL or at least a char array. Thanks in advance.

Hi there, depending on the memory layout of you could just cast the
first channel of your first pixel into a byte pointer. BTW, what do
you mean by color information?
Regards,
Christian
On Sat, Jan 9, 2010 at 9:15 PM,
This is my first post in any mailinglist ever so i hope i am doing this right.
I successfully integrated the boost::gil module into my code to load some images and process their content so that I can display it as a texture in OpenGL.
My problem right now is the massive performance issue in retrieving the color information from the loaded image.
I am looping through every row and column and retrieve the red, green, blue and alpha color with the get_color method and push those values to a char array.
So I was wondering what the best approach would be to get the color information from the gil image into OpenGL or at least a char array.
Thanks in advance.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thank you for your reply but I still do not understand how to cast the
channel to the byte pointer.
I will provide the snippet which is causing the performance issues.
data = (unsigned char*)malloc(src_view.width()*src_view.height()*4);
int i=0;
for (int y=0; y < src_view.height(); y++) {
for (int x=0; x < src_view.width(); x++) {
data[i++] = get_color(src_view(x,y), boost::gil::red_t());
data[i++] = get_color(src_view(x,y), boost::gil::green_t());
data[i++] = get_color(src_view(x,y), boost::gil::blue_t());
data[i++] = get_color(src_view(x,y), boost::gil::alpha_t());
}
}
Later on "data" is passed to the OpenGL function which renders the textures.
Unfortunately I find the gil doxygen documentation more confusing then
helping.
I hope it is clearer what I am trying to do with that image.
In the case you have more questions shoot ahead, I am very frustrated
because I am trying for days to solve that problem and most people seem to
have very little knowledge of gil.
Regards,
Viktor
-----Ursprüngliche Nachricht-----
Von: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Christian
Henning
Gesendet: Sonntag, 10. Januar 2010 19:36
An: boost-users@lists.boost.org
Betreff: Re: [Boost-users] gil and OpenGL
Hi there, depending on the memory layout of you could just cast the
first channel of your first pixel into a byte pointer. BTW, what do
you mean by color information?
Regards,
Christian
On Sat, Jan 9, 2010 at 9:15 PM,
This is my first post in any mailinglist ever so i hope i am doing this right.
I successfully integrated the boost::gil module into my code to load some images and process their content so that I can display it as a texture in OpenGL.
My problem right now is the massive performance issue in retrieving the color information from the loaded image.
I am looping through every row and column and retrieve the red, green, blue and alpha color with the get_color method and push those values to a char array.
So I was wondering what the best approach would be to get the color information from the gil image into OpenGL or at least a char array.
Thanks in advance.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

You could also simply create a view on your memory buffer (using boost::gil::interleaved_view) and then copy the pixels of your source view to this new view. This would give something like (untested, uncompiled, pseudocode) : data = (unsigned char*)malloc(src_view.width()*src_view.height()*4); dst_view = boost::gil::interleaved_view(src_view.width(), src_view.height(), data, src_view.width()*4); std::copy(src_view.begin(), src_view.end(), dst_view.begin()); and you're done...

Viktor, here is a small snippet:
rgba8_image_t img( 320, 240 );
rgba8_view_t v = view( img );
rgba8_pixel_t ppp = *v.begin();
unsigned char* data = &ppp[0];
Let me know if you have more questions.
Regards,
Christian
On Sun, Jan 10, 2010 at 2:06 PM,
Thank you for your reply but I still do not understand how to cast the channel to the byte pointer.
I will provide the snippet which is causing the performance issues.
data = (unsigned char*)malloc(src_view.width()*src_view.height()*4); int i=0; for (int y=0; y < src_view.height(); y++) { for (int x=0; x < src_view.width(); x++) { data[i++] = get_color(src_view(x,y), boost::gil::red_t()); data[i++] = get_color(src_view(x,y), boost::gil::green_t()); data[i++] = get_color(src_view(x,y), boost::gil::blue_t()); data[i++] = get_color(src_view(x,y), boost::gil::alpha_t()); } }
Later on "data" is passed to the OpenGL function which renders the textures.
Unfortunately I find the gil doxygen documentation more confusing then helping.
I hope it is clearer what I am trying to do with that image. In the case you have more questions shoot ahead, I am very frustrated because I am trying for days to solve that problem and most people seem to have very little knowledge of gil.
Regards, Viktor
-----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Christian Henning Gesendet: Sonntag, 10. Januar 2010 19:36 An: boost-users@lists.boost.org Betreff: Re: [Boost-users] gil and OpenGL
Hi there, depending on the memory layout of you could just cast the first channel of your first pixel into a byte pointer. BTW, what do you mean by color information?
Regards, Christian
On Sat, Jan 9, 2010 at 9:15 PM,
wrote: This is my first post in any mailinglist ever so i hope i am doing this right.
I successfully integrated the boost::gil module into my code to load some images and process their content so that I can display it as a texture in OpenGL.
My problem right now is the massive performance issue in retrieving the color information from the loaded image.
I am looping through every row and column and retrieve the red, green, blue and alpha color with the get_color method and push those values to a char array.
So I was wondering what the best approach would be to get the color information from the gil image into OpenGL or at least a char array.
Thanks in advance.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

mailinglist@squarepx.com wrote:
Thank you for your reply but I still do not understand how to cast the channel to the byte pointer.
I will provide the snippet which is causing the performance issues.
data = (unsigned char*)malloc(src_view.width()*src_view.height()*4); int i=0; for (int y=0; y < src_view.height(); y++) { for (int x=0; x < src_view.width(); x++) { data[i++] = get_color(src_view(x,y), boost::gil::red_t()); data[i++] = get_color(src_view(x,y), boost::gil::green_t()); data[i++] = get_color(src_view(x,y), boost::gil::blue_t()); data[i++] = get_color(src_view(x,y), boost::gil::alpha_t()); } }
Later on "data" is passed to the OpenGL function which renders the textures.
Unfortunately I find the gil doxygen documentation more confusing then helping.
I hope it is clearer what I am trying to do with that image. In the case you have more questions shoot ahead, I am very frustrated because I am trying for days to solve that problem and most people seem to have very little knowledge of gil.
Regards, Viktor
-----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Christian Henning Gesendet: Sonntag, 10. Januar 2010 19:36 An: boost-users@lists.boost.org Betreff: Re: [Boost-users] gil and OpenGL
Hi there, depending on the memory layout of you could just cast the first channel of your first pixel into a byte pointer. BTW, what do you mean by color information?
Regards, Christian
On Sat, Jan 9, 2010 at 9:15 PM,
wrote: This is my first post in any mailinglist ever so i hope i am doing this right.
I successfully integrated the boost::gil module into my code to load some images and process their content so that I can display it as a texture in OpenGL.
My problem right now is the massive performance issue in retrieving the color information from the loaded image.
I am looping through every row and column and retrieve the red, green, blue and alpha color with the get_color method and push those values to a char array.
So I was wondering what the best approach would be to get the color information from the gil image into OpenGL or at least a char array.
Thanks in advance.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I do this to load GIL images as OpenGL textures and it works fine for me:
reinterpret_cast

Kenny Riddile wrote:
I do this to load GIL images as OpenGL textures and it works fine for me:
reinterpret_cast
( interleaved_view_get_raw_data(imageView) )
Also, I've noticed that OpenGL interprets the image data upside down, so I flip it prior to calling glTexImage2D using flipped_up_down_view. Flipping the image data seems to be common practice when loading OpenGL textures based on what I've read online.

Kenny Riddile wrote:
Kenny Riddile wrote:
I do this to load GIL images as OpenGL textures and it works fine for me:
reinterpret_cast
( interleaved_view_get_raw_data(imageView) ) Also, I've noticed that OpenGL interprets the image data upside down, so I flip it prior to calling glTexImage2D using flipped_up_down_view. Flipping the image data seems to be common practice when loading OpenGL textures based on what I've read online. You can flip the image, but it is more efficient to flip the texture coordinates on Y (or T) axis. If you have a lot of texture coordinates, you can set a texture matrix (glMatrixMode(GL_TEXTURE)) that flips them on hardware.

Ruben Lopez wrote:
Kenny Riddile wrote:
Kenny Riddile wrote:
I do this to load GIL images as OpenGL textures and it works fine for me:
reinterpret_cast
( interleaved_view_get_raw_data(imageView) ) Also, I've noticed that OpenGL interprets the image data upside down, so I flip it prior to calling glTexImage2D using flipped_up_down_view. Flipping the image data seems to be common practice when loading OpenGL textures based on what I've read online. You can flip the image, but it is more efficient to flip the texture coordinates on Y (or T) axis. If you have a lot of texture coordinates, you can set a texture matrix (glMatrixMode(GL_TEXTURE)) that flips them on hardware.
Thanks! I was actually looking for a convenient way to flip all texture coordinates...I'm still somewhat unfamiliar with OpenGL. I see GLSL also gives me access to the texture matrices for each texture unit in the vertex shader, which is exactly what I need :)
participants (5)
-
Christian Henning
-
Kenny Riddile
-
mailinglist@squarepx.com
-
Nicolas Lelong
-
Ruben Lopez