Advertisement
AnonymousNamefag

render.c

Mar 24th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. // Program used to test the output of bitmap.c
  2. // Like bindump.c but more precise.
  3. // License: Michael Warren FSL
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdint.h>
  8. #include <errno.h>
  9.  
  10. int main( int argc, char **argv ){
  11.     FILE *fp;
  12.     int c;
  13.     int i = 0, j = 0;
  14.     if( !(fp = fopen( argv[1], "r" )) ){
  15.         perror( argv[0] );
  16.         exit( errno );
  17.     }
  18.     uint16_t width;
  19.     uint16_t height;
  20.     fread( &width, 2, 1, fp );
  21.     fread( &height, 2, 1, fp );
  22.     int size = width * height;
  23.     while( (c = fgetc( fp )) != EOF ){
  24.         uint8_t b = 0x80;
  25.         while( b ){
  26.             if( b & c ) putchar( '#' );
  27.             else putchar( ' ' );
  28.             b >>= 1;
  29.             if( ++i % width == 0 ) putchar( '\n' );
  30.             if( ++j >= size ) break;
  31.         }
  32.     }
  33.     fclose( fp );
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement