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

Contents of /eyes/half_scale.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Tue Jul 24 10:18:46 2012 UTC (5 years, 9 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
cleanup
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/2,height/2,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 if ((y%2) == 0) {
113 ssize_t output_width;
114 output_pixels=PixelGetNextIteratorRow(output_iterator,&output_width);
115 if ((output_pixels == (PixelWand **) NULL))
116 break;
117
118 for (x=0; x < (ssize_t) width; x++)
119 {
120 if ((x%2)==0) {
121 PixelGetMagickColor(input_pixels[x],&input_pixel);
122 PixelGetMagickColor(output_pixels[x/2],&output_pixel);
123 output_pixel.red=input_pixel.red;
124 output_pixel.green=input_pixel.green;
125 output_pixel.blue=input_pixel.blue;
126 PixelSetMagickColor(output_pixels[x/2],&output_pixel);
127 }
128 } /* for each column */
129 (void) PixelSyncIterator(output_iterator);
130 } /* if we are an even row */
131 }
132 input_iterator=DestroyPixelIterator(input_iterator);
133 output_iterator=DestroyPixelIterator(output_iterator);
134
135 status=MagickWriteImages(output_wand,oname,MagickTrue);
136 if (status == MagickFalse)
137 ThrowWandException(output_wand);
138 output_wand=DestroyMagickWand(output_wand);
139 MagickWandTerminus();
140 return(0);
141 }
142

  ViewVC Help
Powered by ViewVC 1.1.5