Harlequin RIP SDK

This file implements a TIFF writer for the LE product, using Sam Leffler's libtiff for output. Some attempt is made to re-map channels onto well-supported TIFF modes, but the support for more esoteric TIFF options is poor at best, so files generated may not load in viewers. More...

#include "hhrsdk.h"
#include "skintest.h"
#include "debugpage.h"
#include "rmreport.h"
#include "hvdreport.h"
#include "libtiffrast.h"
#include <string.h>
#include "tiffio.h"

Data Structures

struct  LIBTIFF_RASTER_handle
 Holds all of the state required to output a page of raster with libtiff. More...
 
struct  ImageResource
 Image resource structure for use in Photoshop tag. More...
 
struct  DisplayInfo
 DisplayInfo structure used in Image resource 0x3ff. More...
 

Macros

#define LIBTIFF_FILEFORMAT   "%f-%p%?-N%?-S%?-T.tif"
 The default file name format for files produced by the libtiff output back end.
 
#define LIBTIFF_ELEMENT_FILEFORMAT   "%i%?-N%?-S%?-03r.tif"
 The file name format for all eHVD element output files produced by the libtiff output back end. More...
 
#define INKSET_INKNAMES   2
 

Typedefs

typedef struct LIBTIFF_RASTER_handle LIBTIFF_RASTER_handle
 Holds all of the state required to output a page of raster with libtiff. More...
 
typedef struct ImageResource ImageResource
 Image resource structure for use in Photoshop tag.
 
typedef struct DisplayInfo DisplayInfo
 DisplayInfo structure used in Image resource 0x3ff. More...
 

Functions

static tmsize_t libtiff_read (thandle_t thandle, tdata_t data, tmsize_t size)
 Adapts reading functionality from the Core Device Interface to the libtiff interface.
 
static tmsize_t libtiff_write (thandle_t thandle, tdata_t data, tmsize_t size)
 Adapts writing functionality from the Core Device Interface to the libtiff interface.
 
static toff_t libtiff_seek (thandle_t thandle, toff_t where, int whence)
 Adapts seeking functionality from the Core Device Interface to the libtiff interface.
 
static int libtiff_close (thandle_t thandle)
 Adapts closing functionality from the Core Device Interface to the libtiff interface. More...
 
static toff_t libtiff_size (thandle_t thandle)
 Adapts the size query function from the Core Device Interface to the libtiff interface.
 
static int32 mapChannels (const char *channelnames[], uint32 nchannelnames, LIBTIFF_RASTER_handle *handle, RasterDescription *rd)
 Check mapping of RIP channels to TIFF channels. More...
 
static int32 mapIdentity (LIBTIFF_RASTER_handle *handle, RasterDescription *rd)
 Map RIP channels directly to TIFF channels.
 
static HqBool flushScanlines (LIBTIFF_RASTER_handle *handle)
 Flush any data buffered before writing a whole strip at a time.
 
static HqBool writeScratchLines (LIBTIFF_RASTER_handle *handle, RasterDescription *rd, int32 topline, int32 limitline, int32 channel, uint8 polarity)
 Write strips or scanlines from the scratch buffer, with the selected polarity, optimising re-use of compressed strip data if possible.
 
static HqBool writeBackgroundForUnmappedChannels (LIBTIFF_RASTER_handle *handle, RasterDescription *rd, uint8 polarity)
 Writes data for every TIFF output channel that doesn't have a corresponding channel in the raster generated by the RIP. More...
 
static void setupImageResource (ImageResource *ir, uint16 id, size_t length)
 Set up an Image Resource header.
 
static HqBool setupScratchStrip (LIBTIFF_RASTER_handle *handle, RasterDescription *rd, int32 nBitsPerSample, int32 nchannels)
 Set up a scratch strip buffer for use by channel shuffling, expansion, inversion, TrimPage and unmapped channels.
 
static HqBool setupIFD (LIBTIFF_RASTER_handle *handle, RasterDescription *rd)
 Set up an IFD (image file directory) for TIFF. This is a separate function, so that multiple TIFFWriteDirectory calls can be made for frame-interleaved output. After each call, setupIFD() will be called for the next frame. More...
 
RASTER_result LIBTIFF_COMMON_RASTER_start (void *pJobContext, uint8 *filename, RasterDescription *rd, RASTER_handle *handlep, HqBool compress, HqBool fAllowExpandNTo8, HqBool fPhotoshopFriendly, HVD_monitor *monitor)
 
static HVD_result libtiff_hvd_output_page (HVD_page_output *page)
 Callback function for libHVD to output an HVD page. More...
 

Detailed Description

This file implements a TIFF writer for the LE product, using Sam Leffler's libtiff for output. Some attempt is made to re-map channels onto well-supported TIFF modes, but the support for more esoteric TIFF options is poor at best, so files generated may not load in viewers.

The TIFF writer supports the following parameters for configuration:

CompressionType
This string controls how the raster data should be compressed within the TIFF file. Its value should one of: (Flate), (LZW), (PackBits), (CCITT4), or (None). The default is (LZW).
ExpandTo8Bit
If this boolean is true the TIFF file is written using 8 bits per pixel, but only if it is screened to 1, 2, or 4 bits per pixel in the RIP and is composite color. It is not applied for separations or for mono output. This can be useful during development, as many TIFF viewers cannot display 2- or 4-bit rasters, or 1-bit composite color. The default is true.
PhotoshopFriendly
If this boolean is true a Photoshop tag is written to the TIFF file when outputting spot color channels, which defines the colors and names of the extra channels. In addition, the data of the spot color channels is inverted for CMYK TIFFs. This is for display purposes in Photoshop.
NOTE: The actual raster data in the spot color channels is inverted, so sending a TIFF file produced with this option to a printer will not produce the same output as a TIFF file made when PhotoshopFriendly is false. We anticipate that PhotoshopFriendly is of most value for rapidly previewing the RIP output during development and test, rather than for production use. The default is false.
Predictor
This string controls whether a predictor is used in conjunction with LZW compression. Its value should one of: (None), (Horizontal), or (Auto). The default is not to use a predictor.
CompressionLevel
This integer controls the level Flate compression. The value should be in the range 1-9, or -1 to use the default level of compression. The default is -1.

