Advertisement
PierrotLL

grayscreenshotlib - main.c

May 13th, 2011
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.     int c, i, byte, filesize;
  9.     char bit, pix;
  10.     unsigned char *light_buffer, *dark_buffer;
  11.     char command[100];
  12.     FILE *file, *output;
  13.    
  14.     if(file = fopen("MOVIE.gsl", "r")) {
  15.         fseek(file, 0, SEEK_END);
  16.         filesize = ftell(file);
  17.         fseek(file, 0, SEEK_SET);
  18.         if(filesize % 2048 == 0) {
  19.             mkdir("tmp", 01777);
  20.             light_buffer = malloc(1024);
  21.             dark_buffer = malloc(1024);
  22.             for(i=0 ; i<filesize/2048 ; i++) {
  23.                 output = fopen("tmp/bmp24", "w+");
  24.                 fread(light_buffer, 1, 1024, file);
  25.                 fread(dark_buffer, 1, 1024, file);
  26.                 for(byte=0 ; byte<1024 ; byte++) {
  27.                     for(bit=0 ; bit<8 ; bit++) {
  28.                         pix = (light_buffer[byte] & (1<<(7-bit)) ? 1 : 0);
  29.                         pix |= (dark_buffer[byte] & (1<<(7-bit)) ? 2 : 0);
  30.                         switch(pix) {
  31.                             case 0:
  32.                                 fprintf(output, "%c%c%c", 255, 255, 255);
  33.                                 break;
  34.                             case 1:
  35.                                 fprintf(output, "%c%c%c", 192, 192, 192);
  36.                                 break;
  37.                             case 2:
  38.                                 fprintf(output, "%c%c%c", 128, 128, 128);
  39.                                 break;
  40.                             case 3:
  41.                                 fprintf(output, "%c%c%c", 0, 0, 0);
  42.                                 break;
  43.                         }
  44.                     }
  45.                 }
  46.                 fclose(output);
  47.                 sprintf(command, "rgb2gif -1 -s 128 64 tmp/bmp24 > tmp/%06i.gif", i);
  48.                 system(command);
  49.                 remove("tmp/bmp24");
  50.             }
  51.                 free(light_buffer);
  52.             free(dark_buffer);
  53.             system("gifasm -A 7 $(find tmp/*.gif) > result.gif");
  54.         } else fprintf(stderr, "Invalid file size.\n");
  55.         fclose(file);
  56.     } else fprintf(stderr, "Can't find \"MOVIE.gsl\".\n");
  57.     return EXIT_SUCCESS;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement