Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
bmpio.c File Reference
#include <string.h>
#include "allheaders.h"
#include "pix_internal.h"
#include "bmp.h"

Go to the source code of this file.

Macros

#define DEBUG   0
 

Functions

PIXpixReadStreamBmp (FILE *fp)
 
PIXpixReadMemBmp (const l_uint8 *cdata, size_t size)
 
l_ok pixWriteStreamBmp (FILE *fp, PIX *pix)
 
l_ok pixWriteMemBmp (l_uint8 **pfdata, size_t *pfsize, PIX *pixs)
 

Variables

RGBA_QUAD bwmap [2] = { {255,255,255,255}, {0,0,0,255} }
 
static const l_int32 L_MAX_ALLOWED_WIDTH = 1000000
 
static const l_int32 L_MAX_ALLOWED_HEIGHT = 1000000
 
static const l_int64 L_MAX_ALLOWED_PIXELS = 400000000LL
 
static const l_int32 L_MAX_ALLOWED_RES = 10000000
 

Detailed Description


     Read bmp
          PIX          *pixReadStreamBmp()
          PIX          *pixReadMemBmp()

     Write bmp
          l_int32       pixWriteStreamBmp()
          l_int32       pixWriteMemBmp()

Definition in file bmpio.c.

Macro Definition Documentation

◆ DEBUG

#define DEBUG   0

Definition at line 68 of file bmpio.c.

Function Documentation

◆ pixReadMemBmp()

PIX * pixReadMemBmp ( const l_uint8 * cdata,
size_t size )

pixReadMemBmp()

Parameters
[in]cdatabmp data
[in]sizenumber of bytes of bmp-formatted data
Returns
pix, or NULL on error
Notes:
     (1) The BMP file is organized as follows:
         * 14 byte fileheader
         * Variable size infoheader: 40, 108 or 124 bytes.
           We only use data in he first 40 bytes.
         * Optional colormap, with size 4 * ncolors (in bytes)
         * Image data
     (2) 2 bpp bmp files are not valid in the original spec, but they
         are valid in later versions.
     (3) We support reading rgb files with bpp = 24 and rgba files
         with 32 bpp.  For the latter, the transparency component of
         the generated pix is saved; however, for rgba images with
         non-opaque transparent components, png provides more flexibility.

Definition at line 132 of file bmpio.c.

References PixColormap::array, BMP_FileHeader::bfOffBits, BMP_FileHeader::bfType, BMP_InfoHeader::biBitCount, BMP_InfoHeader::biCompression, BMP_InfoHeader::biHeight, BMP_InfoHeader::biSizeImage, BMP_InfoHeader::biWidth, BMP_InfoHeader::biXPelsPerMeter, BMP_InfoHeader::biYPelsPerMeter, BMP_FHBYTES, BMP_ID, BMP_IHBYTES, COLOR_BLUE, COLOR_GREEN, COLOR_RED, L_ALPHA_CHANNEL, PixColormap::n, and REMOVE_CMAP_BASED_ON_SRC.

Referenced by pixReadStreamBmp().

◆ pixReadStreamBmp()

PIX * pixReadStreamBmp ( FILE * fp)

pixReadStreamBmp()

Parameters
[in]fpfile stream opened for read
Returns
pix, or NULL on error
Notes:
     (1) Here are references on the bmp file format:
         http://en.wikipedia.org/wiki/BMP_file_format
         http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Definition at line 88 of file bmpio.c.

References pixReadMemBmp().

◆ pixWriteMemBmp()

l_ok pixWriteMemBmp ( l_uint8 ** pfdata,
size_t * pfsize,
PIX * pixs )

pixWriteMemBmp()

Parameters
[out]pfdatadata of bmp formatted image
[out]pfsizesize of returned data
[in]pixs1, 2, 4, 8, 16, 32 bpp
Returns
0 if OK, 1 on error
Notes:
     (1) 2 bpp bmp files are not valid in the original spec, and are
         written as 8 bpp.
     (2) pix with depth <= 8 bpp are written with a colormap.
         16 bpp gray and 32 bpp rgb pix are written without a colormap.
     (3) The transparency component in an rgba (spp = 4) pix is written.
     (4) The bmp colormap entries, RGBA_QUAD, are the same as
         the ones used for colormaps in leptonica.  This allows
         a simple memcpy for bmp output.

Definition at line 455 of file bmpio.c.

References RGBA_Quad::alpha, PixColormap::array, BMP_FileHeader::bfOffBits, BMP_FileHeader::bfSize, BMP_FileHeader::bfType, BMP_InfoHeader::biBitCount, BMP_InfoHeader::biClrImportant, BMP_InfoHeader::biClrUsed, BMP_InfoHeader::biCompression, BMP_InfoHeader::biHeight, BMP_InfoHeader::biPlanes, BMP_InfoHeader::biSize, BMP_InfoHeader::biSizeImage, BMP_InfoHeader::biWidth, BMP_InfoHeader::biXPelsPerMeter, BMP_InfoHeader::biYPelsPerMeter, RGBA_Quad::blue, BMP_FHBYTES, BMP_ID, BMP_IHBYTES, COLOR_BLUE, COLOR_GREEN, COLOR_RED, RGBA_Quad::green, L_ALPHA_CHANNEL, and RGBA_Quad::red.

Referenced by pixWriteStreamBmp().

◆ pixWriteStreamBmp()

l_ok pixWriteStreamBmp ( FILE * fp,
PIX * pix )

pixWriteStreamBmp()

Parameters
[in]fpfile stream
[in]pixall depths
Returns
0 if OK, 1 on error

Definition at line 410 of file bmpio.c.

References pixWriteMemBmp().

Variable Documentation

◆ bwmap

RGBA_QUAD bwmap[2] = { {255,255,255,255}, {0,0,0,255} }

Definition at line 59 of file bmpio.c.

◆ L_MAX_ALLOWED_HEIGHT

const l_int32 L_MAX_ALLOWED_HEIGHT = 1000000
static

Definition at line 63 of file bmpio.c.

◆ L_MAX_ALLOWED_PIXELS

const l_int64 L_MAX_ALLOWED_PIXELS = 400000000LL
static

Definition at line 64 of file bmpio.c.

◆ L_MAX_ALLOWED_RES

const l_int32 L_MAX_ALLOWED_RES = 10000000
static

Definition at line 65 of file bmpio.c.

◆ L_MAX_ALLOWED_WIDTH

const l_int32 L_MAX_ALLOWED_WIDTH = 1000000
static

Definition at line 62 of file bmpio.c.