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

Contents of /eyes/hp_predither.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sat Aug 17 21:34:31 2013 UTC (4 years, 11 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
random doesnt work well. did other way
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 if (argc != 4) {
43 fprintf(stderr,"percentage cut of image for penrose\n usage: hp_predither <inpout.png> <output.png> <pct>\n");
44 exit(-1);
45 }
46 char *iname=argv[1];
47 char *oname=argv[2];
48 double pct = atof(argv[3]);
49 int pctran = (pct * 65536 )/100;
50
51 unsigned char *otherrand;
52 int other;
53 unsigned short *rbuf;
54 unsigned short *rbackbuf;
55 int number_of_points;
56 int number_second_points;
57 struct point *points_to_look_at;
58 struct point *second_points_to_look_at;
59 struct point *end_points_to_look_at;
60 struct point *temp_points;
61 int number_end_points;
62 PixelWand *c_wand = NULL;
63 PixelWand *c2_wand = NULL;
64
65 MagickWandGenesis();
66 ssize_t width,height;
67
68 if (!MagickSetResourceLimit(MemoryResource,2000000000)) {
69 fprintf(stderr,"couldnt set memory resource\n");
70 }
71 if (!MagickSetResourceLimit(AreaResource,2000000000)) {
72 fprintf(stderr,"couldnt set area resource\n");
73 }
74 if (!MagickSetResourceLimit(MapResource,2000000000)) {
75 fprintf(stderr,"couldnt set map resource\n");
76 }
77
78 MagickPixelPacket input_pixel;
79 MagickPixelPacket output_pixel;
80 MagickWand *input_wand = NULL;
81 MagickWand *output_wand = NULL;
82 input_wand =NewMagickWand();
83 MagickReadImage(input_wand,iname);
84 width = MagickGetImageWidth(input_wand);
85 height = MagickGetImageHeight(input_wand);
86
87
88 PixelIterator *iterator;
89 PixelWand **pixels;
90 output_wand = NewMagickWand();
91 c_wand = NewPixelWand();
92 PixelSetColor(c_wand,"black"); /* for now */
93 MagickNewImage(output_wand,width,height,c_wand);
94 MagickSetImageChannelDepth(output_wand, AllChannels, 8);
95 MagickSetImageDepth(output_wand, 8);
96
97
98 MagickBooleanType status;
99 PixelIterator *input_iterator;
100 PixelIterator *output_iterator;
101 PixelWand **input_pixels;
102 PixelWand **output_pixels;
103 register ssize_t x;
104 ssize_t y;
105
106 input_iterator=NewPixelIterator(input_wand);
107 if ((input_iterator == (PixelIterator *) NULL) )
108 ThrowWandException(input_wand);
109
110 output_iterator=NewPixelIterator(output_wand);
111 if ((output_iterator == (PixelIterator *) NULL) )
112 ThrowWandException(input_wand);
113 int pos=0;
114 for (y=0; y < (ssize_t) height; y++)
115 {
116 input_pixels=PixelGetNextIteratorRow(input_iterator,&width);
117 ssize_t output_width;
118 output_pixels=PixelGetNextIteratorRow(output_iterator,&output_width);
119 if ((output_pixels == (PixelWand **) NULL))
120 break;
121
122 for (x=0; x < (ssize_t) width; x++)
123 {
124 PixelGetMagickColor(input_pixels[x],&input_pixel);
125 PixelGetMagickColor(output_pixels[x],&output_pixel);
126 if (pos > 65536) {
127 output_pixel.red=input_pixel.red;
128 output_pixel.green=input_pixel.green;
129 output_pixel.blue=input_pixel.blue;
130 pos = pos - 65536;
131 }
132 else {
133 output_pixel.red=65535;
134 output_pixel.green=65535;
135 output_pixel.blue=65535;
136 }
137 pos = pos + pctran;
138
139 PixelSetMagickColor(output_pixels[x],&output_pixel);
140 } /* for each column */
141 (void) PixelSyncIterator(output_iterator);
142 }
143 input_iterator=DestroyPixelIterator(input_iterator);
144 output_iterator=DestroyPixelIterator(output_iterator);
145
146 status=MagickWriteImages(output_wand,oname,MagickTrue);
147 if (status == MagickFalse)
148 ThrowWandException(output_wand);
149 output_wand=DestroyMagickWand(output_wand);
150 MagickWandTerminus();
151 return(0);
152 }
153

  ViewVC Help
Powered by ViewVC 1.1.5