6 Hist = (
double **)calloc(
NLevel,
sizeof(
double));
8 *(Hist + l) = (
double *)calloc(NChar,
sizeof(
double));
9 Quart1[l] = (
unsigned char ) 0;
10 Median[l] = (
unsigned char ) 0;
11 Quart3[l] = (
unsigned char ) 0;
25 for(
int l=0;l<NLevel-1;l++){
26 for(
int r=0;r<ImHeight;r++)
28 ImIn[l]->Set(r,c,(
double)
pixel[(r*ImWidth+c)*NLevel+l]);
31 for(
int l=0;l<NLevel-1;l++){
42 for(
int r=0;r<ImHeight;r++)
44 pixel[(r*ImWidth+c)*NLevel+l] = (
unsigned char)ImOut->
Val(r,c);
56 int SubDiv = Times*Times;
57 unsigned char *raster = (
unsigned char *)malloc(SubDiv*NLevel*
ImWidth*ImHeight*
sizeof(
char));
62 pixel = (
unsigned char *)malloc(NLevel*
ImWidth*ImHeight*
sizeof(
char));
69 unsigned char *raster = (
unsigned char *)malloc(NLevel*
ImWidth*ImHeight*
sizeof(
char));
72 int NStep = NGridw*NGridh/2+30;
75 int *Sequence = (
int *)calloc(NGridw*NGridh,
sizeof(
int));
81 SwapBlocks(
pixel,raster,
ImWidth,ImHeight,Perm,NGridw,NGridh,Sequence,NPartition);
82 Sequence += NPartition;
85 printf(
"%d/%d %lf\n",
Step,NStep,
Step/(
double)NStep);
95 unsigned char *raster = (
unsigned char *)malloc(4*
ImWidth*ImHeight*
sizeof(
char));
97 int *Sequence = (
int *)calloc(NStep*NStep,
sizeof(
int));
100 int TtWidth = (int)(
ImWidth/(
double)NStep);
101 int TtHeight = (int)(ImHeight/(
double)NStep);
104 for(
int m=Grana;m>=0;m--){
114 for(
Step=NStep*NStep*(m+1);
Step>NStep*NStep*m;
Step--,n++)
116 THeight = (int)(((Sequence[n])/(
double)NStep))*TtHeight;
117 TWidth = ((Sequence[n]%NStep))*TtWidth;
119 int nPos = ((THeight)*
ImWidth + (TWidth))*NLevel;
122 Discretize(
pixel+nPos,raster+nPos,
ImWidth,ImHeight,TtWidth,TtHeight,Discrx,Discry);
139 void DrEffect::NablaPhi(){
140 if(Median[0] == 0){printf(
"Create an histogram before\n");
return;}
143 Weight.
a1 = 1.; Weight.
a2 = 0.;
144 Weight.
a3 = 0.; Weight.
a4 = 0.;
148 Phi = (
double **)calloc(2,
sizeof(
double));
150 *(Phi+i) = (
double *)calloc(
ImWidth*ImHeight,
sizeof(
double));
151 for(
int r=0;r<ImHeight;r++)
154 double Val = (
pixel[i*
NLevel]==0?1.:(double)
pixel[i*NLevel])/(double)Median[0];
155 Phi[0][i] = log10(Val);
156 ImIn->
Set(r,c,Phi[0][i]);
161 for(
int r=0;r<ImHeight;r++)
163 Phi[1][r*ImWidth+c] = ImIn->
Val(r,c);
173 Weight.
a1 = 1.; Weight.
a2 = 0.;
174 Weight.
a3 = 0.; Weight.
a4 = 0.;
182 for(
int l=0;l<NLevel-1;l++){
183 for(
int r=0;r<ImHeight;r++)
185 ImIn->
Set(r,c,(
double)
pixel[(r*ImWidth+c)*NLevel+l]);
189 for(
int r=0;r<ImHeight;r++)
191 pixel[(r*ImWidth+c)*NLevel+l] = (
unsigned char)ImIn->
Val(r,c);
200 for(
int l=0;l<NLevel-1;l++){
201 for(
int r=0;r<ImHeight;r++)
203 ImIn->
Set(r,c,(
double)
pixel[(r*ImWidth+c)*NLevel+l]);
205 for(
int r=0;r<ImHeight;r++)
207 pixel[(r*ImWidth+c)*NLevel+l] = (
unsigned char)ImOut->
Val(r,c);
213 void DrEffect::Histo(){
214 double Area[4] = {0.,0.,0.,0.};
215 for(
int l=0;l<
NLevel;l++){
216 for(
int i=0;i<NChar;i++){
217 Hist[l][i] = 0.000001;
220 for(
int l=0;l<3;l++){
221 for(
int h=0;h<ImHeight; h++) {
223 int Intens = (int)
pixel[(h*ImWidth+w)*NLevel +l];
225 Hist[l][Intens] += 1.;
230 double Max[4] = {0.,0.,0.,0.};
232 for(
int i=0;i<NChar;i++){
233 if(Max[l] < Hist[l][i])
234 Max[l] = Hist[l][i] ;
236 for(
int l=0;l<
NLevel;l++){
238 int Fatto[3] = {0,0,0};
239 for(
int i=0;i<NChar;i++){
241 Hist[l][i] /= Area[l] > 0. ? Area[l] : 1.;
242 dMedian += Hist[l][i];
243 if(dMedian > .25 && !Fatto[0]){
247 if(dMedian > .5 && !Fatto[1]){
251 if(dMedian > .75 && !Fatto[2]){
260 void DrEffect::PrintIntensity(){
261 FILE *Ciccia = fopen(
"Intensity.dat",
"w");
263 for(
int h=0;h<ImHeight; h++)
265 fprintf(Ciccia,
"%d %lf %lf %lf",(h*ImWidth+w),(
double)
pixel[(h*ImWidth+w)*NLevel +0],(
double)
pixel[(h*ImWidth+w)*NLevel +1],(
double)
pixel[(h*ImWidth+w)*NLevel +2]);
268 void DrEffect::BlackWhite(){
269 for(
int h=0;h<ImHeight; h++) {
273 Temp += (
double)
pixel[(h*ImWidth+w)*NLevel +l];
275 pixel[(h*ImWidth+w)*4 +l] = (GLubyte)(Temp*.333);
279 int DrEffect::Binary(
int Mode){
281 for(
int l=0;l<3;l++){
282 for(
int i=0;i<
ImWidth*ImHeight;i++){
283 if(
pixel[i*NLevel+l] < Median[l])
284 pixel[i*NLevel+l] = (
unsigned char)0;
286 pixel[i*NLevel+l] = (
unsigned char)255;
291 int DrEffect::Contrast(){
295 for(
int l=0;l<
NLevel;l++){
296 Factor[l] = .1*(double)NChar/(
double)((Quart3[l] - Quart1[l]));
297 Min[l] = (double) Quart1[l];
299 for(
int l=0;l<
NLevel;l++){
300 for(
int i=0;i<
ImWidth*ImHeight;i++){
301 double dNew = (double)
pixel[i*NLevel+l]*Factor[l];
302 unsigned char New = dNew > 0. ? (
unsigned char) dNew : 0;
303 pixel[i*NLevel+l] = New;
308 int DrEffect::SwapBlocks(
unsigned char *
Picture,
unsigned char *OutPicture,
int width,
int height,
PERMUTE *Perm,
int NGridw,
int NGridh,
int *Sequence,
int NPartition){
309 int Stepw = (int)(width/NGridw);
310 int Steph = (int)(height/NGridh);
311 memcpy(OutPicture,Picture,4*width*height);
312 for(
int p=0;p<NPartition;p++){
313 int PSwap = Sequence[p];
314 int vw1 = (int)(PSwap/(
double)NGridw);
315 int vh1 = PSwap%NGridh;
318 int vw2 = (int)(Perm[PSwap].m/(
double)NGridw);
319 int vh2 = Perm[PSwap].
m%NGridh;
322 for(
int vw=0;vw<Stepw;vw++){
323 for(
int vh=0;vh<Steph;vh++){
324 int Pos1 = (vw+w1) + (vh + h1)*width;
325 int Pos2 = (vw+w2) + (vh + h2)*width;
326 if(Pos1 < 0 || Pos1 >= width*height) {printf(
"Width out of range 0<=%d<%d\n",Pos1,width);
continue;}
327 if(Pos2 < 0 || Pos2 >= width*height) {printf(
"Height out of range 0<=%d<%d\n",Pos2,height);
continue;}
328 for(
int l=0;l<
NLevel;l++){
329 OutPicture[Pos1*NLevel+l] = Picture[Pos2*NLevel+l];
330 OutPicture[Pos2*NLevel+l] = Picture[Pos1*NLevel+l];
337 int DrEffect::ShiftBlocks(
unsigned char *Picture,
unsigned char *OutPicture,
int width,
int height,
int *Sequence,
int NGridw,
int NGridh,
int *Sequence1,
int NPartition){
338 int Stepw = (int)(width/NGridw);
339 int Steph = (int)(height/NGridh);
341 for(
int wi=0;wi<width;wi++){
342 int vw = (int) (wi/(
double)width*NGridw);
343 for(
int hi=0;hi<height;hi++){
344 int vh = (int) (hi/(
double)height*NGridh);
345 int PosIn = vw*NGridh + vh;
346 int PosOut = Sequence[PosIn];
347 int vvw = (int)(PosOut/(
double)NGridw);
348 int vvh = PosOut%NGridh;
349 int wo = wi - (vw - vvw)*Stepw;
350 int ho = hi - (vh - vvh)*Steph;
352 if(wo < 0 || wo >= width) {printf(
"Width out of range 0<=%d<%d\n",wo,width);
continue;}
353 if(ho < 0 || ho >= height) {printf(
"Height out of range 0<=%d<%d\n",ho,height);
continue;}
354 for(
int l=0;l<
NLevel;l++){
355 OutPicture[(ho*width+wo)*NLevel+l] = Picture[(hi*width+wi)*NLevel+l];
362 int DrEffect::Discretize(
unsigned char *Picture,
unsigned char *OutPicture,
int ImWidth,
int ImHeight,
int WWidth,
int WHeight,
int Blockw,
int Blockh){
363 for(
int wo=0;wo<WWidth;wo+=Blockw){
364 for(
int ho=0;ho<WHeight;ho+=Blockh){
365 for(
int l=0;l<
NLevel;l++){
366 double ColAverage=0.;
367 for(
int bwi=0;bwi<Blockw;bwi++){
368 for(
int bhi=0;bhi<Blockh;bhi++){
371 ColAverage += (double)Picture[(hi*ImWidth+wi)*NLevel+l];
374 ColAverage /= (double)(Blockw*Blockh);
375 for(
int bwi=0;bwi<Blockw;bwi++){
376 for(
int bhi=0;bhi<Blockh;bhi++){
379 OutPicture[(hi*ImWidth+wi)*NLevel+l] = (
unsigned char) ColAverage;
387 int DrEffect::IncreaseResolution(
unsigned char *Picture,
unsigned char *OutPicture,
int ImWidth,
int ImHeight,
int Times){
388 int OutWidth = ImWidth*Times;
389 int OutHeight = ImHeight*Times;
390 double DeltaIn=1./(double)(ImWidth-1);
391 double DeltaOut=1./(double)(OutWidth-1);
393 double *dArray = (
double *)calloc(ImWidth+NOrder+1,
sizeof(
double));
394 for(
int p=0;p<=ImWidth+NOrder;p++){
398 else if( (NOrder<=p) && (p<=
ImWidth) ){
399 dArray[p] = (p-NOrder+1)*DeltaIn;
402 dArray[p] = (p-NOrder+2)*DeltaIn;
423 for(
int l=0;l<
NLevel;l++){
425 for(
int h=0;h<ImHeight;h++){
429 OutPicture[((ho+0)*OutWidth+(wo+0))*NLevel+l] =
430 .5*(Picture[( (h+0)*ImWidth+(w-1) )*NLevel+l] +
431 Picture[( (h-1)*ImWidth+(w+0) )*NLevel+l]);
432 if(h>0 && w<ImWidth-1)
433 OutPicture[( (ho+0)*OutWidth+(wo+1))*NLevel+l] =
434 .5*(Picture[( (h+0)*ImWidth+(w+1) )*NLevel+l] +
435 Picture[( (h-1)*ImWidth+(w+0) )*NLevel+l]);
436 if(h<ImHeight-1 && w<ImWidth-1)
437 OutPicture[( (ho+1)*OutWidth+(wo+1))*NLevel+l] =
438 .5*(Picture[( (h+0)*ImWidth+(w+1) )*NLevel+l] +
439 Picture[( (h+1)*ImWidth+(w+0) )*NLevel+l]);
440 if(h<ImHeight-1 && w>0)
441 OutPicture[( (ho+1)*OutWidth+(wo+0))*NLevel+l] =
442 .5*(Picture[( (h+0)*ImWidth+(w-1) )*NLevel+l] +
443 Picture[( (h+1)*ImWidth+(w+0) )*NLevel+l]);
449 int DrEffect::Noise(
unsigned char *Picture,
unsigned char *OutPicture,
int width,
int height){
455 Mask[0][0] = 1; Mask[0][1] = 1; Mask[0][2] = 1;
456 Mask[1][0] = 1; Mask[1][1] = 1; Mask[1][2] = 1;
457 Mask[2][0] = 1; Mask[2][1] = 1; Mask[2][2] = 1;
459 Mask[0][0] = 1; Mask[0][1] = 1; Mask[0][2] = 1;
460 Mask[1][0] = 1; Mask[1][1] = 2; Mask[1][2] = 1;
461 Mask[2][0] = 1; Mask[2][1] = 1; Mask[2][2] = 1;
463 Mask[0][0] = 1; Mask[0][1] = 2; Mask[0][2] = 1;
464 Mask[1][0] = 2; Mask[1][1] = 4; Mask[1][2] = 2;
465 Mask[2][0] = 1; Mask[2][1] = 2; Mask[2][2] = 1;
473 for(
int l=0;l<
NLevel;l++){
474 for(
int h=0;h<height-NMaskh; h++) {
475 for(
int w=0;w<width-NMaskw; w++) {
476 OutPicture[(h*width+w)*NLevel +l] = 0;
477 for(
int lh=0;lh<NMaskh;lh++){
478 for(
int lw=0;lw<NMaskw;lw++){
479 OutPicture[(h*width+w)*NLevel +l] += (
unsigned char)(
480 Mask[lh][lw]*Picture[((h+lh)*width+(w+lw))*NLevel +l]*Det);
489 int DrEffect::Edges(
unsigned char *Picture,
unsigned char *OutPicture,
int width,
int height){
495 Mask[0][0] = 1; Mask[0][1] = 0; Mask[0][2] = -1;
496 Mask[1][0] = 2; Mask[1][1] = 0; Mask[1][2] = -2;
497 Mask[2][0] = 1; Mask[2][1] = 0; Mask[2][2] = -1;
502 for(
int h=0;h<height-NMaskh; h++) {
503 for(
int w=0;w<width-NMaskw; w++) {
504 OutPicture[(h*width+w)*NLevel +l] = 0;
506 for(
int lh=0;lh<NMaskh;lh++){
507 for(
int lw=0;lw<NMaskw;lw++){
508 if(h+lh-1 <0 )
continue;
509 if(w+lw-1<0 )
continue;
510 if(h+lh-1 > height-1)
continue;
511 if(w+lw-1 > width-1)
continue;
512 Temp += ASS((Mask[lh][lw]*Picture[((h+lh-1)*width+(w+lw-1))*NLevel +l]*Det));
516 OutPicture[(h*width+w)*NLevel +l] += (
unsigned char) Temp;
524 for(
int h=0;h<height-NMaskh; h++) {
525 for(
int w=0;w<width-NMaskw; w++) {
527 for(
int lh=NMaskh;lh>0;lh--){
528 for(
int lw=0;lw<NMaskw;lw++){
529 if(h+lh-1 <0 )
continue;
530 if(w+lw-1<0 )
continue;
531 if(h+lh-1 > height-1)
continue;
532 if(w+lw-1 > width-1)
continue;
534 Temp += ASS((Mask[lw][lh]*Picture[((h+lh-1)*width+(w+lw-1))*NLevel +l]*Det));
537 OutPicture[(h*width+w)*NLevel +l] += (
unsigned char) Temp;
543 void DrEffect::DrEkeyboard(
unsigned char key){
double a4
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
int m
Second number of the couple.
void BackFold(Matrice *In, Matrice *Out, int NShift)
Shift all the rows upwards/downwards.
void Run()
Create an animation.
void EffectCoarseGrain(int Grana)
Defocus the images in blocks.
int WritePngwriter()
Write a png file of the data in pixel (uses libpngwriter)
Indices for the permutation.
int PermuteRandomAll(int *Sequence, int NMass)
Permutes a sequence without repeating.
int Picture()
Write a tiff file of the data in pixel.
void EffectMotion()
Shifting of pixels.
void keyboardDraw(unsigned char key)
Combines the key with the functions.
int ImWidth
Width and height of the image.
double a3
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
void Transpose()
Transpose the matrix.
void EffectMC()
Applies a random disposition of blocks.
double Val(int row)
Returns a value in 1d.
void EffectFilter()
Applies a filter to pixel.
double a2
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
double a1
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
Matrice computes the algebric operations on matrices.
bool Set(int row, int column, double Val)
Set a coefficient.
int Step
Current step for the picture's name.
int ApplyFilter(Matrice *Point, Matrice *Res, Matrice *Mask)
Applies the filter.
void EffectIncrease()
Increase the resolution.
Implementation of useful algorythms.
double a0
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
int NLevel
Levels of the images data (usually 4=RGBA)
void Print()
Print the entries.
GLubyte * pixel
Principal image (always allocated)