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

Contents of /eyes/predither_bw.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Apr 8 22:26:23 2013 UTC (5 years, 7 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
work in progress.  Doing heart_blob finishing touches
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     if (!MagickSetResourceLimit(MemoryResource,2000000000)) {
64     fprintf(stderr,"couldnt set memory resource\n");
65     }
66     if (!MagickSetResourceLimit(AreaResource,2000000000)) {
67     fprintf(stderr,"couldnt set area resource\n");
68     }
69     if (!MagickSetResourceLimit(MapResource,2000000000)) {
70     fprintf(stderr,"couldnt set map resource\n");
71     }
72    
73     MagickPixelPacket input_pixel;
74     MagickPixelPacket output_pixel;
75     MagickWand *input_wand = NULL;
76     MagickWand *output_wand = NULL;
77     input_wand =NewMagickWand();
78     MagickReadImage(input_wand,iname);
79     width = MagickGetImageWidth(input_wand);
80     height = MagickGetImageHeight(input_wand);
81    
82    
83     PixelIterator *iterator;
84     PixelWand **pixels;
85     output_wand = NewMagickWand();
86     c_wand = NewPixelWand();
87     PixelSetColor(c_wand,"black"); /* for now */
88     MagickNewImage(output_wand,width,height,c_wand);
89     MagickSetImageChannelDepth(output_wand, AllChannels, 8);
90     MagickSetImageDepth(output_wand, 8);
91    
92    
93     MagickBooleanType status;
94     PixelIterator *input_iterator;
95     PixelIterator *output_iterator;
96     PixelWand **input_pixels;
97     PixelWand **output_pixels;
98     register ssize_t x;
99     ssize_t y;
100    
101     input_iterator=NewPixelIterator(input_wand);
102     if ((input_iterator == (PixelIterator *) NULL) )
103     ThrowWandException(input_wand);
104    
105     output_iterator=NewPixelIterator(output_wand);
106     if ((output_iterator == (PixelIterator *) NULL) )
107     ThrowWandException(input_wand);
108    
109     for (y=0; y < (ssize_t) height; y++)
110     {
111     input_pixels=PixelGetNextIteratorRow(input_iterator,&width);
112     ssize_t output_width;
113     output_pixels=PixelGetNextIteratorRow(output_iterator,&output_width);
114     if ((output_pixels == (PixelWand **) NULL))
115     break;
116    
117     for (x=0; x < (ssize_t) width; x++)
118     {
119     PixelGetMagickColor(input_pixels[x],&input_pixel);
120     PixelGetMagickColor(output_pixels[x],&output_pixel);
121     if (input_pixel.red) {
122     output_pixel.red=input_pixel.red;
123     output_pixel.green=input_pixel.green;
124     output_pixel.blue=input_pixel.blue;
125     }
126     else {
127     output_pixel.red = 255*256; /* Really 254 */
128     output_pixel.green = 255*256;
129     output_pixel.blue = 255*256;
130     }
131     PixelSetMagickColor(output_pixels[x],&output_pixel);
132     } /* for each column */
133     (void) PixelSyncIterator(output_iterator);
134     }
135     input_iterator=DestroyPixelIterator(input_iterator);
136     output_iterator=DestroyPixelIterator(output_iterator);
137    
138     status=MagickWriteImages(output_wand,oname,MagickTrue);
139     if (status == MagickFalse)
140     ThrowWandException(output_wand);
141     output_wand=DestroyMagickWand(output_wand);
142     MagickWandTerminus();
143     return(0);
144     }
145    

  ViewVC Help
Powered by ViewVC 1.1.5