Re: [E-devel] Best way to create an OpenGL texture from an imlib2 image?
Carsten Haitzler (The Rasterman) a écrit : On Tue, 19 Apr 2005 22:23:29 -0400 Jay Summet [EMAIL PROTECTED] babbled: imlib2 appears to store image data internally in ARGB format, which you can get a pointer to with a call such as: unsigned int *pImageData = imlib_image_get_data(); take a look at: evas/src/lib/engines/gl_common/evas_gl_texture.c evas uses the same pix format as imlib2 - and that converts the image to a texture :) (handles nv_rect extensions, power of 2 padding etc.) ie without alpha: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels); with alpha: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels); check that code to see it handling power of 2 problems properly (it doesnt handle texture meshes when max text size image size though). it requires no copy/transform before copying the pixels to the texture. OpenGL glTexImage2D() function wants data in RGBA format. You can do a manual conversion of each and every pixel with a double for loop enclosing the following: ~GLdata[offset] = (pImageData[img_offset] 16) 0xff; ~GLdata[offset + 1] = (pImageData[img_offset] 8) 0xff; ~GLdata[offset + 2] = pImageData[img_offset] 0xff; ~GLdata[offset + 3] = (pImageData[img_offset] 24) 0xff; But this is slow. Is there a better (faster) way to convert an imlib2 image to an OpenGL texture? Thanks, Jay I'm basically looking to load lots of images in various formats and render them as OpenGL textures, I don't think I'll need all of imlib2's image compositing/blending functionality, so perhaps another library would be a better choice? Suggestions? take a look at my tlib.c file best regards Michel /* * $Id: eana_tlib.c,v 1.4 2005/01/29 14:29:30 michel Exp $ * * description: Textures images routines. * */ #include eana_tlib.h static const GLenum t_quality_tab[] = { GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR }; GLenum t_quality(e_quality_t quality) { ASSERTE(quality=0 quality=q_linear_mipmap_linear); return t_quality_tab[quality]; } s_image_t* t_image_load(const char *path, float gamma) { Imlib_Image imlib_image; Imlib_Load_Error imlib_error; s_image_t *image; size_t sz_transfert; DATA32 *transfert; imlib_image = imlib_load_image_with_error_return(path, imlib_error); if ((imlib_error != IMLIB_LOAD_ERROR_NONE) || !imlib_image) { TR(trError, Imlib2 Error: %d\n, imlib_error); return NULL; } image = xalloc(s_image_t); image-name = strdup(path); imlib_context_set_image(imlib_image); image-width = imlib_image_get_width(); image-height = imlib_image_get_height(); image-alpha = imlib_image_has_alpha(); //imlib_image_flip_vertical(); sz_transfert = image-width * image-height * 4; // Imlib2 gives always 4 bytes / pixel image-align = 4; image-pixels = calloc(1, sz_transfert); memset(image-pixels, 1, sz_transfert); transfert = imlib_image_get_data_for_reading_only(); memcpy(image-pixels, transfert, sz_transfert); t_image_gamma_adjust(image-align, image-width, image-height, image-pixels, gamma); imlib_free_image(); return image; } void t_image_gamma_adjust(int align, int width, int height, void *pixels, float gamma) { float scale, temp; float r, g, b; uchar_t *pix; uint_t i, npix; npix = width * height; pix = (uchar_t *) pixels; for (i = 0; i npix; i++, pix += align) { scale = 1.0f; temp = 0.0f; r = g = b = 0; r = (float) pix[0]; g = (float) pix[1]; b = (float) pix[2]; r = r * gamma / 255.0f; g = g * gamma / 255.0f; b = b * gamma / 255.0f; if (r 1.0f (temp = (1.0f/r)) scale) scale = temp; if (g 1.0f (temp = (1.0f/g)) scale) scale = temp; if (b 1.0f (temp = (1.0f/b)) scale) scale = temp; scale *= 255.0f; r *= scale; g *= scale; b *= scale; pix[0] = (uchar_t) r; pix[1] = (uchar_t) g; pix[2] = (uchar_t) b; } } bool_t t_image_write(s_image_t *image, const char *path) { Imlib_Image imlib_image; imlib_image = imlib_create_image_using_data(image-width, image-height, (DATA32 *) image-pixels); imlib_context_set_image(imlib_image); imlib_save_image(path); imlib_free_image(); return TRUE; } void t_image_destroy(s_image_t *image) { if (image-name) free(image-name); if (image-pixels) free(image-pixels); free(image); } int t_tex_create_mipmaps(int align, int width, int height, bool_t alpha, void *pixels, uint_t mipmaps, e_quality_t quality) { int tex; GLenum gluError; GLint internal_format; GLenum format; if (alpha) { internal_format = GL_RGBA; } else { internal_format = GL_RGB; } if (align == 3) {
[E-devel] Best way to create an OpenGL texture from an imlib2 image?
-BEGIN PGP SIGNED MESSAGE- imlib2 appears to store image data internally in ARGB format, which you can get a pointer to with a call such as: unsigned int *pImageData = imlib_image_get_data(); OpenGL glTexImage2D() function wants data in RGBA format. You can do a manual conversion of each and every pixel with a double for loop enclosing the following: ~GLdata[offset] = (pImageData[img_offset] 16) 0xff; ~GLdata[offset + 1] = (pImageData[img_offset] 8) 0xff; ~GLdata[offset + 2] = pImageData[img_offset] 0xff; ~GLdata[offset + 3] = (pImageData[img_offset] 24) 0xff; But this is slow. Is there a better (faster) way to convert an imlib2 image to an OpenGL texture? Thanks, Jay I'm basically looking to load lots of images in various formats and render them as OpenGL textures, I don't think I'll need all of imlib2's image compositing/blending functionality, so perhaps another library would be a better choice? Suggestions? -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iQCVAwUBQmW9IbWkkhmZq4xxAQG/gwP8Cmcz1WmyVuk/qe7OhuPv6yvXFIlrXL4I 0TMKN3mSvbgQSNC4jYqChlYs6onB01QUjfSYkmxu58M8vw4Ux7fWsaAMcCDeNILm lubaj3qtTg/PLuiV8dONqgNA6O0yIefZOjktLz4Uc9fzUF6atng+Drq7PTBzHIhT JU/zCqLLIpQ= =iqD6 -END PGP SIGNATURE- --- This SF.Net email is sponsored by: New Crystal Reports XI. Version 11 adds new functionality designed to reduce time involved in creating, integrating, and deploying reporting solutions. Free runtime info, new features, or free trial, at: http://www.businessobjects.com/devxi/728 ___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] Best way to create an OpenGL texture from an imlib2 image?
Have you tried changing your texture data format to use GL_BGRA and/or GL_UNSIGNED_INT_8_8_8_8_REV? Between them you may be able to set the texture data without the copy or byte swapping. On 4/19/05, Jay Summet [EMAIL PROTECTED] wrote: -BEGIN PGP SIGNED MESSAGE- imlib2 appears to store image data internally in ARGB format, which you can get a pointer to with a call such as: unsigned int *pImageData = imlib_image_get_data(); OpenGL glTexImage2D() function wants data in RGBA format. You can do a manual conversion of each and every pixel with a double for loop enclosing the following: ~GLdata[offset] = (pImageData[img_offset] 16) 0xff; ~GLdata[offset + 1] = (pImageData[img_offset] 8) 0xff; ~GLdata[offset + 2] = pImageData[img_offset] 0xff; ~GLdata[offset + 3] = (pImageData[img_offset] 24) 0xff; But this is slow. Is there a better (faster) way to convert an imlib2 image to an OpenGL texture? Thanks, Jay I'm basically looking to load lots of images in various formats and render them as OpenGL textures, I don't think I'll need all of imlib2's image compositing/blending functionality, so perhaps another library would be a better choice? Suggestions? -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iQCVAwUBQmW9IbWkkhmZq4xxAQG/gwP8Cmcz1WmyVuk/qe7OhuPv6yvXFIlrXL4I 0TMKN3mSvbgQSNC4jYqChlYs6onB01QUjfSYkmxu58M8vw4Ux7fWsaAMcCDeNILm lubaj3qtTg/PLuiV8dONqgNA6O0yIefZOjktLz4Uc9fzUF6atng+Drq7PTBzHIhT JU/zCqLLIpQ= =iqD6 -END PGP SIGNATURE- --- This SF.Net email is sponsored by: New Crystal Reports XI. Version 11 adds new functionality designed to reduce time involved in creating, integrating, and deploying reporting solutions. Free runtime info, new features, or free trial, at: http://www.businessobjects.com/devxi/728 ___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel --- This SF.Net email is sponsored by: New Crystal Reports XI. Version 11 adds new functionality designed to reduce time involved in creating, integrating, and deploying reporting solutions. Free runtime info, new features, or free trial, at: http://www.businessobjects.com/devxi/728 ___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] Best way to create an OpenGL texture from an imlib2 image?
On Tue, 19 Apr 2005 22:23:29 -0400 Jay Summet [EMAIL PROTECTED] babbled: (B (B -BEGIN PGP SIGNED MESSAGE- (B (B imlib2 appears to store image data internally in ARGB format, which you can (B get (B a pointer to with a call such as: (B unsigned int *pImageData = imlib_image_get_data(); (B (Btake a look at: (Bevas/src/lib/engines/gl_common/evas_gl_texture.c (B (Bevas uses the same pix format as imlib2 - and that converts the image to a (Btexture :) (handles nv_rect extensions, power of 2 padding etc.) (B (Bie without alpha: (BglTexImage2D(GL_TEXTURE_2D, 0, (B GL_RGB8, w, h, 0, (B GL_BGRA, GL_UNSIGNED_BYTE, pixels); (B (Bwith alpha: (BglTexImage2D(GL_TEXTURE_2D, 0, (B GL_RGBA8, w, h, 0, (B GL_BGRA, GL_UNSIGNED_BYTE, pixels); (B (Bcheck that code to see it handling power of 2 problems "properly" (it doesnt (Bhandle texture meshes when max text size image size though). it requires no (Bcopy/transform before copying the pixels to the texture. (B (B OpenGL glTexImage2D() function wants data in RGBA format. (B (B You can do a manual conversion of each and every pixel with a double for loop (B enclosing the following: (B (B ~GLdata[offset] = (pImageData[img_offset] 16) 0xff; (B ~GLdata[offset + 1] = (pImageData[img_offset] 8) 0xff; (B ~GLdata[offset + 2] = pImageData[img_offset] 0xff; (B ~GLdata[offset + 3] = (pImageData[img_offset] 24) 0xff; (B (B But this is slow. (B (B Is there a better (faster) way to convert an imlib2 image to an OpenGL (B texture? (B (B Thanks, (B Jay (B (B I'm basically looking to load lots of images in various formats and render (B them (B as OpenGL textures, I don't think I'll need all of imlib2's image (B compositing/blending functionality, so perhaps another library would be a (B better (B choice? Suggestions? (B -BEGIN PGP SIGNATURE- (B Version: GnuPG v1.2.4 (GNU/Linux) (B Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org (B (B iQCVAwUBQmW9IbWkkhmZq4xxAQG/gwP8Cmcz1WmyVuk/qe7OhuPv6yvXFIlrXL4I (B 0TMKN3mSvbgQSNC4jYqChlYs6onB01QUjfSYkmxu58M8vw4Ux7fWsaAMcCDeNILm (B lubaj3qtTg/PLuiV8dONqgNA6O0yIefZOjktLz4Uc9fzUF6atng+Drq7PTBzHIhT (B JU/zCqLLIpQ= (B =iqD6 (B -END PGP SIGNATURE- (B (B (B --- (B This SF.Net email is sponsored by: New Crystal Reports XI. (B Version 11 adds new functionality designed to reduce time involved in (B creating, integrating, and deploying reporting solutions. Free runtime info, (B new features, or free trial, at: http://www.businessobjects.com/devxi/728 (B ___ (B enlightenment-devel mailing list (B enlightenment-devel@lists.sourceforge.net (B https://lists.sourceforge.net/lists/listinfo/enlightenment-devel (B (B (B (B-- (B- Codito, ergo sum - "I code, therefore I am" -- (BThe Rasterman (Carsten Haitzler)[EMAIL PROTECTED] $BMg9%B?(B [EMAIL PROTECTED] (BTokyo, Japan ($BEl5~(B $BF|K\(B) (B (B (B--- (BThis SF.Net email is sponsored by: New Crystal Reports XI. (BVersion 11 adds new functionality designed to reduce time involved in (Bcreating, integrating, and deploying reporting solutions. Free runtime info, (Bnew features, or free trial, at: http://www.businessobjects.com/devxi/728 (B___ (Benlightenment-devel mailing list (Benlightenment-devel@lists.sourceforge.net (Bhttps://lists.sourceforge.net/lists/listinfo/enlightenment-devel