Skip to content

Commit

Permalink
Add support for gzip'd raster files (Issue michaelrsweet#7).
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Jan 21, 2018
1 parent 986f4c3 commit f83a003
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -58,6 +58,7 @@ specific language governing permissions and limitations under the License.

- Now licensed under the Apache License Version 2.0.
- Fixed support for 16-bit per color files.
- Added support for gzip'd raster files (Issue #7)


## Changes in v1.5 - 2017-03-22
Expand Down
35 changes: 27 additions & 8 deletions RasterDisplay.cxx
Expand Up @@ -3,7 +3,7 @@
//
// CUPS/PWG Raster display widget methods.
//
// Copyright 2002-2015 by Michael R Sweet.
// Copyright 2002-2018 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
Expand Down Expand Up @@ -80,6 +80,7 @@ static void convert_ymc(cups_page_header2_t *header, uchar *line,
uchar *colors, uchar *pixels);
static void convert_ymck(cups_page_header2_t *header, uchar *line,
uchar *colors, uchar *pixels);
static ssize_t raster_cb(gzFile ctx, unsigned char *buffer, size_t length);


//
Expand All @@ -103,6 +104,7 @@ RasterDisplay::RasterDisplay(
memset(&header_, 0, sizeof(header_));
memset(&next_header_, 0, sizeof(next_header_));

fp_ = NULL;
ras_ = NULL;
ras_eof_ = 1;
pixels_ = NULL;
Expand Down Expand Up @@ -148,6 +150,12 @@ RasterDisplay::close_file()
ras_eof_ = 1;
}

if (fp_)
{
gzclose(fp_);
fp_ = NULL;
}

if (pixels_)
{
delete[] pixels_;
Expand Down Expand Up @@ -1057,23 +1065,21 @@ int // O - 1 on success, 0 on failure
RasterDisplay::open_file(
const char *filename) // I - File to open
{
int fd; // File descriptor for stream


// printf("RasterDisplay::open_file(filename=\"%s\")\n", filename);

close_file();

if ((fd = open(filename, O_RDONLY)) < 0)
if ((fp_ = gzopen(filename, "r")) == NULL)
{
fl_alert("Unable to open file: %s", strerror(errno));
return (0);
}

if ((ras_ = cupsRasterOpen(fd, CUPS_RASTER_READ)) == NULL)
if ((ras_ = cupsRasterOpenIO((cups_raster_iocb_t)raster_cb, fp_, CUPS_RASTER_READ)) == NULL)
{
fl_alert("cupsRasterOpen() failed!");
close(fd);
fl_alert("cupsRasterOpenIO() failed.");
gzclose(fp_);
fp_ = NULL;
return (0);
}

Expand Down Expand Up @@ -5599,3 +5605,16 @@ convert_ymck(
}
}
}


/*
* 'raster_cb()' - Read data from a gzFile.
*/

static ssize_t /* O - Bytes read or -1 on error */
raster_cb(gzFile ctx, /* I - File pointer */
unsigned char *buffer, /* I - Buffer */
size_t length) /* I - Bytes to read */
{
return ((ssize_t)gzread(ctx, buffer, (unsigned)length));
}
4 changes: 3 additions & 1 deletion RasterDisplay.h
@@ -1,7 +1,7 @@
//
// CUPS raster file display widget header file.
//
// Copyright 2002-2015 by Michael R Sweet.
// Copyright 2002-2018 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
Expand All @@ -19,6 +19,7 @@
# include <FL/Fl.H>
# include <FL/Fl_Group.H>
# include <FL/Fl_Scrollbar.H>
# include <zlib.h>


//
Expand All @@ -41,6 +42,7 @@ enum
class RasterDisplay : public Fl_Group
{
cups_raster_t *ras_; // Raster stream
gzFile fp_; // File pointer
int ras_eof_; // End of file?
cups_page_header2_t header_, // Page header for current page
next_header_; // Next page header
Expand Down

0 comments on commit f83a003

Please sign in to comment.