/[opencvs]/eyes/black_white.c
ViewVC logotype

Annotation of /eyes/black_white.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Nov 12 07:33:44 2012 UTC (7 years, 3 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
cleanup

1 hib 1.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    
13    
14    
15     #define ThrowWandException(wand) \
16     { \
17     char \
18     *description; \
19     \
20     ExceptionType \
21     severity; \
22     \
23     description=MagickGetException(wand,&severity); \
24     (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
25     description=(char *) MagickRelinquishMemory(description); \
26     exit(-1); \
27     }
28    
29    
30    
31    
32    
33    
34    
35    
36    
37     int main(int argc,char **argv)
38     {
39     /* set the stack limit to 500 megabytes */
40     const rlim_t stacksize = 2000*1024*1024; // 2 gigabytes
41     struct rlimit rl;
42    
43     char *iname=argv[1];
44     char *oname=argv[2];
45    
46     unsigned char *otherrand;
47     int other;
48     unsigned short *rbuf;
49     unsigned short *rbackbuf;
50     int number_of_points;
51     int number_second_points;
52     struct point *points_to_look_at;
53     struct point *second_points_to_look_at;
54     struct point *end_points_to_look_at;
55     struct point *temp_points;
56     int number_end_points;
57     PixelWand *c_wand = NULL;
58     PixelWand *c2_wand = NULL;
59    
60     MagickWandGenesis();
61     ssize_t width,height;
62    
63     /*
64     if (!MagickSetResourceLimit(MemoryResource,2000000000)) {
65     fprintf(stderr,"couldnt set memory resource\n");
66     }
67     if (!MagickSetResourceLimit(AreaResource,2000000000)) {
68     fprintf(stderr,"couldnt set area resource\n");
69     }
70     if (!MagickSetResourceLimit(MapResource,2000000000)) {
71     fprintf(stderr,"couldnt set map resource\n");
72     }
73     */
74    
75     MagickPixelPacket input_pixel;
76     MagickPixelPacket output_pixel;
77     MagickWand *input_wand = NULL;
78     MagickWand *output_wand = NULL;
79     input_wand =NewMagickWand();
80     MagickReadImage(input_wand,iname);
81     width = MagickGetImageWidth(input_wand);
82     height = MagickGetImageHeight(input_wand);
83    
84    
85     PixelIterator *iterator;
86     PixelWand **pixels;
87     output_wand = NewMagickWand();
88     c_wand = NewPixelWand();
89     PixelSetColor(c_wand,"black"); /* for now */
90     MagickNewImage(output_wand,width,height,c_wand);
91     MagickSetImageChannelDepth(output_wand, AllChannels, 8);
92     MagickSetImageDepth(output_wand, 8);
93    
94    
95     MagickBooleanType status;
96     PixelIterator *input_iterator;
97     PixelIterator *output_iterator;
98     PixelWand **input_pixels;
99     PixelWand **output_pixels;
100     register ssize_t x;
101     ssize_t y;
102    
103     input_iterator=NewPixelIterator(input_wand);
104     if ((input_iterator == (PixelIterator *) NULL) )
105     ThrowWandException(input_wand);
106    
107     output_iterator=NewPixelIterator(output_wand);
108     if ((output_iterator == (PixelIterator *) NULL) )
109     ThrowWandException(input_wand);
110    
111     for (y=0; y < (ssize_t) height; y++)
112     {
113     input_pixels=PixelGetNextIteratorRow(input_iterator,&width);
114     ssize_t output_width;
115     output_pixels=PixelGetNextIteratorRow(output_iterator,&output_width);
116     if ((output_pixels == (PixelWand **) NULL))
117     break;
118    
119     for (x=0; x < (ssize_t) width; x++)
120     {
121     PixelGetMagickColor(input_pixels[x],&input_pixel);
122     PixelGetMagickColor(output_pixels[x/2],&output_pixel);
123     if (input_pixel.red >= 32768) {
124     output_pixel.red = 65535;
125     output_pixel.green = 65535;
126     output_pixel.blue = 65535;
127     }
128     else {
129     output_pixel.red = 0;
130     output_pixel.green = 0;
131     output_pixel.blue = 0;
132     }
133    
134     PixelSetMagickColor(output_pixels[x],&output_pixel);
135     } /* for each column */
136     (void) PixelSyncIterator(output_iterator);
137     }
138     input_iterator=DestroyPixelIterator(input_iterator);
139     output_iterator=DestroyPixelIterator(output_iterator);
140    
141     status=MagickWriteImages(output_wand,oname,MagickTrue);
142     if (status == MagickFalse)
143     ThrowWandException(output_wand);
144     output_wand=DestroyMagickWand(output_wand);
145     MagickWandTerminus();
146     return(0);
147     }
148    

  ViewVC Help
Powered by ViewVC 1.1.26