VCLib Documentation  6.12.2

JPEG Routines

Macros

#define JPGBUF   (0x4000)
 

Functions

I32 fread_jpeg (image *a, char *name)
 Reads Image Content from a JPEG Image File/Flash EPROM. More...
 
I32 fwrite_jpeg (image *a, char *name, I32 quality, U32 maxlng)
 Writes Image Content to a JPEG Image File/Flash EPROM. More...
 
U8cjpeg (image *a, I32 quality, U8 *addr, U32 maxlng, I32(*func)())
 Encodes Image Content to the JPEG Image File Format. More...
 
U8encode_jpeg (image *a, I32 quality, U8 *addr, U32 maxlng, I32(*func)())
 Encodes Image Content to the JPEG Image File Format (including Color). More...
 
U8djpeg (image *a, U8 *addr, I32(*func)())
 Decodes JPEG Image File Format Data to Image Content. More...
 
#define cjpeg_d(img, qual, addr, maxlng)   cjpeg(img, qual, addr, maxlng, (I32 (*)())NULL)
 Writes JPEG Data to Memory (TO BE COMPLETED). More...
 
#define cjpeg_f(img, qual, addr, maxlng)   cjpeg(img, qual, addr, maxlng, (I32 (*)())wr_flash)
 Writes JPEG Data to Flash Eprom (TO BE COMPLETED). More...
 
#define djpeg_d(img, addr)   djpeg(img, addr, (I32 (*)())rd_dram)
 Reads JPEG Data from Memory (TO BE COMPLETED). More...
 
#define djpeg_f(img, addr)   djpeg(img, addr, (I32 (*)())rd_flash)
 Reads JPEG Data from Flash Eprom (TO BE COMPLETED). More...
 

Detailed Description

JPEG is a standard for still image compression. The images may be stored at an arbitrary compression rate. There is some loss of information: the higher the compression rate the higher the image degradation due to loss of information. We recommend using quality factors of 50% - 80% for high quality images at reasonable compression rates. Since JPEG is a standard it may be used for exchanging image data with e.g. a PC. Standard PC programs comply with the format used in this library. Please be sure to store images as grey-level images since this color compression / decompression is not supported. Image variables used in JPEG compression must have a format which is a multiple of 8 for both, dx and dy. When decompressing images image variables must have a size of at least the size of the JPEG image - otherwise no decompression will be preformed.

Macro Definition Documentation

◆ JPGBUF

#define JPGBUF   (0x4000)

JPEG encode output buffer size, must be > 0x400

◆ cjpeg_d

#define cjpeg_d (   img,
  qual,
  addr,
  maxlng 
)    cjpeg(img, qual, addr, maxlng, (I32 (*)())NULL)

(TO BE COMPLETED).

cjpeg_d() is a macro which calls cjpeg() with basic function wr_dram() as an argument.

◆ cjpeg_f

#define cjpeg_f (   img,
  qual,
  addr,
  maxlng 
)    cjpeg(img, qual, addr, maxlng, (I32 (*)())wr_flash)

(TO BE COMPLETED).

cjpeg_f() is a macro which calls cjpeg() with basic function wr_flash() as an argument.

◆ djpeg_d

#define djpeg_d (   img,
  addr 
)    djpeg(img, addr, (I32 (*)())rd_dram)

(TO BE COMPLETED).

djpeg_d() is a macro which calls djpeg() with basic function rd_dram() as an argument.

◆ djpeg_f

#define djpeg_f (   img,
  addr 
)    djpeg(img, addr, (I32 (*)())rd_flash)

(TO BE COMPLETED).

djpeg_f() is a macro which calls djpeg() with basic function rd_flash() as an argument.

Function Documentation

◆ fread_jpeg()

I32 fread_jpeg ( image a,
char *  name 
)

The function decompresses a JPEG file and displays the result in image variable a. A file with a path given by path is searched, the data is decompressed and the image is written into image variable a.

The function returns -1 if the file could not be opened, it returns -2 if the image could not be displayed. That may be the case, if the JPEG image size is larger than the image variable size. Under normal conditions, the function will return 0.

Note
The JPEG width and height must be a multiple of eight!
Memory Consumption
768 Bytes of Heap Memory.
See also
fwrite_jpeg().

◆ fwrite_jpeg()

I32 fwrite_jpeg ( image a,
char *  name,
I32  quality,
U32  maxlng 
)

