JWS C Library
C language utility library
imgblock.c File Reference

Definitions for an image block and associated functions. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include <inttypes.h>
#include <math.h>
#include <assert.h>
#include "jwsc/base/error.h"
#include "jwsc/matblock/matblock.h"
#include "jwsc/image/image.h"
#include "jwsc/imgblock/imgblock.h"
Include dependency graph for imgblock.c:

Go to the source code of this file.

Functions

create_imgblock

Creates an image block.

void create_imgblock_f (Imgblock_f **img_out, uint32_t num_imgs, uint32_t num_rows, uint32_t num_cols)
 Creates a single precision floating point image block.
create_init_imgblock

Creates and initializes an image block.

void create_init_imgblock_f (Imgblock_f **img_out, uint32_t num_imgs, uint32_t num_rows, uint32_t num_cols, Pixel_f val)
 Creates and initializes a single precision floating point image block.
create_zero_imgblock

Creates an image block and initializes it with zeros.

void create_zero_imgblock_f (Imgblock_f **img_out, uint32_t num_imgs, uint32_t num_rows, uint32_t num_cols)
 Creates a single precision floating point image block and initializes it with zeros.
create_random_imgblock_f

Creates an image block initializes it with random values.

void create_random_imgblock_f (Imgblock_f **img_out, uint32_t num_imgs, uint32_t num_rows, uint32_t num_cols, Pixel_f min, Pixel_f max)
 Creates a single precision floating point image block and initializes it with random values.
create_imgblock_from_matblocks

Creates an image block from three matrix blocks.

Errorcreate_imgblock_from_matblocks_f (Imgblock_f **img_out, const Matblock_f *m_r, const Matblock_f *m_g, const Matblock_f *m_b)
 Creates a single precision floating point image block from three matrix blocks.
create_imgblock_from_matblock

Creates a grayscale image block from a matrix block.

void create_imgblock_from_matblock_f (Imgblock_f **img_out, const Matblock_f *m)
 Creates a single precision floating point grayscale image block from a matrix block.
create_matblocks_from_imgblock

Creates three matrix blocks from an image block.

void create_matblocks_from_imgblock_f (Matblock_f **m_r_out, Matblock_f **m_g_out, Matblock_f **m_b_out, const Imgblock_f *img)
 Creates three single precision floating point matrix blocks from an image block.
create_matblock_from_imgblock

Creates an averaged matrix block from an image block.

void create_matblock_from_imgblock_f (Matblock_f **m_out, const Imgblock_f *img, float r_weight, float g_weight, float b_weight)
 Creates an averaged single precision floating point matrix block from an image block.
copy_imgblock

Copies an image block.

void copy_imgblock_f (Imgblock_f **img_out, const Imgblock_f *img_in)
 Copies a single precision floating point image block.
copy_image_into_imgblock

Copies an image into a imgblock.

Errorcopy_image_into_imgblock_f (Imgblock_f **ib_out, const Imgblock_f *ib_in, const Image_f *i, Imgblock_image orient, uint32_t index)
 Copies a single precision floating point image into an image block.
copy_image_from_imgblock

Copies an image from an imgblock.

Errorcopy_image_from_imgblock_f (Image_f **img_out, const Imgblock_f *img_blk, Imgblock_image orient, uint32_t index)
 Copies a single precision floating point image from and image block.
free_imgblock

Frees an image block.

void free_imgblock_f (Imgblock_f *img)
 Frees a single precision floatin point image block.

Detailed Description

Definitions for an image block and associated functions.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

The image holds single precision floating point pixel elements.

Although the image is indexed by image, row, and column, the pixels are allocated as a 1D array in row-major order. So iterating over the pixels can be done inside a single loop.

Definition in file imgblock.c.


Function Documentation

void create_imgblock_f ( Imgblock_f **  img_out,
uint32_t  num_imgs,
uint32_t  num_rows,
uint32_t  num_cols 
)

Creates a single precision floating point image block.

Parameters:
img_outResult parameter. If *img_out is NULL, an image block is allocated; otherwise its space is re-used.
num_imgsNumber of images in the image block.
num_rowsNumber of rows in the image block.
num_colsNumber of columns in the image block.
Note:
Dimensions must be > 0.

Definition at line 86 of file imgblock.c.

void create_init_imgblock_f ( Imgblock_f **  img_out,
uint32_t  num_imgs,
uint32_t  num_rows,
uint32_t  num_cols,
Pixel_f  val 
)

Creates and initializes a single precision floating point image block.

Parameters:
img_outResult parameter. If *img_out is NULL, an image block is allocated; otherwise its space is re-used.
num_imgsNumber of images in the image block.
num_rowsNumber of rows in the image block.
num_colsNumber of columns in the image block.
valPixel value to initialize all pixels of the image block with.
Note:
Dimensions must be > 0.

Definition at line 165 of file imgblock.c.

void create_zero_imgblock_f ( Imgblock_f **  img_out,
uint32_t  num_imgs,
uint32_t  num_rows,
uint32_t  num_cols 
)

Creates a single precision floating point image block and initializes it with zeros.

Parameters:
img_outResult parameter. If *img_out is NULL, an image block is allocated; otherwise its space is re-used.
num_imgsNumber of images in the image block.
num_rowsNumber of rows in the image block.
num_colsNumber of columns in the image block.
Note:
Dimensions must be > 0.

