/** * 建立 src 图像的灰度版本 * * @param src 源图像 * @param gray 灰度 0 到 100, 0 为源图像, 100 为纯灰色图像 */ image_p create_gray_image(image_p src, int gray) { uint32 y,x; uint8 recover = 0; image_p pimg; uint16 *p16,*psrc16; uint32 *p32,*psrc32; if(gray<0 || gray>100) { nge_print("create_gray_image arg 'gray' must between 0 to 100!"); return NULL; } if(src->swizzle ==1){ unswizzle_swap(src); recover = 1; } pimg = image_create(src->w, src->h, src->dtype); for(y=0;y<src->h;y++) { if(src->dtype == DISPLAY_PIXEL_FORMAT_8888) { p32 = (uint32 *)pimg->data + y*src->texw; psrc32 = (uint32 *)src->data + y*src->texw; } else { p16 = (uint16 *)pimg->data + y*src->texw; psrc16 = (uint16 *)src->data + y*src->texw; } for(x=0;x<src->w;x++) { if(src->dtype == DISPLAY_PIXEL_FORMAT_8888) { *(p32 + x) = (uint32)get_gray_color(pimg->dtype, *(psrc32 + x), gray); } else { *(p16 + x) = (uint16)get_gray_color(pimg->dtype, *(psrc16 + x), gray); } } } if(recover) swizzle_swap(src); return pimg; }
/** * 建立 src 图像的灰度版本 * * @param src 源图像 * @param gray 灰度 0 到 100, 0 为源图像, 100 为纯灰色图像 */ image_p create_gray_image(image_p src, int gray) { uint32_t y,x; image_p pimg; uint16_t *p16 = NULL,*psrc16 = NULL; uint32_t *p32 = NULL,*psrc32 = NULL; if(gray<0 || gray>100) { nge_print("create_gray_image arg 'gray' must between 0 to 100!"); return NULL; } CHECK_AND_UNSWIZZLE(src); pimg = image_create(src->w, src->h, src->dtype); for(y=0;y<src->h;y++) { if(src->dtype == DISPLAY_PIXEL_FORMAT_8888) { p32 = (uint32_t *)pimg->data + y*src->texw; psrc32 = (uint32_t *)src->data + y*src->texw; } else { p16 = (uint16_t *)pimg->data + y*src->texw; psrc16 = (uint16_t *)src->data + y*src->texw; } for(x=0;x<src->w;x++) { if(src->dtype == DISPLAY_PIXEL_FORMAT_8888) { *(p32 + x) = (uint32_t)get_gray_color(pimg->dtype, *(psrc32 + x), gray); } else { *(p16 + x) = (uint16_t)get_gray_color(pimg->dtype, *(psrc16 + x), gray); } } } CHECK_AND_SWIZZLE(src); return pimg; }