The function compresses image variable a to JPEG format according to the JPEG standard. quality is a value between 0 and 100 indicating the resulting image quality. A value near 0 indicates a low quality image (with high compression rate), a value of 100 indicates a high quality image (with low compression rate). In general, a compression rate of 10 - 20 can be expected, depending on the input image. A file is created and all JPEG data will be stored in this file. The path of the file is specified by the string path. If a filesize of maxlng is reached and the JPEG generation process did not finish, the file is deleted afterwards, since it containes no useful information. In this case the function will return -1, otherwise 0. The function also returns -1 if the specified file could not be opened. maxlng must be 22 at minimum, this is the size of the file-header and -trailer. It is recommended to use much larger values for maxlng, e.g. several kilobytes.

Memory Consumption
768 Bytes of Heap Memory.
See also
fread_jpeg().

◆ cjpeg()

U8* cjpeg ( image a,
I32  quality,
U8 addr,
U32  maxlng,
I32(*)()  func 
)

The function compresses image variable a to JPEG format according to the JPEG standard. quality is a value between 0 and 100 indicating the resulting image quality. A value near 0 indicates a low quality image (with high compression rate), a value of 100 indicates a high quality image (with low compression rate). In general, a compression rate of 10 - 20 can be expected, depending on the input image. The JPEG data output is passed to the I/O function func() which specifies the destination of the data and how these data are stored or transmitted. A pointer to this function must be passed to cjpeg(). For the available I/O functions there are macros which make it easier to call the function. The following macros use this function:

  • cjpeg_d() writes JPEG data to memory starting at address addr.
  • cjpeg_f() writes JPEG data to Flash Eprom starting at address addr. Since this is a raw write (no file information is provided) care must be taken to use this function. If you want to write a flash Eprom file with JPEG data, use function fwrite_jpeg() instead.

For all macros the variable img is the image variable a of the cjpeg() function call, qual is the corresponding quality factor. addr and maxlng are start address and maximum length, the functions transferring data via the serial link do not need such variables.

cjpeg_d() and cjpeg_f(): If a data size of maxlng is reached and the JPEG generation process did not finish, the function will return 0L, otherwise it returns the next available address behind the JPEG data.

Of course, you can write your own I/O functions. Pass their address (function pointer) to cjpeg().

Memory Consumption
768 Bytes of Heap Memory.
See also
djpeg().

◆ encode_jpeg()

U8* encode_jpeg ( image imgIn,
I32  quality,
U8 output_ptr,
U32  maxlng,
I32(*)()  func 
)

JPEG is a standard for still image compression. The images may be stored at an arbitrary compression rate. There is some loss of information: the higher the compression rate the higher the image degradation due to loss of information. We recommend using quality factors of 50% - 80% for high quality images at reasonable compression rates.

Since JPEG is a standard it may be used for exchanging image data with e.g. a PC. Standard PC programs comply with the format used in this library. Grey-level and color image compression is supported.

When decompressing images image variables must have a size of at least the size of the JPEG image - otherwise no decompression will be performed.

This function does the main JPEG encoding. Grey and color Images may be encoded with this function. Encoding of color images requires a COLORLIB licence. With a licence of the EXTENSIONLIB comes a FAST, highly optimized version of the JPEG encoding

Parameters
imgInthe source image (GREY or COLOR image)
qualityquality of the compressed image
output_ptrpointer to the buffer memory or NULL
maxlngmaximum available space in bytes
funcfunction pointer for the output / storage of the JPEG data

◆ djpeg()

U8* djpeg ( image a,
U8 addr,
I32(*)()  func 
)

The function decompresses a JPEG file and displays the result in image variable a. The JPEG data input is provided by the I/O function func() which specifies the source of the data and how these data are read or transmitted. A pointer to this function must be passed to djpeg(). For the available I/O functions there are macros, which make it easier to call the function. The following macros use the function:

  • djpeg_d(): The JPEG data are read from memory starting at address addr, the resulting image is stored in image variable a. The function returns the next memory address behind the JPEG code. If a format error occurs it will return 0L. That may be the case, if the JPEG image size is larger than the image variable size.
  • djpeg_f(): The JPEG data are read from flash eprom starting at address addr, the resulting image is stored in image variable a. Since this is a raw read (no file information is used) care must be taken to use this function. If you want to read a flash Eprom file with JPEG data, use function instead. The function returns the next flash eprom address behind the JPEG code. If a format error occurs it will return 0L. That may be the case, if the JPEG image size is larger than the image variable size.

Of course, you can write your own I/O functions. Pass their address (function pointer) to djpeg().

Note
The JPEG width and height must be a multiple of eight!
Memory Consumption
768 Bytes of Heap Memory.
See also
cjpeg().