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
| #include <stdio.h>
#include <string.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;
unsigned long r=0;
unsigned long g=0;
unsigned long b=0;
int jpegSubsamp;
int inColorspace;
unsigned char* compressedImage1 = NULL;
unsigned char* compressedImage2 = NULL;
unsigned char buffer1[width * height * COLOR_COMPONENTS+1];
unsigned char buffer2[width * height * COLOR_COMPONENTS+1];
FILE* fichier_jpeg1 = NULL;
FILE* fichier_jpeg2 = NULL;
fichier_jpeg1 = fopen("/home/seb/c/file.jpeg", "r");//ouverture du fichier
fread(compressedImage1, 1, 720*560, fichier_jpeg1);//lecture du fichier
fclose(fichier_jpeg1);// fermeture du fichier
fichier_jpeg2 = fopen("/home/seb/c/file.jpeg", "r");//ouverture du fichier
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 += *bufPtr1-*bufPtr2;
bufPtr1++;
bufPtr2++;
g += *bufPtr1-*bufPtr2;
bufPtr1++;
bufPtr2++;
b += *bufPtr1-*bufPtr2;
bufPtr1++;
bufPtr2++;
//r += *bufPtr1++;
//g += *bufPtr1++;
//b += *bufPtr1++;
}
}
tjFree(compressedImage1);
tjFree(compressedImage2);
printf("r=%lu g=%lu b=%lu\n",r,g,b);
return 0;
} |
Partager