1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "turbojpeg.h"
int main(int argc, char** argv)
{
const int COLOR_COMPONENTS = 3;
int width = 720;
int height = 560;
unsigned long size=width * height * COLOR_COMPONENTS;
double r=0.0000;
double g=0.0000;
double b=0.0000;
int jpegSubsamp;
int inColorspace;
unsigned char* compressedImage1=(unsigned char*)malloc(width * height * COLOR_COMPONENTS);
unsigned char* compressedImage2=(unsigned char*)malloc(width * height * COLOR_COMPONENTS);
unsigned char buffer1[width * height * COLOR_COMPONENTS];
unsigned char buffer2[width * height * COLOR_COMPONENTS];
FILE* fichier_jpeg1 = NULL;
FILE* fichier_jpeg2 = NULL;
fichier_jpeg1 = fopen("file1.jpeg", "rb");//ouverture du fichier
if(!fichier_jpeg1)
{
printf("erreur lecture JPG 1");
}
fread(compressedImage1, 1, 720*560, fichier_jpeg1);//lecture du fichier
fclose(fichier_jpeg1);// fermeture du fichier
fichier_jpeg2 = fopen("file2.jpeg", "rb");//ouverture du fichier
if(!fichier_jpeg1)
{
printf("erreur lecture JPG 2");
}
fread(compressedImage2, 1, 720*560, fichier_jpeg2);//lecture du fichier
fclose(fichier_jpeg2);// fermeture du fichier
const char *subsampName[TJ_NUMSAMP] = {
"4:4:4", "4:2:2", "4:2:0", "Grayscale", "4:4:0", "4:1:1"
};
const char *colorspaceName[TJ_NUMCS] = {
"RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
};
tjhandle jpegDecompressor = tjInitDecompress();
if (tjDecompressHeader3(jpegDecompressor, compressedImage1, size, &width, &height, &jpegSubsamp,&inColorspace)<0)
printf("lecture JPEG header image1\n");
printf("Image1: %d x %d pixels, %s subsampling, %s colorspace\n",width, height,subsampName[jpegSubsamp], colorspaceName[inColorspace]);
if (tjDecompressHeader3(jpegDecompressor, compressedImage2, size, &width, &height, &jpegSubsamp,&inColorspace)<0)
printf("lecture JPEG header image2\n");
printf("Image2: %d x %d pixels, %s subsampling, %s colorspace\n",width, height,subsampName[jpegSubsamp], colorspaceName[inColorspace]);
if(tjDecompress2(jpegDecompressor, compressedImage1, size, buffer1, width, 0, height, TJPF_RGB, TJFLAG_FASTDCT)<0)
printf("decompressing JPEG image1\n");
if(tjDecompress2(jpegDecompressor, compressedImage2, size, buffer2, width, 0, height, TJPF_RGB, TJFLAG_FASTDCT)<0)
printf("decompressing JPEG image2\n");
tjDestroy(jpegDecompressor);
unsigned char *bufPtr1 = buffer1;
unsigned char *bufPtr2 = buffer2;
for(int i=0; i<560; i++)
{
for(int j=0; j<720; j++)
{
//printf("%d %d \n",*bufPtr1,*bufPtr2);
r += abs((*bufPtr1-*bufPtr2)/255.0000);
bufPtr1++;
bufPtr2++;
g += abs((*bufPtr1-*bufPtr2)/255.0000);
bufPtr1++;
bufPtr2++;
b += abs((*bufPtr1-*bufPtr2)/255.0000);
bufPtr1++;
bufPtr2++;
}
}
tjFree(compressedImage1);
tjFree(compressedImage2);
printf("r=%f g=%f b=%f\n",r,g,b);
return 0;
} |
Partager