Definition at line 209 of file imgblock.c.

void create_random_imgblock_f ( Imgblock_f **  img_out,
uint32_t  num_imgs,
uint32_t  num_rows,
uint32_t  num_cols,
Pixel_f  min,
Pixel_f  max 
)

Creates a single precision floating point image block and initializes it with random values.

Calls rand() to generate the random numbers.

Parameters:
img_outResult parameter. If *img_out is NULL, an image block is allocated; otherwise its space is re-used.
num_imgsNumber of images in the image block.
num_rowsNumber of rows in the image block.
num_colsNumber of columns in the image block.
minMinimum random value.
maxMaximum random value.
Note:
Dimensions must be > 0.
Since Pixel_f samples range [0,1], min and max should be in that range as well so a meaningful image block is created.
Warning:
Does not check min and max to see if they would cause overflow.

Definition at line 253 of file imgblock.c.

Error* create_imgblock_from_matblocks_f ( Imgblock_f **  img_out,
const Matblock_f m_r,
const Matblock_f m_g,
const Matblock_f m_b 
)

Creates a single precision floating point image block from three matrix blocks.

Parameters:
img_outResult parameter. If *img_out is NULL, an image block is allocated; otherwise its space is re-used.
m_rMatrix block to copy into the red samples of the image block.
m_gMatrix block to copy into the green samples of the image block.
m_bMatrix block to copy into the blue samples of the image block.
Returns:
On success, NULL is returned. On error, an Error is returned and *img_out is freed and set to NULL.

Definition at line 310 of file imgblock.c.

void create_imgblock_from_matblock_f ( Imgblock_f **  img_out,
const Matblock_f m 
)

Creates a single precision floating point grayscale image block from a matrix block.

Parameters:
img_outResult parameter. If *img_out is NULL, an image block is allocated; otherwise its space is re-used.
mMatrix block to copy into the red, green and blue samples of the image.

Definition at line 370 of file imgblock.c.

void create_matblocks_from_imgblock_f ( Matblock_f **  m_r_out,
Matblock_f **  m_g_out,
Matblock_f **  m_b_out,
const Imgblock_f img 
)

Creates three single precision floating point matrix blocks from an image block.

Parameters:
m_r_outResult parameter. Red sample matrix block. If *m_r_out is NULL, an image block is allocated; otherwise its space is re-used.
m_g_outResult parameter. Green sample matrix block. If *m_g_out is NULL, an image block is allocated; otherwise its space is re-used.
m_b_outResult parameter. Blue sample matrix block. If *m_b_out is NULL, an image block is allocated; otherwise its space is re-used.
imgImage block to copy into the matrix blocks.

Definition at line 403 of file imgblock.c.

void create_matblock_from_imgblock_f ( Matblock_f **  m_out,
const Imgblock_f img,
float  r_weight,
float  g_weight,
float  b_weight 
)

Creates an averaged single precision floating point matrix block from an image block.

The weights are normalized to sum to one.

Parameters:
m_outResult parameter. If *m_out is NULL, a matrix block is allocated; otherwise its space is re-used.
imgImage block to copy into the matrix block.
r_weightWeight of the red sample.
g_weightWeight of the green sample.
b_weightWeight of the blue sample.
Note:
Weights must be non-negative.

Definition at line 461 of file imgblock.c.

void copy_imgblock_f ( Imgblock_f **  img_out,
const Imgblock_f img_in 
)

Copies a single precision floating point image block.

Parameters:
img_outResult parameter. If *img_out is NULL, an image block is allocated; otherwise its space is re-used.
img_inImage block to copy.

Definition at line 516 of file imgblock.c.

Error* copy_image_into_imgblock_f ( Imgblock_f **  ib_out,
const Imgblock_f ib_in,
const Image_f i,
Imgblock_image  orient,
uint32_t  index 
)

Copies a single precision floating point image into an image block.

Parameters:
ib_outResult parameter. If *ib_out is NULL, a image block is allocated; otherwise its space is re-used.
ib_inImage block to copy a image into.
iImage to copy into the image block.
orientOrientation of the image to copy into the image block.
indexIndex along the orientation dimension to copy the image into the image block.
Returns:
On success, NULL is returned. On error, an Error is returned and *ib_out is freed and set to NULL (if it is not ib_in).
  • ERROR_INV_ARG index is not a valid for the specified orientation dimension.
Note:
If *ib_out == ib_in, then ib_in is overwritten.

Definition at line 566 of file imgblock.c.

Error* copy_image_from_imgblock_f ( Image_f **  img_out,
const Imgblock_f img_blk,
Imgblock_image  orient,
uint32_t  index 
)

Copies a single precision floating point image from and image block.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
img_blkImage block to copy an image from.
orientOrientation of the image to copy from the image block.
indexIndex along the orientation dimension to copy the image from the image block.
Returns:
On success, NULL is returned. On error, an Error is returned and *img_out is freed and set to NULL.
  • ERROR_INV_ARG index is not a valid for the specified orientation dimension.

Definition at line 675 of file imgblock.c.

void free_imgblock_f ( Imgblock_f img)

Frees a single precision floatin point image block.

Parameters:
imgImage block to free.

Definition at line 763 of file imgblock.c.