1 |
#include <stdio.h>
|
2 |
#include <stdlib.h>
|
3 |
#include <math.h>
|
4 |
#include <string.h>
|
5 |
#include <sys/resource.h>
|
6 |
#include <wand/MagickWand.h>
|
7 |
|
8 |
|
9 |
#include "uthash.h"
|
10 |
|
11 |
/*
|
12 |
This returns 0 if the image is grey and 1 if the image is colored
|
13 |
This is useful for cleaning up the timeless information
|
14 |
*/
|
15 |
|
16 |
|
17 |
|
18 |
int test_if_image_bw(char *iname) {
|
19 |
|
20 |
MagickPixelPacket input_pixel;
|
21 |
MagickWand *input_wand = NULL;
|
22 |
PixelWand *c_wand = NULL;
|
23 |
PixelWand *c2_wand = NULL;
|
24 |
input_wand =NewMagickWand();
|
25 |
MagickReadImage(input_wand,iname);
|
26 |
struct point *points_to_look_at;
|
27 |
ssize_t width,height;
|
28 |
width = MagickGetImageWidth(input_wand);
|
29 |
height = MagickGetImageHeight(input_wand);
|
30 |
int number_of_points;
|
31 |
number_of_points=0;
|
32 |
|
33 |
|
34 |
#define ThrowWandException(wand) \
|
35 |
{ \
|
36 |
char \
|
37 |
*description; \
|
38 |
\
|
39 |
ExceptionType \
|
40 |
severity; \
|
41 |
\
|
42 |
description=MagickGetException(wand,&severity); \
|
43 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
|
44 |
description=(char *) MagickRelinquishMemory(description); \
|
45 |
exit(-1); \
|
46 |
}
|
47 |
|
48 |
MagickBooleanType status;
|
49 |
PixelIterator *input_iterator;
|
50 |
PixelWand **input_pixels;
|
51 |
register ssize_t x;
|
52 |
ssize_t y;
|
53 |
|
54 |
input_iterator=NewPixelIterator(input_wand);
|
55 |
if ((input_iterator == (PixelIterator *) NULL) )
|
56 |
ThrowWandException(input_wand);
|
57 |
|
58 |
for (y=0; y < (ssize_t) height; y++)
|
59 |
{
|
60 |
input_pixels=PixelGetNextIteratorRow(input_iterator,&width);
|
61 |
if ((input_pixels == (PixelWand **) NULL))
|
62 |
break;
|
63 |
for (x=0; x < (ssize_t) width; x++)
|
64 |
{
|
65 |
PixelGetMagickColor(input_pixels[x],&input_pixel);
|
66 |
if ((input_pixel.red!=input_pixel.green)&&(input_pixel.red!=input_pixel.blue)) {
|
67 |
fprintf(stderr,"%s %d,%d - %f,%f,%f\n",iname,(int)x,(int)y,input_pixel.red,input_pixel.green,input_pixel.blue);
|
68 |
exit(0);
|
69 |
}
|
70 |
}
|
71 |
}
|
72 |
|
73 |
input_iterator=DestroyPixelIterator(input_iterator);
|
74 |
input_wand=DestroyMagickWand(input_wand);
|
75 |
|
76 |
printf("%s\n",iname);
|
77 |
|
78 |
return (1);
|
79 |
}
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
int main(int argc,char **argv)
|
89 |
{
|
90 |
/* set the stack limit to 500 megabytes */
|
91 |
const rlim_t stacksize = 2000*1024*1024; // 2 gigabytes
|
92 |
struct rlimit rl;
|
93 |
int result;
|
94 |
result = getrlimit(RLIMIT_STACK, &rl);
|
95 |
if (result == 0)
|
96 |
{
|
97 |
if (rl.rlim_cur < stacksize)
|
98 |
{
|
99 |
rl.rlim_cur = stacksize;
|
100 |
result = setrlimit(RLIMIT_STACK, &rl);
|
101 |
if (result != 0)
|
102 |
{
|
103 |
fprintf(stderr, "setrlimit returned result = %d\n", result);
|
104 |
exit(-1);
|
105 |
}
|
106 |
}
|
107 |
}
|
108 |
else {
|
109 |
fprintf(stderr, "getrlimit returned result = %d\n", result);
|
110 |
exit(-1);
|
111 |
}
|
112 |
|
113 |
/* seed1 ip_Address fname */
|
114 |
char *iname=argv[1];
|
115 |
|
116 |
|
117 |
MagickWandGenesis();
|
118 |
|
119 |
test_if_image_bw(iname);
|
120 |
|
121 |
MagickWandTerminus();
|
122 |
exit(0);
|
123 |
}
|
124 |
|