#include "FreeImage.h" typedef struct { int r, g, b; } pixel; pixel **read_img(char *name, int *width, int *height) { FIBITMAP *image; int i,j; RGBQUAD aPixel; pixel **data; if((image = FreeImage_Load(FIF_TIFF, name, 0)) == NULL) { perror("FreeImage_Load"); return NULL; } *width = FreeImage_GetWidth(image); *height = FreeImage_GetHeight(image); data = (pixel **)malloc((*height)*sizeof(pixel *)); for(i = 0 ; i < (*height) ; i++) { data[i] = (pixel *)malloc((*width)*sizeof(pixel)); for(j = 0 ; j < (*width) ; j++) { FreeImage_GetPixelColor(image, j, i, &aPixel); data[i][j].r = (aPixel.rgbRed); data[i][j].g = (aPixel.rgbGreen); data[i][j].b = (aPixel.rgbBlue); } } FreeImage_Unload(image); return data; } void write_img(char *name, pixel **data, int width, int height) { FIBITMAP *image; RGBQUAD aPixel; int i,j; image = FreeImage_Allocate(width, height, 24, 0, 0, 0); if(!image) { perror("FreeImage_Allocate"); return; } for(i = 0 ; i < height ; i++) { for(j = 0 ; j < width ; j++) { aPixel.rgbRed = data[i][j].r; aPixel.rgbGreen = data[i][j].g; aPixel.rgbBlue = data[i][j].b; FreeImage_SetPixelColor(image, j, i, &aPixel); } } if(!FreeImage_Save(FIF_TIFF, image, name, 0)) { perror("FreeImage_Save"); } FreeImage_Unload(image); } int main() { pixel **data; int w, h; data = read_img("spit06.tif", &w, &h); write_img("backup.tif", data, w, h); return 0; }