Advertisement
image28

remove-test.c

Jul 16th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.03 KB | None | 0 0
  1. /* creates pallete from first frame, zeros all colours in palette from first frame */
  2. // after this works extend the palette buffer to a few frames
  3. // then make palette functions for editor, select frames, genorate palette
  4. // comparison of pixels, and actions( subtract, add, set to x colour )
  5.  
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <sys/mman.h>
  10. #include <string.h>
  11. #include "record.h"
  12.  
  13. #define  checkpoint printf("checkpoint\n");
  14. //#define  WIDTH 640
  15. //#define  HEIGHT 480
  16. //#define  VARIATION 2
  17. //#define FRAMES 10
  18. //#define CORRECTION 4
  19.  
  20. static char     *map;
  21.  
  22.  
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.     int done = 0;
  27.     FILE *video;
  28.     char file[40];
  29.     char *background;
  30.     int x,y,z;
  31.     int match=0;
  32.  
  33.     if (argv[1] == NULL) { argv[1] = "output"; } // if no file, try open file named output
  34.     if ((video=fopen(argv[1],"r")) == NULL)  printf("File did not open"); exit; // opens file
  35.     map=malloc(WIDTH*HEIGHT*3); // alloc memory for one frame
  36.     background=malloc((WIDTH*HEIGHT*3)*FRAMES);
  37.  
  38.     checkpoint;
  39.     fseek(video,WIDTH*HEIGHT*3*62,SEEK_SET);
  40.     fread(background, WIDTH*HEIGHT*3*FRAMES, 1, video);
  41.  
  42.     checkpoint;
  43.  
  44.     while ( ! done ) {
  45.     if ( ! feof(video) )
  46.     {
  47.         fread(map, WIDTH*HEIGHT*3, 1, video);
  48.         // remove all colours from palette
  49.         for(x=0; x<WIDTH*HEIGHT*3*FRAMES; x=x+3)
  50.         {
  51.             if (( (int)background[x] > (int)map[x%(WIDTH*HEIGHT*3)]-VARIATION/2 ) && ( (int)background[x] < (int)map[x%(WIDTH*HEIGHT*3)]+VARIATION/2 ))
  52.             {
  53.                 if (( (int)background[x+1] > (int)map[(x+1)%(WIDTH*HEIGHT*3)]-VARIATION/2 ) && ( (int)background[x+1] < (int)map[(x+1)%(WIDTH*HEIGHT*3)]+VARIATION/2 ))
  54.                 {
  55.                     if (( (int)background[x+2] > (int)map[(x+2)%(WIDTH*HEIGHT*3)]-VARIATION/2 ) && ( (int)background[x+2] < (int)map[(x+2)%(WIDTH*HEIGHT*3)]+VARIATION/2 ))
  56.                     {
  57.                         map[(x)%(WIDTH*HEIGHT*3)] = (char)0;
  58.                         map[(x+1)%(WIDTH*HEIGHT*3)] = (char)0;
  59.                         map[(x+2)%(WIDTH*HEIGHT*3)] = (char)255;
  60.                         }
  61.                     }
  62.                 }
  63.         }
  64.  
  65.         for(y=0; y <HEIGHT; y++)
  66.         {
  67.         for(x=0; x <WIDTH; x=x+3)
  68.         {
  69.             if ( ( (int)map[x+(y*WIDTH)] != 0 ) && ( (int)map[x+(y*WIDTH)+1] != 0 ) && ( (int)map[x+(y*WIDTH)+2] != 255 ) )
  70.             {
  71.                 match++;
  72.             }else{
  73.                 if ( match < CORRECTION )
  74.                 {
  75.                     for(z=1; z < CORRECTION; z++)
  76.                     {
  77.                         map[(x+(y*WIDTH))-(z*3)]= (char)0;
  78.                         map[(x+(y*WIDTH)+1)-(z*3)]= (char)0;
  79.                         map[(x+(y*WIDTH)+2)-(z*3)]= (char)255;
  80.                     }
  81.                 }
  82.                 match=0;
  83.             }
  84.  
  85.  
  86.         }
  87.     }
  88.  
  89.     for(x=0; x < WIDTH*3; x=x+3)
  90.     {
  91.             for(y=x; y <HEIGHT*WIDTH*3; y=y+(WIDTH*3))
  92.         {
  93.             if ( ( (int)map[y] != 0 ) && ( (int)map[y+1] != 0 ) && ( (int)map[y+2] != 255 ) )
  94.             {
  95.                 match++;
  96.             }else{
  97.                 if ( match < CORRECTION )
  98.                 {
  99.                     for(z=1; z < CORRECTION; z++)
  100.                     {
  101.                         map[(y)-(z*3)]= (char)0;
  102.                         map[(y+1)-(z*3)]= (char)0;
  103.                         map[(y+2)-(z*3)]= (char)255;
  104.                     }
  105.                 }
  106.                 match=0;
  107.             }
  108.  
  109.  
  110.         }
  111.     }
  112.  
  113.             //checkpoint;
  114.             // write frame to new file
  115.             strcpy(file, argv[1]);
  116.             strcat(file,".edit");
  117.             record(map, file);
  118.         }else{
  119.             done=1;
  120.         }
  121.     }
  122.     fclose(video);
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement