Файл src/writefile.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"

Классы

struct  ExtensionMap

Макросы

#define L_BUF_SIZE   512

Функции

l_int32 pixaWriteFiles (const char *rootname, PIXA *pixa, l_int32 format)
l_int32 pixWrite (const char *filename, PIX *pix, l_int32 format)
l_int32 pixWriteStream (FILE *fp, PIX *pix, l_int32 format)
l_int32 pixWriteImpliedFormat (const char *filename, PIX *pix, l_int32 quality, l_int32 progressive)
l_int32 pixChooseOutputFormat (PIX *pix)
l_int32 getImpliedFileFormat (const char *filename)
const char * getFormatExtension (l_int32 format)
l_int32 pixWriteMem (l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 format)
l_int32 pixDisplay (PIX *pixs, l_int32 x, l_int32 y)
l_int32 pixDisplayWithTitle (PIX *pixs, l_int32 x, l_int32 y, const char *title, l_int32 dispflag)
l_int32 pixDisplayWrite (PIX *pixs, l_int32 reduction)
l_int32 pixDisplayWriteFormat (PIX *pixs, l_int32 reduction, l_int32 format)
l_int32 pixSaveTiled (PIX *pixs, PIXA *pixa, l_int32 reduction, l_int32 newrow, l_int32 space, l_int32 dp)

Переменные

static const l_int32 MAX_DISPLAY_WIDTH = 1000
static const l_int32 MAX_DISPLAY_HEIGHT = 800
static const l_int32 MAX_SIZE_FOR_PNG = 200
static const l_float32 DEFAULT_SCALING = 1.0
static const l_int32 NUM_EXTENSIONS = 14
const char * ImageFileFormatExtensions []
static struct ExtensionMap extension_map []

Макросы

#define L_BUF_SIZE   512


Функции

const char* getFormatExtension ( l_int32  format  ) 

getFormatExtension()

Input: format (integer) Return: extension (string), or null if format is out of range

Notes: (1) This string is NOT owned by the caller; it is just a pointer to a global string. Do not free it.

l_int32 getImpliedFileFormat ( const char *  filename  ) 

getImpliedFileFormat()

Input: filename Return: output format, or IFF_UNKNOWN on error or invalid extension.

Notes: (1) This determines the output file format from the extension of the input filename.

l_int32 pixaWriteFiles ( const char *  rootname,
PIXA pixa,
l_int32  format 
)

pixaWriteFiles()

Input: rootname pixa format (defined in imageio.h) Return: 0 if OK; 1 on error

l_int32 pixChooseOutputFormat ( PIX pix  ) 

pixChooseOutputFormat()

Input: pix Return: output format, or 0 on error

Notes: (1) This should only be called if the requested format is IFF_DEFAULT. (2) If the pix wasn't read from a file, its input format value will be IFF_UNKNOWN, and in that case it is written out in a compressed but lossless format.

l_int32 pixDisplay ( PIX pixs,
l_int32  x,
l_int32  y 
)

pixDisplay()

Input: pix (1, 2, 4, 8, 16, 32 bpp) x, y (location of xv frame) Return: 0 if OK; 1 on error

Notes: (1) This uses xv to display. It must be on your $PATH variable. (2) Because xv reduces images to fit the screen, we do this reduction in advance, and write it out to a temporary file in the current directory with the name "junk_xv_display.*" (3) This function uses a static internal variable to number output files written by a single process. Behavior with a shared library may be unpredictable.

l_int32 pixDisplayWithTitle ( PIX pixs,
l_int32  x,
l_int32  y,
const char *  title,
l_int32  dispflag 
)

pixDisplayWithTitle()

Input: pix (1, 2, 4, 8, 16, 32 bpp) x, y (location of xv frame) title (<optional> on xv window; can be NULL); dispflag (0 to disable; 1 to write) Return: 0 if OK; 1 on error

Notes: (1) See notes for pixDisplay(). (2) This displays the image if dispflag == 1.

l_int32 pixDisplayWrite ( PIX pixs,
l_int32  reduction 
)

pixDisplayWrite()

Input: pix (1, 2, 4, 8, 16, 32 bpp) reduction (-1 to reset/erase; 0 to disable; otherwise this is a reduction factor) Return: 0 if OK; 1 on error

Notes: (1) This defaults to jpeg output for pix that are 32 bpp or 8 bpp without a colormap. If you want to write all images losslessly, use format == IFF_PNG in pixDisplayWriteFormat(). (2) See pixDisplayWriteFormat() for usage details.

l_int32 pixDisplayWriteFormat ( PIX pixs,
l_int32  reduction,
l_int32  format 
)

pixDisplayWriteFormat()

Input: pix (1, 2, 4, 8, 16, 32 bpp) reduction (-1 to reset/erase; 0 to disable; otherwise this is a reduction factor) format (IFF_PNG or IFF_JFIF_JPEG) Return: 0 if OK; 1 on error

