smntc
an in-memory multimodal graph database
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
Bmp.c File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "errors.h"
+ Include dependency graph for Bmp.c:

Go to the source code of this file.

Data Structures

struct  Bmp
 It stores an image in memory. More...
 

Macros

#define RGB_COLOR_LENGTH   3
 
#define FILE_HEADER_LENGTH   14
 
#define INFO_HEADER_LENGTH   40
 
#define PAD_LENGTH   3
 

Functions

struct BmpBmp_destruct (struct Bmp *this)
 It destructs a managing object for one image.
 
unsigned int Bmp_getWidth (struct Bmp *this)
 
unsigned int Bmp_getHeight (struct Bmp *this)
 It supplies the height of an image.
 
unsigned long Bmp_getLength (struct Bmp *this)
 It supplies the number of pixels.
 
void Bmp_getPixelOfRaster (struct Bmp *this, int horizontal, int vertical, unsigned char *red, unsigned char *green, unsigned char *blue, int *error)
 It supplies three colors of a pixel when the horizontal and vertical positions of a raster are provided by the caller.
 
void Bmp_getPixelOfLine (struct Bmp *this, int index, unsigned char *red, unsigned char *green, unsigned char *blue, int *error)
 It supplies three colors of a pixel when the horizontal and vertical positions of a raster are provided by the caller.
 
struct BmpBmp_readFile (const char *filename, int *error)
 It loads an image file with the bmp format into memory.
 
void Bmp_writeFile (struct Bmp *this, const char *filename, int *error)
 It writes an image in a file in bmp format.
 

Macro Definition Documentation

◆ FILE_HEADER_LENGTH

#define FILE_HEADER_LENGTH   14

Definition at line 8 of file Bmp.c.

◆ INFO_HEADER_LENGTH

#define INFO_HEADER_LENGTH   40

Definition at line 9 of file Bmp.c.

◆ PAD_LENGTH

#define PAD_LENGTH   3

Definition at line 10 of file Bmp.c.

◆ RGB_COLOR_LENGTH

#define RGB_COLOR_LENGTH   3

Definition at line 7 of file Bmp.c.

Function Documentation

◆ Bmp_destruct()

struct Bmp * Bmp_destruct ( struct Bmp this)

It destructs a managing object for one image.

Parameters
thisa managing object for one image

Definition at line 22 of file Bmp.c.

◆ Bmp_getHeight()

unsigned int Bmp_getHeight ( struct Bmp this)

It supplies the height of an image.

Parameters
thisa managing object for one image

Definition at line 39 of file Bmp.c.

◆ Bmp_getLength()

unsigned long Bmp_getLength ( struct Bmp this)

It supplies the number of pixels.

It is used to extract individual pixels in a loop.

Returns
the number of pixels in the image.
Parameters
thisa managing object for one image

Definition at line 44 of file Bmp.c.

◆ Bmp_getPixelOfLine()

void Bmp_getPixelOfLine ( struct Bmp this,
int  index,
unsigned char *  red,
unsigned char *  green,
unsigned char *  blue,
int *  error 
)

It supplies three colors of a pixel when the horizontal and vertical positions of a raster are provided by the caller.

Parameters
thisa managing object for one image
indexthe pixel position in a line (0 is top left), it cannot be equal or exceed the length of an image
redred value (from 0 to 255)
greengreen value (from 0 to 255)
blueblue value (from 0 to 255)
errorerror tracking (0 means no error)

Definition at line 58 of file Bmp.c.

◆ Bmp_getPixelOfRaster()

void Bmp_getPixelOfRaster ( struct Bmp this,
int  horizontal,
int  vertical,
unsigned char *  red,
unsigned char *  green,
unsigned char *  blue,
int *  error 
)

It supplies three colors of a pixel when the horizontal and vertical positions of a raster are provided by the caller.

Parameters
thisa managing object for one image
horizontalthe vertical pixel position starting from above (0 is top), it cannot be equal or exceed the image width
verticalthe horizontal position of a pixel counted from the left side of the screen from the point of view of the user (0 is left), it cannot be equal or exceed the image height
redred value (from 0 to 255)
greengreen value (from 0 to 255)
blueblue value (from 0 to 255)
errorerror tracking (0 means no error)

Definition at line 49 of file Bmp.c.

◆ Bmp_getWidth()

unsigned int Bmp_getWidth ( struct Bmp this)
Parameters
thisa managing object for one image

Definition at line 34 of file Bmp.c.

◆ Bmp_readFile()

struct Bmp * Bmp_readFile ( const char *  filename,
int *  error 
)

It loads an image file with the bmp format into memory.

The order is RGBRGBRGB from top left to bottom right, without any padding. The RGBA format with alpha channel for opacity is not supported.

One pixel image reserves 54 bytes for headers. Color space information must not be added to the headers.

> hexdump -C bmps/one_pixel_all_channels_different.bmp
00000000 42 4d 3a 00 00 00 00 00 00 00 36 00 00 00 28 00 |BM:.......6...(.|
00000010 00 00 01 00 00 00 01 00 00 00 01 00 18 00 00 00 |................|
00000020 00 00 04 00 00 00 23 2e 00 00 23 2e 00 00 00 00 |......#...#.....|
00000030 00 00 00 00 00 00 56 34 12 00 |......V4..|
-------- -- -- -- -- -- -- 56 34 12 -- here: blue 56 + green 34 + red 12
Returns
a managing object for one image
Parameters
filenamea path to a file
errorerror tracking (0 means no error)

Definition at line 65 of file Bmp.c.

◆ Bmp_writeFile()

void Bmp_writeFile ( struct Bmp this,
const char *  filename,
int *  error 
)

It writes an image in a file in bmp format.

Parameters
thisa managing object for one image
filenamea path to a file
errorerror tracking (0 means no error)

Definition at line 242 of file Bmp.c.