#ifndef __ARTWORK_CONVERSION_COPYRIGHT_QISMRASTER_H #define __ARTWORK_CONVERSION_COPYRIGHT_QISMRASTER_H #ifdef __cplusplus #include #include "qismextension.h" #ifndef RASTER_LNX_DECLSPEC #ifdef _WIN32 #define RASTER_LNX_DECLSPEC #elif __GNUC__ >= 4 #ifdef RASTER_EXPORTS #define RASTER_LNX_DECLSPEC __attribute__ ((visibility ("default"))) #else #define RASTER_LNX_DECLSPEC #endif #else #define RASTER_LNX_DECLSPEC #endif #endif namespace NsQisMLib { class QisMFile; } namespace NsQisMRaster { /******************************************************************************* QISMRASTER FLAGS ------------------------------------------------------------------------------*/ struct RASTER_LNX_DECLSPEC QisMRasterFlags { /***************************************************************************** Raster Image Output Format ----------------------------------------------------------------------------*/ enum ImageFormat { IFF_BUF=0 /* Do not write the raster image to disk */ ,IFF_TIFF=1 /* Write image to a TIFF file with packbits compression */ ,IFF_BMP=2 /* Write image to a BMP file without compression */ ,IFF_RAW=3 /* Write image to disk as-is with a small header */ /* RAW Format -------------------------------------------------------------- 'L''G''R''A''W''0''0' ---------------------------------------------------------------------------- : 4 bytes : 4 bytes : 8 bytes : bytes --------------------------------------------------------------------------*/ }; }; /******************************************************************************* QISMRASTER ERROR CODES ------------------------------------------------------------------------------*/ struct RASTER_LNX_DECLSPEC QisMRasterError { enum New_object_codes { NOE_INV_NAME = -1 /* Invalid (empty/null) class name */ ,NOE_UNK_NAME = -2 /* Unrecognized class name '' */ }; enum Rasterize_window_codes { RWE_INV_WIN = -1 /* Invalid window extents ,,, */ ,RWE_INIT_ERR = -2 /* Initialization failed, */ ,RWE_DATA_COLLECT = -3 /* Data collection error, */ ,RWE_FORMAT = -4 /* Failed to create [code ] */ ,RWE_PATTERN = -5 /* Failed to rasterize , */ }; enum Rasterize_window_synthesized_codes { RWSE_NO_SYNTH = -1 /* Unable to locate the QisMLayerSynth extension */ ,RWSE_SYNTH_INIT = -2 /* Failed to initialize synthesizer, */ ,RWSE_INV_WIN = -3 /* Invalid window extents ,,, */ ,RWSE_INIT_ERR = -4 /* Initialization failed, */ ,RWSE_INV_SPEC = -5 /* Invalid synthesis spec, */ ,RWSE_FORMAT = -6 /* Failed to create [code ] */ ,RWSE_SYNTHESIS = -7 /* Synthesis error, */ }; enum Rasterize_polygon_set_codes { RPSE_INV_POLYS = -1 /* Invalid (empty or null) polygon set */ ,RPSE_INIT_ERR = -2 /* Initialization failed, */ ,RPSE_INV_WIN = -3 /* Invalid window extents ,,, */ }; enum Create_rasterizer_codes { CRE_INV_FILE = -1 /* Invalid (null) QisMFile handle */ ,CRE_EXPLODER = -2 /* Failed to create exploder, */ }; enum Create_formatter_codes { CFE_OBJALLOC = -1 /* Object allocation failure */ }; enum Write_tiff_codes { WTE_INTERNAL = -1 /*
*/ }; enum Write_bmp_codes { WBE_INTERNAL = -1 /*
*/ }; enum Write_raw_codes { WRE_FOPEN = -1 /*
*/ }; }; /******************************************************************************* Interface to retrive information about a raster image ------------------------------------------------------------------------------*/ class RASTER_LNX_DECLSPEC QisMRasterImage { public: /***************************************************************************** Get data structure name and version ----------------------------------------------------------------------------*/ virtual const char* Object_name() const = 0; /***************************************************************************** Get the name/path assigned to this image ----------------------------------------------------------------------------*/ virtual const char* Image_name() const = 0; /***************************************************************************** Get the address of the memory buffer that holds the raster image ----------------------------------------------------------------------------*/ virtual const unsigned char* Image_buffer() const = 0; /***************************************************************************** Get the size of the raster image buffer in bytes ----------------------------------------------------------------------------*/ virtual long long Image_size_bytes() const = 0; /***************************************************************************** Get the total number of polygons involved in generating this image ----------------------------------------------------------------------------*/ virtual long long Polygon_count() const = 0; /***************************************************************************** Get the total number of polygon vertices involved in generating this image ----------------------------------------------------------------------------*/ virtual long long Vertex_count() const = 0; /***************************************************************************** Get elapsed time for generating this image ----------------------------------------------------------------------------*/ virtual double Rip_time_sec() const = 0; /***************************************************************************** Get the width and height of the image in pixels ----------------------------------------------------------------------------*/ virtual unsigned int Width_px() const = 0; virtual unsigned int Height_px() const = 0; /***************************************************************************** Get the extents of the data (in file units) corresponding to this image ----------------------------------------------------------------------------*/ virtual double Extents_llx() const = 0; virtual double Extents_lly() const = 0; virtual double Extents_urx() const = 0; virtual double Extents_ury() const = 0; /***************************************************************************** Check if the image polarity is inverted (bits representing data are 0) ----------------------------------------------------------------------------*/ virtual bool Inverted() const = 0; /***************************************************************************** Get the dithering value (using 8x8 bayer matrix) ----------------------------------------------------------------------------*/ virtual double Dither() const = 0; /***************************************************************************** Get size of a pixel along X and Y axes in file units ----------------------------------------------------------------------------*/ virtual double Pixelsize_x() const = 0; virtual double Pixelsize_y() const = 0; /***************************************************************************** Get the image resolution along X and Y axes in dots-per-inch ----------------------------------------------------------------------------*/ virtual double DPI_x() const = 0; virtual double DPI_y() const = 0; /***************************************************************************** Check if the image was rasterized from right to left. If so, the minX of the data occurs on the RHS of the raster image ----------------------------------------------------------------------------*/ virtual bool Right_to_left() const = 0; /***************************************************************************** Get all of the information about this image as a pre-formatted string ----------------------------------------------------------------------------*/ virtual const char* Report() const = 0; }; /******************************************************************************* A base-type for data objects relevant to the QisMRaster API ------------------------------------------------------------------------------*/ class RASTER_LNX_DECLSPEC QisMRasterObject { public: /***************************************************************************** All objects of that are of type QisMRasterObject can be deleted using the 'delete' operator ----------------------------------------------------------------------------*/ virtual ~QisMRasterObject() {} /***************************************************************************** Get data structure name and version ----------------------------------------------------------------------------*/ virtual const char* Object_name() const = 0; }; /******************************************************************************* A data structure to specify various rasterization options ------------------------------------------------------------------------------*/ class RASTER_LNX_DECLSPEC QisMRasterParams: public QisMRasterObject { public: /***************************************************************************** Reset the options to default values ----------------------------------------------------------------------------*/ virtual void Reset() = 0; /***************************************************************************** Set/Get image resolution in terms of size of a pixel in file units Default: 1.0 file unit along X and Y ----------------------------------------------------------------------------*/ virtual void Pixelsize(const double xSize, const double ySize) = 0; virtual double Pixelsize_x() const = 0; virtual double Pixelsize_y() const = 0; /***************************************************************************** Set/Get image polarity. If true, data bits in the image are 0 and non-data bits are 1. Default: false ----------------------------------------------------------------------------*/ virtual void Invert(const bool set = true) = 0; virtual bool Invert() const = 0; /***************************************************************************** Set/Get dithering value (0.0 - 1.0) using a 8x8 bayer matrix. Default: 1.0 A value of 1.0 will result in 1 pixel for every single data bit. A value of 0.0 will set all data bits to background ----------------------------------------------------------------------------*/ virtual void Dither(const double value) = 0; virtual double Dither() const = 0; /***************************************************************************** Set/Get the rasterization direction. If true, rasterization occurs from right to left so that the minX of the data is found on the RHS of the image. No change in the Y direction. Default: false ----------------------------------------------------------------------------*/ virtual void Right_to_left(const bool set = true) = 0; virtual bool Right_to_left() const = 0; /***************************************************************************** Set/Get the estimated size of the polygon buffer. As soon as the polygon buffer is full, it is rasterized and flushed before more any polygons are collected. This way, the polygon buffer can be pre-allocated for superior performance. If the bolygon buffer size is 0, each polygon is rasterized as it is received (on-the-fly). This makes the rasterization single threaded and may be suitable for small polygon sets. Default: 50,000,000 vertices ----------------------------------------------------------------------------*/ virtual void Est_polygon_buffer_count(const long long numVertices) = 0; virtual long long Est_polygon_buffer_count() const = 0; /***************************************************************************** Enable/Disable pattern recognition. If enabled, rasterization is optimized for cell references that repeat within the specified window. This could save a lot of computations and therefore speed up the rasterization. Default: Enabled (true) ----------------------------------------------------------------------------*/ virtual void Pattern_recognition(const bool set = true) = 0; virtual bool Pattern_recognition() const = 0; /***************************************************************************** Set/Get the image format (Refer to QisMRasterFlags::ImageFormat) ----------------------------------------------------------------------------*/ virtual void Image_format(const QisMRasterFlags::ImageFormat format) = 0; virtual QisMRasterFlags::ImageFormat Image_format() const = 0; /***************************************************************************** Set/Get the number of threads to be used for rasterization. If thrnum == 0, the optimal number of threads is automatically set based on the number of processors in the system. If thrnum == 1, all polygons are rasterized on-the-fly (no buffering). If thrnum > 1, polygons are collected in a buffer (upto Est_polygon_buffer_count()) before being rasterized. Default: 0 (Auto- compute) ----------------------------------------------------------------------------*/ virtual void Num_threads(const int thrnum) = 0; virtual int Num_threads() const = 0; }; /******************************************************************************* A data structure to store a set of polygons ------------------------------------------------------------------------------*/ class RASTER_LNX_DECLSPEC QisMRasterPolygonSet: public QisMRasterObject { public: /***************************************************************************** Clear the polygon set ----------------------------------------------------------------------------*/ virtual void Reset() = 0; /***************************************************************************** Add a polygon to the set ----------------------------------------------------------------------------*/ virtual bool Add_polygon(const int* xy, const int nv) = 0; /*---------------------------------------------------------------------------- PARAMETERS + xy: An array of xy-coordinate pairs representing the closed polygon. It contains nv xy pairs or nv*2 integers. The co-ordinate values are in database units (DBU). 1 DBU = 1 file unit/grid e.g For a file with units as microns and grid of 1000/um (or 0.001 um), 1 DBU = 1000 + nv: Number of xy pairs. e.g A closed rectangle has nv == 5 (Last point is identical to the first) ------------------------------------------------------------------------------ RETURN + Success: true + Failure: false (Invalid polygon) ------------------------------------------------------------------------------ DETAILS + The polygons are assumed to have the same grid and units as the QisMFile used to initialize the rasterizer *****************************************************************************/ /***************************************************************************** Use this to free up unused memory after all the polygons have been added ----------------------------------------------------------------------------*/ virtual void Consolidate() = 0; /***************************************************************************** Get the number of polygons in the set ----------------------------------------------------------------------------*/ virtual int Count() const = 0; /***************************************************************************** Get the lower-left and upper-right co-ordinates of the extents of the data in this polygon set ----------------------------------------------------------------------------*/ virtual void Data_extents( double& llx, double& lly, double& urx, double& ury ) const = 0; }; /******************************************************************************* Interface to an instance of the rasterizer ------------------------------------------------------------------------------*/ class RASTER_LNX_DECLSPEC QisMRasterizer { public: /***************************************************************************** Get implementation name and version ----------------------------------------------------------------------------*/ virtual const char* Object_name() const = 0; /***************************************************************************** The information (error string and code) corresponding to the last error condition ----------------------------------------------------------------------------*/ virtual const char* Get_last_error_msg() const = 0; virtual int Get_last_error_code() const = 0; /***************************************************************************** Rasterize a single window using polygons belonging to one or more layers for a given cell ----------------------------------------------------------------------------*/ virtual const QisMRasterImage* Rasterize_window( const char* name, const double llx, const double lly, const double urx, const double ury, const QisMRasterParams* params, const char* viewCell, const char* layers ) = 0; /*---------------------------------------------------------------------------- PARAMETERS + name: Name associated with this raster image. It will be used as the base path (directory + filename) if this image is written to disk as TIFF/BMP/RAW + llx, lly, urx, ury: Lower-left and upper-right co-ordinates of the window to be rasterized (in file units) + params: Rasterization options + viewCell: Name of the cell to be rasterized. If NULL/empty, the deepest top cell in the file is used + layers: A string containing comma-separated list of layers or layer:datatypes to be rasterized. If NULL/empty, all layers will be used ------------------------------------------------------------------------------ RETURN + Success: A non-NULL handle to the raster image + Failure: NULL. Call Get_last_error_msg() or Get_last_error_code() for more information about the error ------------------------------------------------------------------------------ ERROR CODES: One of the QisMRasterError::Rasterize_window_codes ------------------------------------------------------------------------------ DETAILS + For multiple windows, use this method in a loop. The image buffer will be automatically adjusted to match the image/window size *****************************************************************************/ /***************************************************************************** Rasterize a single window using polygons created by performing various boolean operation on layers for a given cell ----------------------------------------------------------------------------*/ virtual const QisMRasterImage* Rasterize_window_synthesized( const char* name, const double llx, const double lly, const double urx, const double ury, const QisMRasterParams* params, const char* viewCell, const char* synthSpec ) = 0; /*---------------------------------------------------------------------------- PARAMETERS + name: Name associated with this raster image. It will be used as the base path (directory + filename) if this image is written to disk as TIFF/BMP/RAW + llx, lly, urx, ury: Lower-left and upper-right co-ordinates of the window to be rasterized (in file units) + params: Rasterization options + viewCell: Name of the cell to be rasterized. If NULL/empty, the deepest top cell in the file is used + synthSpec: Specification of boolean operations between layers. Refer to 'LAYER SYNTHESIS SPEC' (below) for details. All target layers will be rasterized ------------------------------------------------------------------------------ RETURN + Success: A non-NULL handle to the raster image + Failure: NULL. Call Get_last_error_msg() or Get_last_error_code() for more information about the error ------------------------------------------------------------------------------ ERROR CODES: One of the QisMRasterError::Rasterize_window_synthesized_codes ------------------------------------------------------------------------------ DETAILS + For multiple windows, use this method in a loop. The image buffer will be automatically adjusted to match the image/window size *****************************************************************************/ /***************************************************************************** Rasterize a pre-computed set of polygons specific to the client application ----------------------------------------------------------------------------*/ virtual const QisMRasterImage* Rasterize_polygon_set( const char* name, const QisMRasterPolygonSet* polygonSet, const QisMRasterParams* params, const double* rasterWindow = 0, const double* offsets = 0, const int nOffsets = 0 ) = 0; /*---------------------------------------------------------------------------- PARAMETERS + name: Name associated with this raster image. It will be used as the base path (directory + filename) if this image is written to disk as TIFF/BMP/RAW + polygonSet: Pre-computed set of polygons to be rasterized + params: Rasterization options + rasterWindow: If not NULL, specify a window into the polygon set to be rasterized. If NULL, the overall extents of the polygon set will be used as the raster window + offsets, nOffsets: If not NULL/empty, specify a set of xy-coordinates at which the specified set of polygons repeat (as a whole). In this case, the polygon set is used as a pattern that repeats at one or more places. The reference origin of this pattern is assumed to be 0,0. If NULL/empty, the specified polygon set is rasterized as-is at their specified co-ordinates ------------------------------------------------------------------------------ RETURN + Success: A non-NULL handle to the raster image + Failure: NULL. Call Get_last_error_msg() or Get_last_error_code() for more information about the error ------------------------------------------------------------------------------ ERROR CODES: One of the QisMRasterError::Rasterize_window_synthesized_codes ------------------------------------------------------------------------------ DETAILS + For multiple windows, use this method in a loop. The image buffer will be automatically adjusted to match the image/window size *****************************************************************************/ }; /******************************************************************************* Interface to an instance of the image formatter ------------------------------------------------------------------------------*/ class RASTER_LNX_DECLSPEC QisMFormatter { public: /***************************************************************************** Get implementation name and version ----------------------------------------------------------------------------*/ virtual const char* Object_name() const = 0; /***************************************************************************** The information (error string and code) corresponding to the last error condition ----------------------------------------------------------------------------*/ virtual const char* Get_last_error_msg() const = 0; virtual int Get_last_error_code() const = 0; /***************************************************************************** Write a raster image to a TIFF file with packbits compression ----------------------------------------------------------------------------*/ virtual bool Write_tiff( const char* filePath, const int pxWidth, const unsigned long long imgSizeBytes, const double dpiX, const double dpiY, unsigned char* buffer, const int numThreads ) = 0; /*---------------------------------------------------------------------------- PARAMETERS + filePath: Path of the file to be created + pxWidth: Width of the image in pixels + imgSizeBytes: Size of the image in bytes + dpiX, dpiY: Image resolution in dots-per-inch + buffer: Address of the memory buffer where the image is held + numThreads: No. threads to be used for formatting the image ------------------------------------------------------------------------------ RETURN + Success: true + Failure: false. Call Get_last_error_msg() or Get_last_error_code() for details ------------------------------------------------------------------------------ ERROR CODES: One of QisMRasterError::Write_tiff_codes *****************************************************************************/ /***************************************************************************** Write a raster image to an uncompressed BMP file ----------------------------------------------------------------------------*/ virtual bool Write_bmp( const char* filePath, const int pxWidth, const unsigned long long imgSizeBytes, const double dpiX, const double dpiY, unsigned char* buffer, const int numThreads ) = 0; /*---------------------------------------------------------------------------- PARAMETERS + filePath: Path of the file to be created + pxWidth: Width of the image in pixels + imgSizeBytes: Size of the image in bytes + dpiX, dpiY: Image resolution in dots-per-inch + buffer: Address of the memory buffer where the image is held + numThreads: No. threads to be used for formatting the image ------------------------------------------------------------------------------ RETURN + Success: true + Failure: false. Call Get_last_error_msg() or Get_last_error_code() for details ------------------------------------------------------------------------------ ERROR CODES: One of QisMRasterError::Write_bmp_codes *****************************************************************************/ /***************************************************************************** Write a raster image to a RAW file (Refer to QisMRasterFlags::ImageFormat for syntax) ----------------------------------------------------------------------------*/ virtual bool Write_raw( const char* filePath, const int pxWidth, const int pxHeight, const unsigned long long imgSizeBytes, unsigned char* buffer ) = 0; /*---------------------------------------------------------------------------- PARAMETERS + filePath: Path of the file to be created + pxWidth, pxHeight: Width, height of the image in pixels + imgSizeBytes: Size of the image in bytes + buffer: Address of the memory buffer where the image is held ------------------------------------------------------------------------------ RETURN + Success: true + Failure: false. Call Get_last_error_msg() or Get_last_error_code() for details ------------------------------------------------------------------------------ ERROR CODES: One of QisMRasterError::Write_raw_codes *****************************************************************************/ }; #define QISMEXTENSION_RASTER "QisMRaster" #define QISMCODE_RASTER 14827 /******************************************************************************* Interface to the QisMRaster Extension for QisMLib ------------------------------------------------------------------------------*/ class RASTER_LNX_DECLSPEC QisMRaster: public NsQisMLib::QisMExtensionAPI { public: /***************************************************************************** The information (error string and code) corresponding to the last error condition ----------------------------------------------------------------------------*/ virtual const char* Get_last_error_msg() const = 0; virtual int Get_last_error_code() const = 0; /***************************************************************************** Create an instance of one of the various data structures of type QisMRasterObject ----------------------------------------------------------------------------*/ virtual QisMRasterObject* New_object(const char* className) = 0; /*---------------------------------------------------------------------------- PARAMETERS + className: Name of the class whose object is to be created. To be used for :- * QisMRasterParams * QisMRasterPolygonSet ------------------------------------------------------------------------------ RETURN + Success: non-NULL handle to the newly created object. It must be casted to the appropriate type using dynamic_cast + Failure: NULL. Call Get_last_error_msg() or Get_last_error_code() for more information about this error ------------------------------------------------------------------------------ ERROR CODES: One of QisMRasterError::New_object_codes ------------------------------------------------------------------------------ DETAILS + Every object created with this method MUST be destroyed using the 'delete' operator to avoid memory leak *****************************************************************************/ /***************************************************************************** Create and destroy an instance of the rasterizer ----------------------------------------------------------------------------*/ virtual QisMRasterizer* Create_rasterizer( NsQisMLib::QisMFile* filedb, const int argC = 0, const char* const* argT = 0, void* const* argV = 0 ) = 0; virtual void Destroy_rasterizer(QisMRasterizer* handle) = 0; /*---------------------------------------------------------------------------- PARAMETERS + filedb: Handle to a QisMFile database obtained from QisMLib::Load_file(..) + argC, argT, argV: Reserved ------------------------------------------------------------------------------ RETURN + Success: non-NULL handle to an instance of the rasterizer + Failure: NULL. Call Get_last_error_msg() or Get_last_error_code() for more information about this error ------------------------------------------------------------------------------ ERROR CODES: One of QisMRaster::Create_rasterizer_codes ------------------------------------------------------------------------------ DETAILS + Every instance of the rasterizer MUST be destroyed using Destroy_rasterizer(..) to avoid memory/resource leak + Each successful call to Create_rasterizer(..) checks out 1 license (QISMCODE_RASTER) which is checked-in during Destroy_rasterizer(..) *****************************************************************************/ /***************************************************************************** Create and destroy an instance of the formatter ----------------------------------------------------------------------------*/ virtual QisMFormatter* Create_formatter() = 0; virtual void Destroy_formatter(QisMFormatter* handle) = 0; /*---------------------------------------------------------------------------- RETURN + Success: non-NULL handle to an instance of the formatter + Failure: NULL. Call Get_last_error_msg() or Get_last_error_code() for more information about this error ------------------------------------------------------------------------------ ERROR CODES: One of QisMRaster::Create_formatter_codes ------------------------------------------------------------------------------ DETAILS + Every instance of the formatter MUST be destroyed using Destroy_formatter(..) to avoid memory/resource leak *****************************************************************************/ }; } #endif #endif /******************************************************************************* LAYER SYNTHESIS SPEC -------------------------------------------------------------------------------- + := [;]* (One or more targets) + := :=[:] [[:]]* (Generate a layer:dttp from operations on one or more layers or layer:dttps) + := '+' (union) or '-' (difference) or '&' (intersection) or '^' (xor) or ',' (aggregation/OR-without-union) or '|' (aggregation/OR-without-union) + All : will be outputted + Any hierarchy if present in the input is flattened Examples: 100:0=2,5:0,7 (aggregate polygons on 2:* 5:0 and 7:* into a new layer 100:0) 100:0=2+5:0+7 (unionize polygons on 2:* 5:0 and 7:* into a new layer 100:0) 100:0=2+5:0-7 (unionize polygons on 2:* 5:0 and then subtract 7:* to create a new layer 100:0) 100:0=2,5:0-7 (aggregate polygons on 2:* 5:0 and then subtract 7:* to create a new layer 100:0) 100:0=2^5 (Compute XOR between 2:* and 5:* as 100:0) 100:0=2&5 (Compute INTERSECTION between 2:* and 5:* as 100:0) 100:0=2+5;200:0=100:0-5;300:0=200^5;400:0=300&5 (Create multiple synthesized layers from multiple operations between layers) *******************************************************************************/