Notes: (1) This writes files if reduction > 0. These can be displayed, ordered in a tiled representation, with, for example, gthumb. (2) All previously written files can be erased by calling with reduction < 0; the value of pixs is ignored. (3) If reduction > 1 and depth == 1, this does a scale-to-gray reduction. (4) This function uses a static internal variable to number output files written by a single process. Behavior with a shared library may be unpredictable. (5) Output file format is as follows: format == IFF_JFIF_JPEG: png if d < 8 or d == 16 or if the output pix has a colormap. Otherwise, output is jpg. format == IFF_PNG: png (lossless) on all images. (6) For 16 bpp, the choice of full dynamic range with log scale is the best for displaying these images. Alternative outputs are pix8 = pixMaxDynamicRange(pixt, L_LINEAR_SCALE); pix8 = pixConvert16To8(pixt, 0); // low order byte pix8 = pixConvert16To8(pixt, 1); // high order byte

l_int32 pixSaveTiled ( PIX pixs,
PIXA pixa,
l_int32  reduction,
l_int32  newrow,
l_int32  space,
l_int32  dp 
)

pixSaveTiled()

Input: pixs (1, 2, 4, 8, 32 bpp) pixa (the pix are accumulated here) reduction (0 to disable; otherwise this is a reduction factor) newrow (0 if placed on the same row as previous; 1 otherwise) space (horizontal and vertical spacing, in pixels) dp (depth of pixa; 8 or 32 bpp; only used on first call) Return: 0 if OK, 1 on error.

Notes: (1) Before calling this function for the first time, use pixaCreate() to make the that will accumulate the pix. This is passed in each time pixSaveTiled() is called. (2) is the integer reduction factor for the input image. After reduction and possible depth conversion, the image is saved in the input pixa, along with a box that specifies the location to place it when tiled later. Disable saving the pix by setting reduction == 0. (3) and specify the location of the new pix with respect to the last one(s) that were entered. (4) specifies the depth at which all pix are saved. It can be only 8 or 32 bpp. Any colormap is removed. This is only used at the first invocation. (5) This function uses two variables from call to call. If they were static, the function would not be .so or thread safe, and furthermore, there would be interference with two or more pixa accumulating images at a time. Consequently, we use the first pix in the pixa to store and obtain both the depth and the current position of the bottom (one pixel below the lowest image raster line when laid out using the boxa). The bottom variable is stored in the input format field, which is the only field available for storing an int.

l_int32 pixWrite ( const char *  filename,
PIX pix,
l_int32  format 
)

pixWrite()

Input: filename pix format (defined in imageio.h) Return: 0 if OK; 1 on error

Notes: (1) Open for write using binary mode (with the "b" flag) to avoid having Windows automatically translate the NL into CRLF, which corrupts image files. On non-windows systems this flag should be ignored, per ISO C90. Thanks to Dave Bryan for pointing this out.

l_int32 pixWriteImpliedFormat ( const char *  filename,
PIX pix,
l_int32  quality,
l_int32  progressive 
)

pixWriteImpliedFormat()

Input: filename pix quality (iff JPEG; 1 - 100, 0 for default) progressive (iff JPEG; 0 for baseline seq., 1 for progressive) Return: 0 if OK; 1 on error

Notes: (1) This determines the output format from the filename extension. (2) The last two args are ignored except for requests for jpeg files. (3) The jpeg default quality is 75.

l_int32 pixWriteMem ( l_uint8 **  pdata,
size_t *  psize,
PIX pix,
l_int32  format 
)

pixWriteMem()

Input: &data (<return> data of tiff compressed image) &size (<return> size of returned data) pix format (defined in imageio.h) Return: 0 if OK, 1 on error

Notes: (1) On windows, this will only write tiff and PostScript to memory. For other formats, it requires open_memstream(3). (2) PostScript output is uncompressed, in hex ascii. Most printers support level 2 compression (tiff_g4 for 1 bpp, jpeg for 8 and 32 bpp).

l_int32 pixWriteStream ( FILE *  fp,
PIX pix,
l_int32  format 
)

pixWriteStream()

Input: stream pix format Return: 0 if OK; 1 on error.


Переменные

const l_float32 DEFAULT_SCALING = 1.0 [static]

struct ExtensionMap extension_map[] [static]

Инициализатор

 
                            { { ".bmp",  IFF_BMP       },    
                              { ".jpg",  IFF_JFIF_JPEG },    
                              { ".jpeg", IFF_JFIF_JPEG },    
                              { ".png",  IFF_PNG       },    
                              { ".tif",  IFF_TIFF      },    
                              { ".tiff", IFF_TIFF      },    
                              { ".pnm",  IFF_PNM       },    
                              { ".gif",  IFF_GIF       },    
                              { ".ps",   IFF_PS        } }

Инициализатор

 {"unknown",
                                           "bmp",
                                           "jpg",
                                           "png",
                                           "tif",
                                           "tif",
                                           "tif",
                                           "tif",
                                           "tif",
                                           "tif",
                                           "tif",
                                           "pnm",
                                           "ps",
                                           "gif"}

const l_int32 MAX_DISPLAY_HEIGHT = 800 [static]

const l_int32 MAX_DISPLAY_WIDTH = 1000 [static]

const l_int32 MAX_SIZE_FOR_PNG = 200 [static]

const l_int32 NUM_EXTENSIONS = 14 [static]


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:38 2009. Создано системой  doxygen 1.5.9