The value of DEMOTIFF is supported for PageBufferType and -o for backwards compatibility. Its use is deprecated. It uses the LIBTIFF raster backend, but CompressionType defaults to (None) and ExpandTo8Bit defaults to false.

Similarly the value of LIBTIFFPS is supported for PageBufferType and -o for backwards compatibility. Its use is deprecated. It uses the LIBTIFF raster backend, but PhotoshopFriendly defaults to true.

Macro Definition Documentation

◆ INKSET_INKNAMES

#define INKSET_INKNAMES   2

tiff.h doesn't define this

◆ LIBTIFF_ELEMENT_FILEFORMAT

#define LIBTIFF_ELEMENT_FILEFORMAT   "%i%?-N%?-S%?-03r.tif"

The file name format for all eHVD element output files produced by the libtiff output back end.

This file name format cannot be overridden from the command line.

Typedef Documentation

◆ DisplayInfo

typedef struct DisplayInfo DisplayInfo

DisplayInfo structure used in Image resource 0x3ff.

See Appendix A of Photoshop API Guide.pdf

◆ LIBTIFF_RASTER_handle

Holds all of the state required to output a page of raster with libtiff.

An instance of this structure is created by LIBTIFF_RASTER_start(), and then passed back as an opaque RASTER_handle pointer. It is subsequently passed back into each LIBTIFF_RASTER_write_data() call, and finally to LIBTIFF_RASTER_finish(). Both of those functions cast the opaque pointer back to LIBTIFF_RASTER_handle, and LIBTIFF_RASTER_finish() will end by freeing the structure. In a multi-page job, no state is remembered between pages. The output of each page is a completely separate activity, implemented as a separate set of calls to the libtiff library.

Like most raster handling functions, the libtiff back-end makes use of the Core RIP Device Interface (see swdevice.h), so that the bytes of output data can be sent to any destination. The DEVICELIST and DEVICE_FILEDESCRIPTOR members refer to the output destination.

Function Documentation

◆ libtiff_close()

static int libtiff_close ( thandle_t  thandle)
static

Adapts closing functionality from the Core Device Interface to the libtiff interface.

Nothing is actually done by this function, because the output device file descriptor is actually closed by LIBTIFF_RASTER_finish().

◆ LIBTIFF_COMMON_RASTER_start()

RASTER_result LIBTIFF_COMMON_RASTER_start ( void *  pJobContext,
uint8 filename,
RasterDescription rd,
RASTER_handle handlep,
HqBool  compress,
HqBool  fAllowExpandNTo8,
HqBool  fPhotoshopFriendly,
struct HVD_monitor hvdMonitor 
)

Common raster start function called from LIBTIFF, LIBTIFFPS, DEMOTIFF, FRAMETIFF, and ASYNCTIFF.

◆ libtiff_hvd_output_page()

static HVD_result libtiff_hvd_output_page ( HVD_page_output page)
static

Callback function for libHVD to output an HVD page.

Parameters
[in]pageThe output page description from libHVD.
Return values
HVD_SUCCESSThe page was output successfully
Returns
One of the HVD_ERROR_* error codes, or any other return value greater than MON_CLASS_ERROR is an error UID. HVD_ERROR_* codes should be translated to monitor UID errors using HVD_result_translate(). The error subclass, PS error type, and UID for the error can be deconstructed using the macros in monevent.h.

◆ mapChannels()

static int32 mapChannels ( const char *  channelnames[],
uint32  nchannelnames,
LIBTIFF_RASTER_handle handle,
RasterDescription rd 
)
static

Check mapping of RIP channels to TIFF channels.

Contone CMYK and RGB device spaces are mapped to multiple colorants, but keeping CMYK/RGB in the first 4/3 channels of the TIFF, to make viewing easy. Other channels are mapped to Extrasamples. This routine sets up a channel map and the Extrasamples array in the raster handle, and returns the total number of channels required. It also sets the "shuffle" field in the raster handle, which indicates if pixels need shuffling.

◆ setupIFD()

static HqBool setupIFD ( LIBTIFF_RASTER_handle handle,
RasterDescription rd 
)
static

Set up an IFD (image file directory) for TIFF. This is a separate function, so that multiple TIFFWriteDirectory calls can be made for frame-interleaved output. After each call, setupIFD() will be called for the next frame.

< tiff.h doesn't define this

< tiff.h doesn't define this

< tiff.h doesn't define this

< tiff.h doesn't define this

< tiff.h doesn't define this

◆ writeBackgroundForUnmappedChannels()

static HqBool writeBackgroundForUnmappedChannels ( LIBTIFF_RASTER_handle handle,
RasterDescription rd,
uint8  polarity 
)
static

Writes data for every TIFF output channel that doesn't have a corresponding channel in the raster generated by the RIP.

Called from setupIFD() for frame-interleaved and band-interleaved cases.

Parameters
handleThe TIFF output descriptor.
rdThe RIP's raster descriptor.
polarityThe data to write in the unmapped channels (0 or 0xff)
Returns
TRUE if the function succeeds, otherwise FALSE.