⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deskjet.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 2 页
字号:




#include "d:\cips\cips.h"

#define EIGHT  '\010'
#define ESCAPE 27
#define SIXTYFOUR 64
#define ONEHUNDRED 100
#define FORMFEED  '\014'

short image1[ROWS][COLS];
short image2[ROWS][COLS];
short r[200];

char patterns[64][8] =
   { {255, 255, 255, 255, 255, 255, 255, 255},
     {255, 255, 255, 255, 255, 255, 255, 127},
     {255, 255, 255, 255, 255, 255, 255,  63},
     {255, 255, 255, 255, 255, 255, 255,  31},
     {255, 255, 255, 255, 255, 255, 255,  15},
     {255, 255, 255, 255, 255, 255, 255,   7},
     {255, 255, 255, 255, 255, 255, 255,   3},
     {255, 255, 255, 255, 255, 255, 255,   1},
     {255, 255, 255, 255, 255, 255, 255,   0},
     {255, 255, 255, 255, 255, 255, 127,   0},
     {255, 255, 255, 255, 255, 255,  63,   0},
     {255, 255, 255, 255, 255, 255,  31,   0},
     {255, 255, 255, 255, 255, 255,  15,   0},
     {255, 255, 255, 255, 255, 255,   7,   0},
     {255, 255, 255, 255, 255, 255,   3,   0},
     {255, 255, 255, 255, 255, 255,   1,   0},
     {255, 255, 255, 255, 255, 255,   0,   0},
     {255, 255, 255, 255, 255, 127,   0,   0},
     {255, 255, 255, 255, 255,  63,   0,   0},
     {255, 255, 255, 255, 255,  31,   0,   0},
     {255, 255, 255, 255, 255,  15,   0,   0},
     {255, 255, 255, 255, 255,   7,   0,   0},
     {255, 255, 255, 255, 255,   3,   0,   0},
     {255, 255, 255, 255, 255,   1,   0,   0},
     {255, 255, 255, 255, 255,   0,   0,   0},
     {255, 255, 255, 255, 127,   0,   0,   0},
     {255, 255, 255, 255,  63,   0,   0,   0},
     {255, 255, 255, 255,  31,   0,   0,   0},
     {255, 255, 255, 255,  15,   0,   0,   0},
     {255, 255, 255, 255,   7,   0,   0,   0},
     {255, 255, 255, 255,   3,   0,   0,   0},
     {255, 255, 255, 255,   1,   0,   0,   0},
     {255, 255, 255, 255,   0,   0,   0,   0},
     {255, 255, 255, 127,   0,   0,   0,   0},
     {255, 255, 255,  63,   0,   0,   0,   0},
     {255, 255, 255,  31,   0,   0,   0,   0},
     {255, 255, 255,  15,   0,   0,   0,   0},
     {255, 255, 255,   7,   0,   0,   0,   0},
     {255, 255, 255,   3,   0,   0,   0,   0},
     {255, 255, 255,   1,   0,   0,   0,   0},
     {255, 255, 255,   0,   0,   0,   0,   0},
     {255, 255, 127,   0,   0,   0,   0,   0},
     {255, 255,  63,   0,   0,   0,   0,   0},
     {255, 255,  31,   0,   0,   0,   0,   0},
     {255, 255,  15,   0,   0,   0,   0,   0},
     {255, 255,   7,   0,   0,   0,   0,   0},
     {255, 255,   3,   0,   0,   0,   0,   0},
     {255, 255,   1,   0,   0,   0,   0,   0},
     {255, 255,   0,   0,   0,   0,   0,   0},
     {255, 127,   0,   0,   0,   0,   0,   0},
     {255,  63,   0,   0,   0,   0,   0,   0},
     {255,  31,   0,   0,   0,   0,   0,   0},
     {255,  15,   0,   0,   0,   0,   0,   0},
     {255,   7,   0,   0,   0,   0,   0,   0},
     {255,   3,   0,   0,   0,   0,   0,   0},
     {255,   1,   0,   0,   0,   0,   0,   0},
     {255,   0,   0,   0,   0,   0,   0,   0},
     {127,   0,   0,   0,   0,   0,   0,   0},
     { 63,   0,   0,   0,   0,   0,   0,   0},
     { 31,   0,   0,   0,   0,   0,   0,   0},
     { 15,   0,   0,   0,   0,   0,   0,   0},
     {  7,   0,   0,   0,   0,   0,   0,   0},
     {  3,   0,   0,   0,   0,   0,   0,   0},
     {  1,   0,   0,   0,   0,   0,   0,   0}};





