[cups.development] How to find out end of file in raster format

Michael Sweet msweet at apple.com
Sun Dec 6 12:35:50 PST 2009


On Dec 5, 2009, at 11:32 PM, solomon wrote:
> 
> Hi,
> 
> I am developing a filter for my custom printer, i am developing based on rastertoepson filter. i want to know one thing how to find out when do we reach end of file of the printable file.

When cupsRasterReadHeader/cupsRasterReadHeader2 returns 0, you have reached the end-of-file (or detected a bad raster header/corrupt file).  There will never be any additional data at the end of a properly formed CUPS raster stream.

> suppose in main before entering in to print data we are checking for end of file using while statement as shown below:
> while (cupsRasterReadHeader2(ras, &header))
> 
> this loop will execute up to end of file. but if my page is longer than end of file(printable file) i want to quit the printing may be as shown below

You need to call cupsRasterReadPixels for each line in the page.  Thus the normal print loop looks something like this:

    /* Read all pages in the raster stream */
    while (cupsRasterReadHeader(ras, &header))
    {
      /* Allocate memory for reading pixels */
      unsigned char *buffer = malloc(header.cupsBytesPerLine);

      /* Read all of the lines on the current page */
      for (y = 0; y < header.cupsHeight; y ++)
        if (cupsRasterReadPixels(ras, buffer, header.cupsBytesPerLine))
        {
          /* Output the line to the printer */
          ...
        }
        else
          break;
    }


___________________________________________________
Michael Sweet, Senior Printing System Engineer







More information about the cups-devel mailing list