Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Image Processing


May 1991/New Products/Listing 3

Listing 3

/*******************************************************
*  file d:\cips\pi.c
*
*  Purpose - These functions print an image out to the
*      line printer. The parameters in this function
*      are defined differently than in most other CIPS
*      functions. The parameters il, ie, ll, le are
*      coordinates inside the 100x100 image array.
*      The parameters first_line and first_element
*      are coordinates for the entire image file.
*      So, if you want to start printing at row 10
*      and column 10 of the image file you would call:
*         read_tiff_image(name, the_image, 10, 10,
*                         110, 110);
*         print_image(the_image, name, 1, 1, 1, 100, 18,
*                     10, 10);
*      In normal print mode you can only print 17
*      columns: le - ie = 17.
*
*  External Calls: fwrite.c -  my_frwiteln

*                              my_fwrite
*                  rstring.c - read_string
*                              long_clear_buffer
********************************************************/

#include "d:\cips\cips.h"
#define FORMFEED '\014'

print_image(the_image, name, channel, il, ie, ll, le,
          first_line, first_element)
   char  name[];
   int   channel, il, ie, ll, le, first_line, first_element;
   short the_image[ROWS] [COLS];
{
   char printer_name[MAX_NAME_LENGTH);
   FILE *printer;

   strcpy(printer_name, "prn");
   if( (printer = fopen(printer_name, "w")) == NULL)
      printf("\nPI> Could not open printer");
   else{
      printf("\nPI> The print file is opened");
     /********************************************
     *   If your printer has some form of
     *   condensed printing, you can send those
     *   commands via software using the fputc
     *   function. For example, if your printer
     *   needs to sequence X Y Z to start
     *   condensed printing, insert the following
     *   three calls right here:
     *   fputc('X', printer);
     *   putc('Y', printer);
     *   fputc('Z', printer);
     *********************************************/
      perform_printing(printer, the_image, name, channel,
                    il, ll, ie, le, first_line, first_element);
      fclose(printer);
   }  /* ends else print */
}     /* ends print_image */

perform_printing(printer, the_image, name, channel,
              il, ll, ie, le, first_line, first_element)
   char  name[];
   FILE  *printer;
   int        channel, il, ie, ll, le, first_line, first_element;
   short the_image[ROWS][COLS];
{
   char output[300],
       response[80],
       string [300];
   int  i,
       j,
       k,
       line_counter;

   printf("\nPI> Print header");
   line_counter = 0;
   long_clear_buffer(string);
   sprintf(string,"      This image is -- %s --", name);
   my_fwriteln(printer, string);
   ++ line_counter;

   long_clear_buffer(string);
   sprintf(string," The parameters are:");
   my_fwriteln(printer,string);
   ++ line_counter;

   long_clear_buffer(string);
   sprintf(string,"       channel=%d il=%d ll=%d ie=%d le=%d",
          channel, first_line, first_line+ll-2,
          first_element, first_element+le-2);
   my_fwriteln(printer, string);
   ++line_counter;
   long_clear_buffer(string);
   sprintf (string, " ");
   my_fwriteln(printer, string);
   ++line_counter;

   print_column_header(&line_counter, first_element, ie, le,
                    output, string, printer);

   for(i=il; i<ll; i++){
      long_clear_buffer(string);
   /* now print the image */
      sprintf(string," ");
      long_clear_buffer(output);
      sprintf(output, "%3d-", i+first_line-1);
      append_string(output, string);
      for(j=ie; j<le; j++){
         long_clear_buffer(output);
         sprintf(output,"%4d", the_image [i] [j] );
         append_string(output, string);
      }  /* ends loop over j columns */

      my_fwriteln(printer, string);
      line_counter = line_counter + 1;
      if(line_counter >= 53){
         line_counter = 0;
         putc(FORMFEED, printer);
         print_column_header(&line_counter, first_element, ie,
                          le, output, string, printer);
      }  /* ends if line_counter >=65*/
   }  /* ends loop over i rows */

   for(i=line_counter; i<66; i++){
      long_clear_buffer(string);
      sprintf(string, " ");
      my_fwriteln(printer, string);
   }
}      /* ends perform_printing */
print_column_header(line_counter, first_element, ie, le, output,
                 string, printer)
   char string[], output[];
   FILE *printer;
   int first_element, ie, le, *line_counter;
{
   int k;

   long_clear_buffer(string);
   sprintf(string,"          ",);

   for(k=first_element; k<(first_element + (le-ie)); k++){
      long_clear_buffer(output);
      sprintf(output, "-%3d", k);
      append_string(output, string);
   }  /* ends loop over k */
   my_fwriteln(printer, string);
   *line_counter = *line_counter + 1;

}  /* ends print_column_header  */

/**********************************************
*  print_image_array(...
*  This function prints a 100x100 image array. ***********************************************/
print_image_array(the_image)
   short the_image[ROWS] [COLS];
{
   char response [80];
   printf("\nPIA> Enter a comment line\n--");
   clear_buffer(response);
   read_string(response);
                          /*      il  ie  ll    le     */
   print_image(the_image, response, 0,  1,  1, 100,  17, 0, 0);
   print_image(the_image, response, 0,  1, 18, 100,  35, 0, 0);
   print_image(the_image, response, 0,  1, 36, 100,  53, 0, 0);
   print_image(the_image, response, 0,  1, 54, 100,  71, 0, 0);
   print_image(the_image, response, 0,  1, 72, 100,  89, 0, 0);
   print_image(the_image, response, 0,  1, 90, 100, 100, 0, 0);
}  /* ends print_image_array */

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.