Allink  v0.1
DrOpenGL.cpp
1 #include "DrEffect.h"
2 #ifdef __glut_h__
3 DrEffect::DrEffect(){
4  Mat = new Matematica();
5  NChar = 256;
6  Hist = (double **)calloc(NLevel,sizeof(double));
7  for(int l=0;l<NLevel;l++){
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;
12  }
13  Initialize();
14 };
16  int NStep = 1000;
17  int Acc = -1;
18  int Vel = 100;
19  int Pos = 0.;
20  Matrice *ImIn[3];
21  for(int d=0;d<3;d++){
22  ImIn[d] = new Matrice(ImHeight,ImWidth);
23  }
24  Matrice *ImOut = new Matrice(ImHeight,ImWidth);
25  for(int l=0;l<NLevel-1;l++){
26  for(int r=0;r<ImHeight;r++)
27  for(int c=0;c<ImWidth;c++)
28  ImIn[l]->Set(r,c,(double)pixel[(r*ImWidth+c)*NLevel+l]);
29  }
30  for(Step=NStep;Step>0;Step--){
31  for(int l=0;l<NLevel-1;l++){
32  // for(int r=0;r<ImHeight;r++){
33  // int r1 = r + Pos;
34  // if(r1 >= In->pNRow()) r1 -= ImHeight;
35  // if(r1 < 0) r1 += ImHeight;
36  // for(int c=0;c<Imwidth;c++){
37 
38  // Out->Set(r1,c,In->Val(r,c));
39  // }
40  // }
41  Mat->BackFold(ImIn[l],ImOut,Pos);
42  for(int r=0;r<ImHeight;r++)
43  for(int c=0;c<ImWidth;c++)
44  pixel[(r*ImWidth+c)*NLevel+l] = (unsigned char)ImOut->Val(r,c);
45  }
46  Vel += Acc;
47  Pos += Vel;
48  //WritePixel();
50  }
51  delete ImOut;
52  delete ImIn;
53 }
55  int Times = 2;
56  int SubDiv = Times*Times;
57  unsigned char *raster = (unsigned char *)malloc(SubDiv*NLevel*ImWidth*ImHeight*sizeof(char));
58  //IncreaseResolution(pixel,raster,ImWidth,ImHeight,Times);
59  free(pixel);
60  ImWidth *= Times;
61  ImHeight *= Times;
62  pixel = (unsigned char *)malloc(NLevel*ImWidth*ImHeight*sizeof(char));
63  memcpy(pixel,raster,NLevel*ImWidth*ImHeight);
64  free(raster);
65  //SubWindow1 = glutCreateSubWindow(MainWindow, 0, 0,width/2,height/2);
66  return;
67 }
69  unsigned char *raster = (unsigned char *)malloc(NLevel*ImWidth*ImHeight*sizeof(char));
70  int NGridw = 32;
71  int NGridh = 32;//24;
72  int NStep = NGridw*NGridh/2+30;
73  //int NBlock = 4;
74  int NPartition = 1;//(int)(NGridw*NGridh/(double)NStep);
75  int *Sequence = (int *)calloc(NGridw*NGridh,sizeof(int));
76  PERMUTE *Perm = (PERMUTE *)calloc(NGridw*NGridh,sizeof(PERMUTE));
77  Mat->PermuteRandomAll(Perm,NGridw*NGridh);
78  Mat->PermuteRandomAll(Sequence,NGridw*NGridh/2);
79  //for(Step=NStep;Step>0;Step--)
80  {
81  SwapBlocks(pixel,raster,ImWidth,ImHeight,Perm,NGridw,NGridh,Sequence,NPartition);
82  Sequence += NPartition;
83  memcpy(pixel,raster,NLevel*ImWidth*ImHeight);
84  glutPostRedisplay();
85  printf("%d/%d %lf\n",Step,NStep,Step/(double)NStep);
86  //WritePng();
87  WritePixel();
88  }
89  free(Perm);
90  free(raster);
91  //free(Sequence);
92  return;
93 }
95  unsigned char *raster = (unsigned char *)malloc(4*ImWidth*ImHeight*sizeof(char));
96  int NStep = 8;//NGridw*NGridh/2;
97  int *Sequence = (int *)calloc(NStep*NStep,sizeof(int));
98  int Discrx = 1;
99  int Discry = 1;
100  int TtWidth = (int)(ImWidth/(double)NStep);
101  int TtHeight = (int)(ImHeight/(double)NStep);
102  int TWidth = 0;
103  int THeight= 0;
104  for(int m=Grana;m>=0;m--){
105  Discrx *= 2;
106  Discry *= 2;
107  }
108  int m = 0;
109  {
110  Mat->PermuteRandomAll(Sequence,NStep*NStep);
111  THeight = 0;
112  TWidth = 0;
113  int n=0;
114  for(Step=NStep*NStep*(m+1);Step>NStep*NStep*m;Step--,n++)
115  {
116  THeight = (int)(((Sequence[n])/(double)NStep))*TtHeight;
117  TWidth = ((Sequence[n]%NStep))*TtWidth;
118  memcpy(raster,pixel,4*ImWidth*ImHeight);
119  int nPos = ((THeight)*ImWidth + (TWidth))*NLevel;
120  //int nPos = ((THeight-TtHeight)*ImWidth + (TWidth-TtWidth))*NLevel;
121  //printf("(%d %d) (%d %d) %d %d %d %d %d\n",TWidth,THeight,ImWidth,ImHeight,Discrx,Discry,Sequence[n],nPos,(ImHeight*ImWidth + (ImWidth))*NLevel);
122  Discretize(pixel+nPos,raster+nPos,ImWidth,ImHeight,TtWidth,TtHeight,Discrx,Discry);
123  if((n+1)%NStep==0){
124  THeight+= TtHeight;
125  TWidth = 0;
126  }
127  TWidth += TtWidth;
128  memcpy(pixel,raster,4*ImWidth*ImHeight);
129  glutPostRedisplay();
130  //printf("%d/%d %lf\n",Step,NStep,Step/(double)NStep);
131  //WritePng();
132  //WritePixel();
133  }
134  }
135  free(raster);
136  //free(Sequence);
137  return;
138 }
139 void DrEffect::NablaPhi(){
140  if(Median[0] == 0){printf("Create an histogram before\n");return;}
141  SPLINE Weight;
142  Weight.a0 = 0.;
143  Weight.a1 = 1.; Weight.a2 = 0.;
144  Weight.a3 = 0.; Weight.a4 = 0.;
145  Matrice *Mask = new Matrice(Weight,3);
146  Mask->Print();
147  Matrice *ImIn = new Matrice(ImHeight,ImWidth);
148  Phi = (double **)calloc(2,sizeof(double));
149  for(int i=0;i<2;i++)
150  *(Phi+i) = (double *)calloc(ImWidth*ImHeight,sizeof(double));
151  for(int r=0;r<ImHeight;r++)
152  for(int c=0;c<ImWidth;c++){
153  int i = r*ImWidth+c;
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]);
157  }
158  Mat->ApplyFilter(ImIn,Mask);
159  Mask->Transpose();
160  Mat->ApplyFilter(ImIn,Mask);
161  for(int r=0;r<ImHeight;r++)
162  for(int c=0;c<ImWidth;c++)
163  Phi[1][r*ImWidth+c] = ImIn->Val(r,c);
164  free(Mask);
165  free(ImIn);
166  printf("Fatto\n");
167 }
169  //Mat->Binary(pixel,width,height,100);return;
170  //Mat->Contrast(pixel,width,height);return;
171  SPLINE Weight;
172  Weight.a0 = 0.;
173  Weight.a1 = 1.; Weight.a2 = 0.;
174  Weight.a3 = 0.; Weight.a4 = 0.;
175  Matrice *Mask = new Matrice(Weight,3);
176  double Sigma = .5;
177  double CutOff = 3.;
178  // Mask->FillGaussian(Sigma,CutOff);
179  Mask->Print();
180  Matrice *ImIn = new Matrice(ImHeight,ImWidth);
181  //int l=1;
182  for(int l=0;l<NLevel-1;l++){
183  for(int r=0;r<ImHeight;r++)
184  for(int c=0;c<ImWidth;c++)
185  ImIn->Set(r,c,(double)pixel[(r*ImWidth+c)*NLevel+l]);
186  Mat->ApplyFilter(ImIn,Mask);
187  // Mask->Transpose();
188  // Mat->ApplyFilter(ImIn,Mask);
189  for(int r=0;r<ImHeight;r++)
190  for(int c=0;c<ImWidth;c++)
191  pixel[(r*ImWidth+c)*NLevel+l] = (unsigned char)ImIn->Val(r,c);
192  }
193  delete Mask;
194  delete ImIn;
195  return;
196 }
198  Matrice *ImIn = new Matrice(ImHeight,ImWidth);
199  Matrice *ImOut = new Matrice(ImHeight,ImWidth);
200  for(int l=0;l<NLevel-1;l++){
201  for(int r=0;r<ImHeight;r++)
202  for(int c=0;c<ImWidth;c++)
203  ImIn->Set(r,c,(double)pixel[(r*ImWidth+c)*NLevel+l]);
204  Mat->BackFold(ImIn,ImOut,120);
205  for(int r=0;r<ImHeight;r++)
206  for(int c=0;c<ImWidth;c++)
207  pixel[(r*ImWidth+c)*NLevel+l] = (unsigned char)ImOut->Val(r,c);
208  }
209  delete ImOut;
210  delete ImIn;
211  return;
212 }
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;
218  }
219  }
220  for(int l=0;l<3;l++){
221  for(int h=0;h<ImHeight; h++) {
222  for(int w=0;w<ImWidth; w++) {
223  int Intens = (int)pixel[(h*ImWidth+w)*NLevel +l];
224  //if( Intens <= 0 || Intens >= NChar -1){ continue;}
225  Hist[l][Intens] += 1.;
226  Area[l] += 1.;
227  }
228  }
229  }
230  double Max[4] = {0.,0.,0.,0.};
231  for(int l=0;l<NLevel;l++)
232  for(int i=0;i<NChar;i++){
233  if(Max[l] < Hist[l][i])
234  Max[l] = Hist[l][i] ;
235  }
236  for(int l=0;l<NLevel;l++){
237  double dMedian = 0.;
238  int Fatto[3] = {0,0,0};
239  for(int i=0;i<NChar;i++){
240  // Hist[l][i] /= Max[l] > 0. ? Max[l] : 1.;
241  Hist[l][i] /= Area[l] > 0. ? Area[l] : 1.;
242  dMedian += Hist[l][i];
243  if(dMedian > .25 && !Fatto[0]){
244  Quart1[l] = i;
245  Fatto[0] = 1;
246  }
247  if(dMedian > .5 && !Fatto[1]){
248  Median[l] = i;
249  Fatto[1] = 1;
250  }
251  if(dMedian > .75 && !Fatto[2]){
252  Quart3[l] = i;
253  Fatto[2] = 1;
254  }
255  //printf("%d %d %lf Quartiles %d %d %d\n",l,i,Hist[l][i],Quart1[l],Median[l],Quart3[l]);
256  }
257  }
258  //PrintIntensity();
259 }
260 void DrEffect::PrintIntensity(){
261  FILE *Ciccia = fopen("Intensity.dat","w");
262  for(int l=0;l<3;l++)
263  for(int h=0;h<ImHeight; h++)
264  for(int w=0;w<ImWidth; w++)
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]);
266  fclose(Ciccia);
267 }
268 void DrEffect::BlackWhite(){
269  for(int h=0;h<ImHeight; h++) {
270  for(int w=0;w<ImWidth; w++) {
271  double Temp = 0.;
272  for(int l=0;l<3;l++)
273  Temp += (double)pixel[(h*ImWidth+w)*NLevel +l];
274  for(int l=0;l<3;l++)
275  pixel[(h*ImWidth+w)*4 +l] = (GLubyte)(Temp*.333);
276  }
277  }
278 }
279 int DrEffect::Binary(int Mode){
280  Histo();
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;
285  else
286  pixel[i*NLevel+l] = (unsigned char)255;
287  }
288  }
289  return 1;
290 }
291 int DrEffect::Contrast(){
292  Histo();
293  double Factor[NLevel];
294  double Min[NLevel];
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];
298  }
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];// - Min[l];
302  unsigned char New = dNew > 0. ? (unsigned char) dNew : 0;
303  pixel[i*NLevel+l] = New;
304  }
305  }
306  return 1;
307 }
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;
316  int w1 = vw1*Stepw;
317  int h1 = vh1*Steph;
318  int vw2 = (int)(Perm[PSwap].m/(double)NGridw);//(int)(Sequence[PSwap]/(double)NGridw);
319  int vh2 = Perm[PSwap].m%NGridh;//Sequence[PSwap]%NGridh;
320  int w2 = vw2*Stepw;
321  int h2 = vh2*Steph;
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];
331  }
332  }
333  }
334  }
335  return 1;
336 }
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);
340  //memcpy(OutPicture,Picture,4*width*height);
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;
351  //printf("%d %d -> %d %d / %d %d, %d %d -> %d %d / %d %d\n",wi,hi,wo,ho,width,height,vw,vh,vvw,vvh,Stepw,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];
356  }
357  }
358  }
359  free(Sequence);
360  return 1;
361 }
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++){
369  int wi = wo + bwi;
370  int hi = ho + bhi;
371  ColAverage += (double)Picture[(hi*ImWidth+wi)*NLevel+l];
372  }
373  }
374  ColAverage /= (double)(Blockw*Blockh);
375  for(int bwi=0;bwi<Blockw;bwi++){
376  for(int bhi=0;bhi<Blockh;bhi++){
377  int wi = wo + bwi;
378  int hi = ho + bhi;
379  OutPicture[(hi*ImWidth+wi)*NLevel+l] = (unsigned char) ColAverage;
380  }
381  }
382  }
383  }
384  }
385  return 1;
386 }
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);
392  int NOrder = 3+1;
393  double *dArray = (double *)calloc(ImWidth+NOrder+1,sizeof(double));
394  for(int p=0;p<=ImWidth+NOrder;p++){
395  if(p<NOrder){
396  dArray[p] = 0;
397  }
398  else if( (NOrder<=p) && (p<=ImWidth) ){
399  dArray[p] = (p-NOrder+1)*DeltaIn;//Pm[p-NOrder].Pos[CLat1];//
400  }
401  else if( p>ImWidth){
402  dArray[p] = (p-NOrder+2)*DeltaIn;
403  }
404  }
405 // for(int vo=0;vo<ImWidth;vo++){
406 // for(int vvo=0;vvo<ImHeight;vvo++){
407 // PlOut[vo][vvo] = 0.;
408 // double x = DeltaOut*vo;
409 // //for(int vi=0;vi<NIn;vi++){
410 // for(int vi=vo-1;vi<vo+NOrder+1;vi++){
411 // if(vi < 0 || vi >= ImWidth) continue;
412 // double Blendx = Blend(dArray,x,vi,NOrder);
413 // double y = DeltaOut*vvo;
414 // //for(int vvi=0;vvi<NIn;vvi++){
415 // for(int vvi=vvo-1;vvi<vvo+NOrder+1;vvi++){
416 // if(vvi < 0 || vvi >= ImWidth) continue;
417 // double Blendy = Mat->Blend(dArray,y,vvi,NOrder);
418 // PlOut[vo][vvo] += Blendx*Blendy * PlIn[vi][vvi];
419 // }
420 // }
421 // }
422 // }
423  for(int l=0;l<NLevel;l++){
424  for(int w=0;w<ImWidth;w++){
425  for(int h=0;h<ImHeight;h++){
426  int ho = h*Times;
427  int wo = w*Times;
428  if(w>0 && h>0)
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]);
444  }
445  }
446  }
447  return 1;
448 }
449 int DrEffect::Noise(unsigned char *Picture,unsigned char *OutPicture,int width,int height){
450  int NMaskh = 3;
451  int NMaskw = 3;
452  double Mask[3][3];
453  //unsigned char * raster = (unsigned char *) malloc(sizeof(unsigned char) * width * height * 4);
454  double Det = 1./9.;
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;
458  Det = 1./10.;
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;
462  Det = 1./16.;
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;
466  //Gaussian
467  // Det = 1./249.;
468  // 3 6 8 6 3
469  // 6 14 19 14 6
470  // 8 19 25 19 8
471  // 6 14 19 14 6
472  // 3 6 8 6 3
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);
481  }
482  }
483  }
484  }
485  }
486  return 1;
487 }
488 
489 int DrEffect::Edges(unsigned char *Picture,unsigned char *OutPicture,int width,int height){
490  int NMaskh = 3;
491  int NMaskw = 3;
492  //unsigned char *raster = (unsigned char *)malloc(width*height*NLevel*sizeof(unsigned char));
493  double Mask[3][3];
494  double Det = 1./4.;
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;
498  //Gradiente per riga
499  for(int l=0;l<NLevel;l++)
500  {
501  //int l=2;
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;
505  double Temp=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));
513  //OutPicture[(h*width+w)*NLevel +l] += (unsigned char)(ASS((Mask[lh][lw]*Picture[((h+lh-1)*width+(w+lw-1))*NLevel +l]*Det)));
514  }
515  }
516  OutPicture[(h*width+w)*NLevel +l] += (unsigned char) Temp;
517  }
518  }
519  }
520  //Gradiente per colonna
521  for(int l=0;l<NLevel;l++)
522  {
523  //int l=2;
524  for(int h=0;h<height-NMaskh; h++) {
525  for(int w=0;w<width-NMaskw; w++) {
526  double Temp=0.;
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;
533  //OutPicture[(h*width+w)*NLevel +l] += (unsigned char)(ASS((Mask[lw][lh]*Picture[((h+lh-1)*width+(w+lw-1))*NLevel +l]*Det)));
534  Temp += ASS((Mask[lw][lh]*Picture[((h+lh-1)*width+(w+lw-1))*NLevel +l]*Det));
535  }
536  }
537  OutPicture[(h*width+w)*NLevel +l] += (unsigned char) Temp;
538  }
539  }
540  }
541  return 1;
542 }
543 void DrEffect::DrEkeyboard(unsigned char key){
544  switch (key){
545  case 'a':
546  glutPostRedisplay();
547  break;
548  case 'b':
549  glutPostRedisplay();
550  break;
551  case 'c':
552  glutPostRedisplay();
553  break;
554  case 'd':
555  glutPostRedisplay();
556  break;
557  case 'e':
558  glutPostRedisplay();
559  break;
560  case 27:
561  exit(0);
562  break;
563  case 40:
564  break;
565  default:
566  break;
567  }
568  keyboardDraw(key);
569 }
570 
571 #endif// __glut_h__
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.
Definition: DrOpenGL.cpp:15
void EffectCoarseGrain(int Grana)
Defocus the images in blocks.
Definition: DrOpenGL.cpp:94
int WritePngwriter()
Write a png file of the data in pixel (uses libpngwriter)
Definition: DrawFile.cpp:277
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.
Definition: DrawFile.cpp:183
void EffectMotion()
Shifting of pixels.
Definition: DrOpenGL.cpp:197
void keyboardDraw(unsigned char key)
Combines the key with the functions.
int ImWidth
Width and height of the image.
Definition: Draw.h:153
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.
Definition: DrOpenGL.cpp:68
double Val(int row)
Returns a value in 1d.
void Initialize()
Definition: DrDefinition.cpp:3
void EffectFilter()
Applies a filter to pixel.
Definition: DrOpenGL.cpp:168
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&#39;s name.
Definition: Draw.h:244
int ApplyFilter(Matrice *Point, Matrice *Res, Matrice *Mask)
Applies the filter.
void EffectIncrease()
Increase the resolution.
Definition: DrOpenGL.cpp:54
Implementation of useful algorythms.
Definition: Matematica.h:76
double a0
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
Coefficient of a spline.
int WritePixel()
Boh.
Definition: DrawFile.cpp:186
int NLevel
Levels of the images data (usually 4=RGBA)
Definition: Draw.h:256
void Print()
Print the entries.
GLubyte * pixel
Principal image (always allocated)
Definition: Draw.h:270