Advertisement
Guest User

ch1.c

a guest
Mar 27th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.67 KB | None | 0 0
  1. /*
  2.  
  3. ch1.c
  4.  
  5. Parameters: none
  6.  
  7. Create a 12-zone test chart with the following stripe widths (in pixels) per zone:
  8.  
  9.     10   8   9  11
  10.  
  11.      6   4   5   7
  12.  
  13.     14  12  13  16
  14.  
  15. Compile with:
  16.  
  17.     cc -o ch1 ch1.c
  18.  
  19.  
  20. The 1800x1800-pixel output file, named "chart1.gray", should then be converted using
  21. ImageMagick's "convert" command-line utility from the ".gray" bytestream format to
  22. a more standard image format like bmp:
  23.  
  24.     convert -size 1800x1800 -depth 8 chart1.gray chart1.bmp
  25.  
  26. ImageMagick can be downloaded from: http://www.imagemagick.org/
  27.  
  28. */
  29.  
  30. #include <unistd.h>
  31. #include <fcntl.h>
  32. #include <stdlib.h>
  33.  
  34. int main() {
  35.     unsigned char
  36.         *buf, *ptr, *ptr2;
  37.     int i, j, fd;
  38.  
  39.     //ptr2 = ptr = buf = calloc( 648 * 600, 1 );
  40.     buf = calloc( 1800 * 1800, 1 );
  41.  
  42.     ptr2 = buf + 1800 * 800;
  43.     ptr = ptr2 + 260;
  44.  
  45. // 6
  46.     for( i = 0; i < 13; i++ ) {
  47.         for( j = 0; j < 6; j++ )
  48.             *ptr++ = 255;
  49.         ptr += 6;
  50.     }
  51.     for( j = 0; j < 6; j++ )
  52.         *ptr++ = 255;
  53.  
  54. // 4
  55.     for( i = 0; i < 20; i++ ) {
  56.         ptr += 4;
  57.         for( j = 0; j < 4; j++ )
  58.             *ptr++ = 255;
  59.     }
  60.  
  61. // 5
  62.     for( i = 0; i < 16; i++ ) {
  63.         ptr += 5;
  64.         for( j = 0; j < 5; j++ )
  65.             *ptr++ = 255;
  66.     }
  67.  
  68. // 7
  69.     for( i = 0; i < 11; i++ ) {
  70.         ptr += 7;
  71.         for( j = 0; j < 7; j++ )
  72.             *ptr++ = 255;
  73.     }
  74.  
  75.     ptr = ptr2 + 1800;
  76.     for( i = 0; i < 199; i++ ) {
  77.         for( j = 0; j < 1800; j++ )
  78.             *ptr++ = *ptr2++;
  79.     }
  80.  
  81.     ptr2 = buf + 1800 * 600;
  82.     ptr = ptr2 + 260;
  83.  
  84. // 10
  85.     for( i = 0; i < 8; i++ ) {
  86.         for( j = 0; j < 10; j++ )
  87.             *ptr++ = 255;
  88.         ptr += 10;
  89.     }
  90.  
  91. // 8
  92.     for( i = 0; i < 10; i++ ) {
  93.         for( j = 0; j < 8; j++ )
  94.             *ptr++ = 255;
  95.         ptr += 8;
  96.     }
  97.  
  98. // 9
  99.     for( i = 0; i < 9; i++ ) {
  100.         for( j = 0; j < 9; j++ )
  101.             *ptr++ = 255;
  102.         ptr += 9;
  103.     }
  104.  
  105. // 11
  106.     for( i = 0; i < 7; i++ ) {
  107.         for( j = 0; j < 11; j++ )
  108.             *ptr++ = 255;
  109.         ptr += 11;
  110.     }
  111.     for( j = 0; j < 11; j++ )
  112.         *ptr++ = 255;
  113.  
  114.     ptr = ptr2 + 1800;
  115.     for( i = 0; i < 199; i++ ) {
  116.         for( j = 0; j < 1800; j++ )
  117.             *ptr++ = *ptr2++;
  118.     }
  119.  
  120.     ptr2 = buf + 1800 * 1000;
  121.     ptr = ptr2 + 260;
  122.  
  123. // 14
  124.     for( i = 0; i < 5; i++ ) {
  125.         for( j = 0; j < 14; j++ )
  126.             *ptr++ = 255;
  127.         ptr += 14;
  128.     }
  129.     for( j = 0; j < 14; j++ )
  130.         *ptr++ = 255;
  131.  
  132. // 12
  133.     for( i = 0; i < 7; i++ ) {
  134.         ptr += 12;
  135.         for( j = 0; j < 12; j++ )
  136.             *ptr++ = 255;
  137.     }
  138.  
  139. // 13
  140.     for( i = 0; i < 6; i++ ) {
  141.         ptr += 13;
  142.         for( j = 0; j < 13; j++ )
  143.             *ptr++ = 255;
  144.     }
  145.  
  146. // 16
  147.     for( i = 0; i < 5; i++ ) {
  148.         ptr += 16;
  149.         for( j = 0; j < 16; j++ )
  150.             *ptr++ = 255;
  151.     }
  152.  
  153.     ptr = ptr2 + 1800;
  154.     for( i = 0; i < 199; i++ ) {
  155.         for( j = 0; j < 1800; j++ )
  156.             *ptr++ = *ptr2++;
  157.     }
  158.  
  159.     fd = open( "chart1.gray", O_WRONLY | O_CREAT | O_TRUNC, 0600 );
  160.     write( fd, buf, 1800 * 1800 );
  161.     close( fd );
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement