diff --git a/TPs/TP3/CODE/MODIF_IMG/FreeImage/FreeImage3180.pdf b/TPs/TP3/CODE/MODIF_IMG/FreeImage/FreeImage3180.pdf new file mode 100755 index 0000000000000000000000000000000000000000..205e4b55edf156e35d119fbabc7269261383e8ed Binary files /dev/null and b/TPs/TP3/CODE/MODIF_IMG/FreeImage/FreeImage3180.pdf differ diff --git a/TPs/TP3/CODE/MODIF_IMG/FreeImage/FreeImage3180.tar.gz b/TPs/TP3/CODE/MODIF_IMG/FreeImage/FreeImage3180.tar.gz new file mode 100755 index 0000000000000000000000000000000000000000..3437bf30b1edd936c0a411523d52feeeb0337154 Binary files /dev/null and b/TPs/TP3/CODE/MODIF_IMG/FreeImage/FreeImage3180.tar.gz differ diff --git a/TPs/TP3/CODE/MODIF_IMG/Makefile b/TPs/TP3/CODE/MODIF_IMG/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..9a17f7a0528dcd6f9fe07d3e802d28f11bc3787a --- /dev/null +++ b/TPs/TP3/CODE/MODIF_IMG/Makefile @@ -0,0 +1,8 @@ + +default: all + +all: + g++ -I${HOME}/softs/FreeImg/include modif_img.cpp -L${HOME}/softs/FreeImg/lib/ -lfreeimage -o modif_img.exe + +clean: + rm -f *.o modif_img.exe diff --git a/TPs/TP3/CODE/MODIF_IMG/img.jpg b/TPs/TP3/CODE/MODIF_IMG/img.jpg new file mode 100755 index 0000000000000000000000000000000000000000..85d1ab61fe424c65095ed2beaac2795537d9d710 Binary files /dev/null and b/TPs/TP3/CODE/MODIF_IMG/img.jpg differ diff --git a/TPs/TP3/CODE/MODIF_IMG/install.sh b/TPs/TP3/CODE/MODIF_IMG/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..8ef2ff3d93460841ed8d924433cf9076f43ae07e --- /dev/null +++ b/TPs/TP3/CODE/MODIF_IMG/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd FreeImage +tar xzvf FreeImage3180.tar.gz +cd FreeImage +make +make install +export LD_LIBRARY_PATH=${HOME}/softs/FreeImage/lib:$LD_LIBRARY_PATH diff --git a/TPs/TP3/CODE/MODIF_IMG/modif_img.cpp b/TPs/TP3/CODE/MODIF_IMG/modif_img.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5d254cdade8392568b7bd9faa91a84ebd20ca52f --- /dev/null +++ b/TPs/TP3/CODE/MODIF_IMG/modif_img.cpp @@ -0,0 +1,90 @@ +#include <iostream> +#include <string.h> +#include "FreeImage.h" + +using namespace std; + +int main (int argc , char** argv) +{ + FreeImage_Initialise(); + const char *PathName = "img.jpg"; + const char *PathDest = "new_img.png"; + // load and decode a regular file + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(PathName); + + FIBITMAP* bitmap = FreeImage_Load(FIF_JPEG, PathName, 0); + + if(! bitmap ) + exit( 1 ); //WTF?! We can't even allocate images ? Die ! + + unsigned width = FreeImage_GetWidth(bitmap); + unsigned height = FreeImage_GetHeight(bitmap); + unsigned pitch = FreeImage_GetPitch(bitmap); + + fprintf(stderr, "Processing Image of size %d x %d\n", width, height); + + unsigned int *img = (unsigned int*) malloc(sizeof(unsigned int) * 3 * width * height); + unsigned int *d_img = (unsigned int*) malloc(sizeof(unsigned int) * 3 * width * height); + + BYTE *bits = (BYTE*)FreeImage_GetBits(bitmap); + for ( int y =0; y<height; y++) + { + BYTE *pixel = (BYTE*)bits; + for ( int x =0; x<width; x++) + { + int idx = ((y * width) + x) * 3; + img[idx + 0] = pixel[FI_RGBA_RED]; + img[idx + 1] = pixel[FI_RGBA_GREEN]; + img[idx + 2] = pixel[FI_RGBA_BLUE]; + pixel += 3; + } + // next line + bits += pitch; + } + + memcpy(d_img, img, 3 * width * height * sizeof(unsigned int)); + + // Kernel + for ( int y =0; y<height; y++) + { + for ( int x =0; x<width; x++) + { + int ida = ((y * width) + x) * 3; + d_img[ida + 0] = d_img[ida + 0]; + d_img[ida + 1] = d_img[ida + 1]; + d_img[ida + 2] = d_img[ida + 2]; + } + } + + // Copy back + memcpy(img, d_img, 3 * width * height * sizeof(unsigned int)); + + bits = (BYTE*)FreeImage_GetBits(bitmap); + for ( int y =0; y<height; y++) + { + BYTE *pixel = (BYTE*)bits; + for ( int x =0; x<width; x++) + { + RGBQUAD newcolor; + + int idx = ((y * width) + x) * 3; + newcolor.rgbRed = img[idx + 0]; + newcolor.rgbGreen = img[idx + 1]; + newcolor.rgbBlue = img[idx + 2]; + + if(!FreeImage_SetPixelColor(bitmap, x, y, &newcolor)) + { fprintf(stderr, "(%d, %d) Fail...\n", x, y); } + + pixel+=3; + } + // next line + bits += pitch; + } + + if( FreeImage_Save (FIF_PNG, bitmap , PathDest , 0 )) + cout << "Image successfully saved ! " << endl ; + FreeImage_DeInitialise(); //Cleanup ! + + free(img); + free(d_img); +}