bool BlenderSession::builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels) { int frame = builtin_image_frame(builtin_name); PointerRNA ptr; RNA_id_pointer_create((ID*)builtin_data, &ptr); BL::Image b_image(ptr); if(b_image) { int width = b_image.size()[0]; int height = b_image.size()[1]; int channels = b_image.channels(); unsigned char *image_pixels; image_pixels = image_get_pixels_for_frame(b_image, frame); if(image_pixels) { memcpy(pixels, image_pixels, width * height * channels * sizeof(unsigned char)); MEM_freeN(image_pixels); } else { if(channels == 1) { memset(pixels, 0, width * height * sizeof(unsigned char)); } else { unsigned char *cp = pixels; for(int i = 0; i < width * height; i++, cp += channels) { cp[0] = 255; cp[1] = 0; cp[2] = 255; if(channels == 4) cp[3] = 255; } } } /* premultiply, byte images are always straight for blender */ unsigned char *cp = pixels; for(int i = 0; i < width * height; i++, cp += channels) { cp[0] = (cp[0] * cp[3]) >> 8; cp[1] = (cp[1] * cp[3]) >> 8; cp[2] = (cp[2] * cp[3]) >> 8; } return true; } return false; }
bool BlenderSession::builtin_image_pixels(const string &builtin_name, unsigned char *pixels) { string name; int frame; builtin_name_split(builtin_name, name, frame); BL::Image b_image = b_data.images[name]; if(b_image) { int width = b_image.size()[0]; int height = b_image.size()[1]; int channels = b_image.channels(); unsigned char *image_pixels; image_pixels = image_get_pixels_for_frame(b_image, frame); if(image_pixels) { memcpy(pixels, image_pixels, width * height * channels * sizeof(unsigned char)); MEM_freeN(image_pixels); } else { if(channels == 1) { memset(pixels, 0, width * height * sizeof(unsigned char)); } else { unsigned char *cp = pixels; for(int i = 0; i < width * height; i++, cp += channels) { cp[0] = 255; cp[1] = 0; cp[2] = 255; if(channels == 4) cp[3] = 255; } } } return true; } return false; }