main()
{
   char caption[80],
        c[80],
        d[80],
        image_name[80],
        page[80],
        type[80];

   FILE *printer;

   int	i,
	invert,
        j,
        channel,
        il,
        ie,
        ll,
        le;

   unsigned long histogram[256], final_hist[256];

   printer = fopen("prn", "w");

      /************************************************
      *
      *   Print the page number and a few blank lines.
      *
      *************************************************/

   select_proportional_font(printer);

   printf("\n\nEnter page number ---\b\b\b");
   gets(page);

   strcpy(image_name, "                                           ");
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);

   my_fwrite(printer, image_name);
   my_fwrite(printer, image_name);

   sprintf(image_name,
     "                                                            %s", page);
   my_fwriteln(printer, image_name);

   strcpy(image_name, "      ");
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);

      /***************************************************
      *
      *   Get the following information:
      *      . image name
      *      . image parameters
      *      . size of image
      *      . type of image
      *
      ***************************************************/

   strcpy(image_name, "d:/pix/philips.tif");
   get_image_name(image_name);
   channel = 1;
   il =   1;
   ie =   1;
   ll = 100;
   le = 100;
   invert = 1;
   get_parameters(&il, &ie, &ll, &le);

   printf("\nEnter invert (1=on 0=off) -\b");
   get_integer(&invert);

   printf("\n\nEnter the caption for the figure\n->");
   gets(caption);

   printf("\n\nPrint    a) 100x200     b) 200x200\n->");
   gets(d);

   printf("\n\nPrint    a) original image    b) result image\n->");
   gets(type);


      /*****************************************************
      *
      *   Read in two image arrays and calculate histogram.
      *
      ******************************************************/

   printf("\nReading image");
   read_tiff_image(image_name, image1, il, ie, ll, le);
   ie = ie + 100;
   le = le + 100;

   printf("\nReading image");
   read_tiff_image(image_name, image2, il, ie, ll, le);

   if(invert == 1){
      for(i=0; i<ROWS; i++){
	 for(j=0; j<COLS; j++){
	    image1[i][j] = 255 - image1[i][j];
	    image2[i][j] = 255 - image2[i][j];
	 }
      }
   }

   zero_long_histogram(histogram);
   zero_long_histogram(final_hist);

   calculate_long_histogram(image1, histogram);
   printf("\nCalculated histogram");
   calculate_long_histogram(image2, histogram);
   printf("\nCalculated histogram");

        /**************************************************
        *
        *    If you are printing a result image then do not
        *    do histogram equalization.
        *
        *    If this is an orginal image then you have a
        *    choice of using histogram equalization before
        *    printing or using a straight transform.
        *
        ***************************************************/

   if( (type[0] == 'a') || (type[0] == 'A')){
      printf("\n\nDo you want to perform histogram equalization?(y/n) ");
      gets(c);
      if( (c[0] == 'y')         ||
          (c[0] == 'Y')){
         printf("\nPerforming histogram equalization");
         perform_histogram_equalization(image1, histogram);
         printf("\nPerforming histogram equalization");
         perform_histogram_equalization(image2, histogram);
      }  /* ends yes do histogram equalization */

      else{  /* no equalization so reduce
                gray levels from 256 to 64 */
         for(i=0; i<ROWS; i++){
            for(j=0; j<COLS; j++){
               image1[i][j] = image1[i][j]/4;
               image2[i][j] = image2[i][j]/4;
            }
         }
      }   /* ends else */

   }  /* ends if original image type */

   calculate_long_histogram(image1, final_hist);
   calculate_long_histogram(image2, final_hist);



        /**************************************************
        *
        *   Now set the graphics mode on the printer
        *   and print the image rows.
        *
        ***************************************************/

   printf("\nBegin");
   end_graphics_mode(printer);
   select_300_dpi_resolution(printer);
   set_raster_width(printer);
   start_raster_graphics(printer);
   select_full_graphics_mode(printer);



   for(i=0; i<100; i++){
      for(j=0; j<100; j++){
         r[j]          = image1[i][j];
         r[j+100] = image2[i][j];
      }  /* ends loop over j */

      end_graphics_mode(printer);
      select_300_dpi_resolution(printer);
      set_raster_width(printer);
      start_raster_graphics(printer);
      select_full_graphics_mode(printer);

      if( (type[0] == 'a') || (type[0] == 'A'))
         print_original_100_row(printer, r);
      else
         print_result_100_row(printer, r);

      printf("\n\tPrinting row %d", i);
   }  /* ends loop over i */

           /* ends first half */



      /*****************************************************
      *
      *   If you selected a 200x200 printout then repeat
      *   the above steps for 2 more 100x100 arrays
      *
      ******************************************************/

   if( (d[0] == 'b')   ||
       (d[0] == 'B')){

      ie = ie - 100;
      le = le - 100;
      il = il + 100;
      ll = ll + 100;


      printf("\nReading image");
      read_tiff_image(image_name, image1, il, ie, ll, le);
      ie = ie + 100;
      le = le + 100;

      printf("\nReading image");
      read_tiff_image(image_name, image2, il, ie, ll, le);

         /***********************************************
         *
         *   If printing a result image do not perform
         *   histogram equalization.
         *
         ***********************************************/

      if( (type[0] == 'a') || (type[0] == 'A')){
         if( (c[0] == 'y')   ||
             (c[0] == 'Y')){
            printf("\nPerforming histogram equalization");
            perform_histogram_equalization(image1, histogram);
            printf("\nPerforming histogram equalization");
            perform_histogram_equalization(image2, histogram);
         }  /* ends yes do histogram equalization */

         else{        /* no equalization so reduce
                gray levels from 256 to 64 */
            for(i=0; i<ROWS; i++){
               for(j=0; j<COLS; j++){
                  image1[i][j] = image1[i][j]/4;
                  image2[i][j] = image2[i][j]/4;
               }
            }
         }   /* ends else */
      }  /* ends if original image type */

      calculate_long_histogram(image1, final_hist);
      calculate_long_histogram(image2, final_hist);

      printf("\nBegin");
      end_graphics_mode(printer);
      select_300_dpi_resolution(printer);
      set_raster_width(printer);
      start_raster_graphics(printer);
      select_full_graphics_mode(printer);



      for(i=0; i<100; i++){
         for(j=0; j<100; j++){
            r[j]     = image1[i][j];
            r[j+100] = image2[i][j];
         }  /* ends loop over j */

         end_graphics_mode(printer);
         select_300_dpi_resolution(printer);
         set_raster_width(printer);
         start_raster_graphics(printer);
         select_full_graphics_mode(printer);

         if( (type[0] == 'a') || (type[0] == 'A'))
            print_original_100_row(printer, r);
         else
            print_result_100_row(printer, r);

         printf("\n\tPrinting row %d", i);
      }  /* ends loop over i */


   }  /* ends if d == b */


      /* a couple of blank lines before the histogram */
   end_graphics_mode(printer);
   select_proportional_font(printer);
   strcpy(image_name, "      ");
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);

   select_300_dpi_resolution(printer);
   set_raster_width(printer);
   start_raster_graphics(printer);
   select_full_graphics_mode(printer);
   print_hist_image(printer, final_hist);

   end_graphics_mode(printer);
   select_proportional_font(printer);
   strcpy(image_name, "      ");
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);
   my_fwriteln(printer, image_name);

   sprintf(image_name, "                      %s", caption);
   my_fwriteln(printer, image_name);

   putc(FORMFEED, printer);

   printf("\nEnd");
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -