void* imImageGetOpenGLData(const imImage* image, int *format) { if (!imImageIsBitmap(image)) return NULL; int transp_count; imbyte* transp_index = (imbyte*)imImageGetAttribute(image, "TransparencyIndex", NULL, NULL); imbyte* transp_map = (imbyte*)imImageGetAttribute(image, "TransparencyMap", NULL, &transp_count); imbyte* transp_color = (imbyte*)imImageGetAttribute(image, "TransparencyColor", NULL, NULL); int glformat; switch(image->color_space) { case IM_MAP: if (image->has_alpha || transp_map || transp_index) glformat = GL_RGBA; else glformat = GL_RGB; break; case IM_RGB: if (image->has_alpha || transp_color) glformat = GL_RGBA; else glformat = GL_RGB; break; case IM_BINARY: default: /* IM_GRAY */ if (image->has_alpha || transp_map || transp_index) glformat = GL_LUMINANCE_ALPHA; else glformat = GL_LUMINANCE; break; } int gldepth; switch (glformat) { case GL_RGB: gldepth = 3; break; case GL_RGBA: gldepth = 4; break; case GL_LUMINANCE_ALPHA: gldepth = 2; break; default: /* GL_LUMINANCE */ gldepth = 1; break; } int size = image->count*gldepth; imImageSetAttribute(image, "GLDATA", IM_BYTE, size, NULL); imbyte* gldata = (imbyte*)imImageGetAttribute(image, "GLDATA", NULL, NULL); int depth = image->depth; if (image->has_alpha) depth++; /* copy data, including alpha */ if (image->color_space != IM_MAP) { imConvertPacking(image->data[0], gldata, image->width, image->height, depth, gldepth, IM_BYTE, 0); if (image->color_space == IM_BINARY) iImageMakeGray(gldata, gldepth, image->count); } else { /* copy map data */ memcpy(gldata, image->data[0], image->size); /* size does not include alpha */ /* expand MAP to RGB or RGBA */ imConvertMapToRGB(gldata, image->count, gldepth, 1, image->palette, image->palette_count); if (image->has_alpha) iImageGLCopyMapAlpha((imbyte*)image->data[1], gldata, gldepth, image->count); /* copy the alpha plane */ } /* set alpha based on attributes */ if (!image->has_alpha) { if (image->color_space == IM_RGB) { if (transp_color) iImageGLSetTranspColor(gldata, image->count, *(transp_color+0), *(transp_color+1), *(transp_color+2)); } else { if (transp_map) iImageGLSetTranspMap((imbyte*)image->data[0], gldata, image->count, transp_map, transp_count); else if (transp_index) iImageGLSetTranspIndex((imbyte*)image->data[0], gldata, gldepth, image->count, *transp_index); } } if (format) *format = glformat; return gldata; }
int imConvertToBitmap(const imImage* src_image, imImage* dst_image, int cpx2real, float gamma, int absolute, int cast_mode) #endif { assert(src_image); assert(dst_image); if (!imImageMatchSize(src_image, dst_image) || !imImageIsBitmap(dst_image)) return IM_ERR_DATA; #ifdef IM_PROCESS int counter = imProcessCounterBegin("Building Bitmap"); #else int counter = imCounterBegin("Building Bitmap"); #endif int ret; if (src_image->data_type == IM_BYTE) { // NO data type conversion, only color mode conversion #ifdef IM_PROCESS ret = imProcessConvertColorSpace(src_image, dst_image); #else ret = imConvertColorSpace(src_image, dst_image); #endif } else { if (src_image->color_space == IM_RGB || src_image->color_space == IM_GRAY) { // data type conversion, but NO color mode conversion #ifdef IM_PROCESS ret = imProcessConvertDataType(src_image, dst_image, cpx2real, gamma, absolute, cast_mode); #else ret = imConvertDataType(src_image, dst_image, cpx2real, gamma, absolute, cast_mode); #endif } else { // data type conversion AND color mode conversion imImage* temp_image = imImageCreate(src_image->width, src_image->height, dst_image->color_space, src_image->data_type); if (!temp_image) ret = IM_ERR_MEM; else { // first convert color_mode in the bigger precision #ifdef IM_PROCESS ret = imProcessConvertColorSpace(src_image, temp_image); #else ret = imConvertColorSpace(src_image, temp_image); #endif if (ret == IM_ERR_NONE) { // second just convert data type #ifdef IM_PROCESS ret = imProcessConvertDataType(temp_image, dst_image, cpx2real, gamma, absolute, cast_mode); #else ret = imConvertDataType(temp_image, dst_image, cpx2real, gamma, absolute, cast_mode); #endif } imImageDestroy(temp_image); } } } #ifdef IM_PROCESS imProcessCounterEnd(counter); #else imCounterEnd(counter); #endif return ret; }
/*****************************************************************************\ image:isBitmap() \*****************************************************************************/ static int imluaImageIsBitmap (lua_State *L) { lua_pushboolean(L, imImageIsBitmap(imlua_checkimage(L, 1))); return 1; }