Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #define MAXXLAT 1228800
  5.  
  6. void pix(int frame, int alen, int achannels, short *abuf, double *fbuf,
  7.   int ww, int wh, int bpp, int *mbuf, unsigned char *dst, unsigned char *src,
  8.   unsigned char *buf2, unsigned char *buf3)
  9. {
  10. int i, o, o1, x, y, x1, y1, dx=bpp, dy=bpp*ww;
  11. int ww2=ww/2, wh2=wh/2;
  12. struct xlatr{
  13.   signed short xlatx;
  14.   signed short xlaty;
  15. }xlattable[MAXXLAT];
  16. float fx,fy,fr=0.0;
  17.  
  18. if(frame < 1)
  19. {
  20.   printf("\npix: generating %i,%i transform map...",ww,wh);
  21.   for(y=0; y<wh; y++) { //printf("%d ",y);
  22.    for(x=0; x<ww; x++) {
  23.    fx=(float)(x-ww2);
  24.    fy=(float)(y-wh2);
  25.    fr=0.43*sqrt(fx*fx+fy*fy);
  26.      o=x+y*ww;  // o is an index to the destination
  27.      //xlattable[o].xlatx = (int)((ww2-fx-fr*sin(fy))+ww2)/64;
  28.      xlattable[o].xlatx = (int)((-ww2-fx-fr*cos(fy/16))+ww2)/57;
  29.      xlattable[o].xlaty = (int)((-wh2-fy-fr*sin(fx/16))+wh2)/69;
  30.    }
  31.  }
  32.  printf("done\n");
  33. }
  34. // apply pixel translation with wrapping (toroidal) and fade out colors
  35. int odest, array_size;
  36. o=0; array_size=ww*wh;
  37. for(y=0; y<wh; y++) { for(x=0; x<ww; x++) {
  38.     o=(x+y*ww);  // o is an index to the destination array (4 packed bytes for rgb)
  39.     odest=o+(xlattable[o].xlatx+ww*xlattable[o].xlaty);  
  40.          if (odest < 0) {
  41.              odest=(array_size-1)-((-odest-1)%array_size);
  42.          }
  43.          else {
  44.              odest=odest%array_size;
  45.          }
  46.     for(i=2;i>=0;i--) {
  47.       //copy xlated r,g,b src to dst and subtract a bit
  48.       if(src[i+odest*4]<3) dst[i+o*4]=0; else dst[i+o*4]=src[i+odest*4]-3;
  49.     }
  50. } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement