]> bicyclesonthemoon.info Git - ott/enhance/blob - compare.c
reveal online
[ott/enhance] / compare.c
1 // compare.c
2 // The tool to compare if two images are identical or not.
3 // 21.09.2015
4 // 
5 // Copyright (C) 2015  Balthasar SzczepaƄski
6 // 
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
11 // 
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU Affero General Public License for more details.
16 // 
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 // 
20
21 // Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)
22 // on Pentium III libdevil must be recompiled with
23 // --disable-ssl2 --disable-ssl3
24 // (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include "IL/il.h"
29
30 #define SAME      0
31 #define DIFF_PIX  1
32 #define DIFF_SIZE 2
33 #define FAIL      3
34
35 int mustard(const char *t,int m,int e);
36 int main(int argc, char *argv[]);
37
38 ILuint inpix1, inpix2;
39 unsigned char q =0;
40
41 int main(int argc, char *argv[])
42 {
43         
44         ILubyte *data1, *data2;
45         
46         ILuint x1, x2, y1, y2;
47         unsigned long i,s;
48         
49         if (argc<3)
50                 return mustard("compare inpix1 inpix2 ",0,FAIL);
51         if(argc>3)
52                 q=1;
53         
54         ilInit();
55                 
56         ilEnable(IL_ORIGIN_SET);
57         ilEnable(IL_FILE_OVERWRITE);
58         
59         ilGenImages(1,&inpix1);
60         ilGenImages(1,&inpix2);
61         
62         ilBindImage(inpix1);
63         if(!ilLoadImage(argv[1]))
64                 return mustard("inpix1 load fail.",1,FAIL);
65         if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))
66                 return mustard("inpix1 convert fail.",1,FAIL);
67         
68         x1=ilGetInteger(IL_IMAGE_WIDTH);
69         y1=ilGetInteger(IL_IMAGE_HEIGHT);
70         
71         data1=ilGetData();
72         ilBindImage(inpix2);
73         if(!ilLoadImage(argv[2]))
74                 return mustard("inpix2 load fail.",1,FAIL);
75         if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))
76                 return mustard("inpix2 convert fail.",1,FAIL);
77         
78         x2=ilGetInteger(IL_IMAGE_WIDTH);
79         if(x1!=x2)
80                 return mustard("different size.",1,DIFF_SIZE);
81         y2=ilGetInteger(IL_IMAGE_HEIGHT);
82         if(y1!=y2)
83                 return mustard("different size.",1,DIFF_SIZE);
84         
85         data2=ilGetData();
86         
87         s=3*x1*y1;
88         for(i=0;i<s;++i)
89         {
90                 if(data1[i]!=data2[i])
91                         return mustard("different pixels.",1,DIFF_PIX);
92         }
93         return mustard("identical.",1,SAME);
94 }
95
96 int mustard(const char *t, int m,int e)
97 {
98         if(!q)puts(t);
99         switch (m)
100         {
101         case 1:
102                 ilDeleteImages(1,&inpix1);
103                 ilDeleteImages(1,&inpix2);
104   case 0:
105   default:
106                 return e;
107         }
108 }