This repository was archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist1.c
210 lines (159 loc) · 5.37 KB
/
hist1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "MagickWand/studio.h"
#include "MagickWand/MagickWand.h"
// #define DegreesToRadians(a) (a*M_PI/180.)
// #include "image-magick.c"
// #include <wand/MagickWand.h>
#include <math.h>
void sorting(size_t *x,size_t y, char color[]);
int sort_hist(const void *p1, const void *q1)
{
const PixelWand **pixels = p1;
const PixelWand **pixels1 = q1;
size_t ip,iq;
ip = PixelGetColorCount(*pixels);
iq = PixelGetColorCount(*pixels1);
if(ip > iq)return(1);
if(ip < iq)return(-1);
return(0);
}
int main(int argc, const char * argv[]) {
// Prototype vars
MagickWand * wand, *wand1, *wand0;
PixelWand ** histogram, *pwand;
const double *arguments;
typedef int bool;
const char *DistortMethod[3];
double r[6];
DrawingWand *dw = NULL;
PixelWand *PW1,*PW2,*PW3,*PW4;
size_t histogram_count = 0;
// Boot environment.
MagickWandGenesis();
// Allocate & read image
wand = NewMagickWand();
pwand = NewPixelWand();
dw = NewDrawingWand();
MagickReadImage(wand, "cnbc.jpg");
dw = NewDrawingWand();
PW1 = PW2 = PW3 = PW4 = PW5 = NewPixelWand();
PixelSetColor(PW1,"white");
PixelSetColor(PW2,"#cccccc");
PixelSetColor(PW3,"black");
PixelSetColor(PW4,"#333333");
PixelSetColor(PW5,"#FFFFFF");
// Get Histogram as array of pixels
printf("%s\n", DistortMethod[0]);
// printf("%lu\n", &histogram_count);
// &histogram_count=8;
MagickSetImageDepth(wand,8);
histogram = MagickGetImageHistogram(wand, &histogram_count);
// Iterate over each pixel & dump info.
// printf("%lu\n", histogram_count);
size_t colorcount[histogram_count];
char *color[histogram_count];
qsort(histogram,histogram_count,sizeof(PixelWand *),sort_hist);
size_t i;
wand1 = CloneMagickWand(wand);
wand0 = CloneMagickWand(wand);
for(i=histogram_count-1; i>=histogram_count-2; i--) {
colorcount[i] = PixelGetColorCount(histogram[i]);
color[i] = PixelGetColorAsString(histogram[i]);
printf("%s => %zu\n",
color[i],
colorcount[i]);
//-size 1x1 xc:#E36612
MagickSetImageColormapColor(wand,1,histogram[i]);
MagickAppendImages(wand, MagickTrue);
}
/*UndefinedDitherMethod
NoDitherMethod
RiemersmaDitherMethod
FloydSteinbergDitherMethod*/
// +dither -remap
MagickRemapImage(wand1, wand, NoDitherMethod);
//gradient
MagickSetImageMatte(wand, MagickTrue);
// -size 2x8
MagickResizeImage(wand0, 2,8, GaussianFilter);
//rotate
MagickRotateImage(wand,pwand,270);
// -roll +2+0
MagickRollImage(wand0, 2, 0);
//-roll +4+0
MagickRollImage(wand0, 4, 0);
//-roll +6+0
MagickRollImage(wand0, 6, 0);
//-append
MagickAppendImages(wand, MagickTrue);
// MagickMontageImage(MagickWand *wand,
// const DrawingWand drawing_wand,const char *tile_geometry,
// const char *thumbnail_geometry,const MontageMode mode,
// const char *frame)
MagickMontageImage(wand, dw, "6x4+0+0", "1200x874+4+3",UndefinedMode,"15x15+3+3");
// -define compose:args=100
MagickSetImageArtifact(wand, "compose:args", "100");
//-compose blend -composite
MagickCompositeImage(wand, wand0, BlendCompositeOp,MagickFalse, 0, 0);
//-fuzz 20%
//-fill 'gray(80%)' -opaque white
MagickOpaquePaintImage(wand,PW1,PW2,20*QuantumRange/100,MagickFalse);
//-fuzz 20%
//-fill 'gray(20%)' -opaque black
MagickOpaquePaintImage(wand,PW3,PW4,20*QuantumRange/100,MagickFalse);
/*this will be in a loop according to number of colors chhosen*/
//+transparent '#FFFFFF' -alpha extract
MagickTransparentPaintImage(wand, PW5, 1.0, 0, MagickFalse);
// -rotate -45 +repage -gravity center -crop 600x437+0+0 +repage
MagickRotateImage(wand,pwand,-45);
MagickSetImageGravity(wand, CenterGravity);
MagickCropImage(wand, 437, 600, 0, 0);
MagickResetImagePage(wand,"600x437+0+0");
// -clone 0 -clone 2 -compose softlight -composite
// wand0 = CloneMagickWand(wand);
// wand2 = CloneMagickWand(wand);
// MagickCompositeImage(wand, wand0, LinearDodgeCompositeOp,MagickFalse, 0, 0);
// MagickCompositeImage(wand, wand2, LinearDodgeCompositeOp,MagickFalse, 0, 0);
// -delete 0,2
// DestroyMagickWand(wand0);
// DestroyMagickWand(wand2);
//+swap -compose over -alpha off -compose copy_opacity -composite '(' -clone 0 -background black -shadow 25x2+0+0 -channel A -level 0,50% +channel ')' +swap +repage -gravity center -compose over -composite ./EMBROIDERY.22607/tmpI_0.mpc
/*And loop ends here*/
// sorting(colorcount,histogram_count, *color);
// Clean-up
MagickWriteImage(wand,"cnbcjpg_m.jpg");
if(wand)wand = DestroyMagickWand(wand);
if(dw)dw = DestroyDrawingWand(dw);
DestroyPixelWand(*histogram);
MagickWandTerminus();
return 0;
}
void sorting(size_t *x, size_t y, char color[])
{
size_t i,j,temp;
size_t index[y];
size_t temp2;
printf("%s\n", &color[0]);
for(i = 1; i <= y-1; i++)
{
for(j = 0; j < y-i; j++)
{
// printf("%zu\n", *(x+j));
if(*(x+j) <*(x+j+1))
{
temp = *(x+j);
*(x+j) = *(x+j+1);
*(x+j+1) = temp;
// temp2 = ;
// j = j+1;
// j+1 = temp2
// &color[j+1] = temp2;
}
}
}
for(i = 0; i < 5; i++)
{
printf("\n%zu",*(x+i));
printf("\n%s",&color[0]);
x[i] =*(x+i);
}
}