Turnstone Operating System
Loading...
Searching...
No Matches
image_png.64.c File Reference

PNG image converter methods. More...

#include <graphics/png.h>
#include <errno.h>
#include <buffer.h>
#include <compression.h>
#include <logging.h>
#include <utils.h>
#include <crc.h>

Classes

struct  png_decoder_t
 
struct  png_encoder_t
 

Macros

#define PNG_SIGNATURE   0x0A1A0A0D474E5089ULL
 

Typedefs

typedef enum png_error_types_t png_error_types_t
 
typedef struct png_decoder_t png_decoder_t
 
typedef enum png_chunk_type_t png_chunk_type_t
 
typedef enum png_filter_type_t png_filter_type_t
 
typedef uint8_t(* png_filter_t) (uint8_t *dst, int64_t dst_idx, uint32_t scanline_len, uint32_t bpp, int64_t x, int64_t y)
 
typedef struct png_encoder_t png_encoder_t
 

Enumerations

enum  png_error_types_t {
  PNG_SUCCESS , PNG_ERROR_UNKNOWN , PNG_DECODER_INVALID_CHUNK_LENGTH , PNG_DECODER_INVALID_COLOR_TYPE ,
  PNG_DECODER_INVALID_FILTER_METHOD , PNG_DECODER_INVALID_COMPRESSION_METHOD , PNG_DECODER_INVALID_INTERLACE_METHOD , PNG_DECODER_IEND_ALREADY_PARSED ,
  PNG_DECODER_IEND_NOT_FOUND , PNG_DECODER_UNKNOWN_CHUNK_TYPE , PNG_DECODER_MULTIPLE_CHUNK_TYPE_NOT_ALLOWED , PNG_DECODER_INCORRECT_CHUNK_ORDER ,
  PNG_DECODER_CRC_MISMATCH , PNG_DECODER_UNSUPPORTED_COLOR_TYPE , PNG_DECODER_INVALID_FILTER_TYPE , PNG_DECODER_UNCOMPRESS_SIZE_MISMATCH ,
  PNG_DECODER_INVALID_ZLIB_HEADER , PNG_DECODER_ADLER32_MISMATCH , PNG_DECODER_MEMORY_ERROR , PNG_DECODER_INVALID_PNG_HEADER ,
  PNG_DECODER_SIZE_MISMATCH
}
 
enum  png_chunk_type_t {
  PNG_CHUNK_TYPE_IHDR , PNG_CHUNK_TYPE_cHRM , PNG_CHUNK_TYPE_gAMA , PNG_CHUNK_TYPE_iCCP ,
  PNG_CHUNK_TYPE_sBIT , PNG_CHUNK_TYPE_sRGB , PNG_CHUNK_TYPE_PLTE , PNG_CHUNK_TYPE_bKGD ,
  PNG_CHUNK_TYPE_hIST , PNG_CHUNK_TYPE_tRNS , PNG_CHUNK_TYPE_pHYs , PNG_CHUNK_TYPE_sPLT ,
  PNG_CHUNK_TYPE_IDAT , PNG_CHUNK_TYPE_tIME , PNG_CHUNK_TYPE_iTXt , PNG_CHUNK_TYPE_tEXt ,
  PNG_CHUNK_TYPE_zTXt , PNG_CHUNK_TYPE_IEND , PNG_CHUNK_TYPE_MAX
}
 
enum  png_filter_type_t {
  PNG_FILTER_TYPE_NONE , PNG_FILTER_TYPE_SUB , PNG_FILTER_TYPE_UP , PNG_FILTER_TYPE_AVERAGE ,
  PNG_FILTER_TYPE_PAETH , PNG_FILTER_TYPE_MAX
}
 

Functions

 MODULE ("turnstone.kernel.graphics.image")
 
static png_chunk_type_t png_chunk_type_from_uint32 (uint32_t type)
 
static boolean_t png_chunk_order_allowed (png_decoder_t *png_decoder, png_chunk_type_t chunk_type)
 
static int8_t png_decoder_is_png (png_decoder_t *png_decoder)
 
static int8_t png_decoder_parse_ihdr (png_decoder_t *png_decoder, uint8_t *chunk_data, uint32_t length)
 
static int8_t png_decoder_parse_chunk (png_decoder_t *png_decoder)
 
static int8_t png_decoder_init (png_decoder_t *png_decoder, buffer_t *buffer)
 
static int8_t png_decoder_parse_chunks (png_decoder_t *png_decoder)
 
static uint8_t png_filter_none (uint8_t *dst, int64_t dst_idx, uint32_t scanline_len, uint32_t bpp, int64_t x, int64_t y)
 
static uint8_t png_filter_sub (uint8_t *dst, int64_t dst_idx, uint32_t scanline_len, uint32_t bpp, int64_t x, int64_t y)
 
static uint8_t png_filter_up (uint8_t *dst, int64_t dst_idx, uint32_t scanline_len, uint32_t bpp, int64_t x, int64_t y)
 
static uint8_t png_filter_average (uint8_t *dst, int64_t dst_idx, uint32_t scanline_len, uint32_t bpp, int64_t x, int64_t y)
 
static uint8_t png_paeth_predictor (uint16_t a, uint16_t b, uint16_t c)
 
static uint8_t png_filter_paeth (uint8_t *dst, int64_t dst_idx, uint32_t scanline_len, uint32_t bpp, int64_t x, int64_t y)
 
static png_filter_t png_get_filter_func (png_filter_type_t filter_type)
 
static int8_t png_decoder_apply_defilter (png_decoder_t *png_decoder, const uint8_t *img_data, const graphics_raw_image_t *res)
 
static graphics_raw_image_tpng_decoder_get_image (png_decoder_t *png_decoder)
 
graphics_raw_image_tgraphics_load_png_image (const uint8_t *data, uint32_t size)
 
static int8_t png_encoder_init (png_encoder_t *png_encoder, graphics_raw_image_t *image)
 
static int8_t png_encoder_find_and_apply_filter (png_encoder_t *png_encoder)
 
static int8_t png_encoder_compress (png_encoder_t *png_encoder)
 
static int8_t png_encoder_build_png (png_encoder_t *png_encoder)
 
uint8_tgraphics_save_png_image (const graphics_raw_image_t *image, uint64_t *size)
 

Variables

const uint32_t png_chunk_type_strings []
 
const boolean_t png_chunk_type_allow_multiple []
 

Detailed Description

PNG image converter methods.

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Variable Documentation

◆ png_chunk_type_allow_multiple

const boolean_t png_chunk_type_allow_multiple[]
Initial value:
= {
[PNG_CHUNK_TYPE_IHDR] = false,
[PNG_CHUNK_TYPE_PLTE] = false,
[PNG_CHUNK_TYPE_IDAT] = true,
[PNG_CHUNK_TYPE_IEND] = false,
[PNG_CHUNK_TYPE_cHRM] = false,
[PNG_CHUNK_TYPE_gAMA] = false,
[PNG_CHUNK_TYPE_iCCP] = false,
[PNG_CHUNK_TYPE_sBIT] = false,
[PNG_CHUNK_TYPE_sRGB] = false,
[PNG_CHUNK_TYPE_bKGD] = false,
[PNG_CHUNK_TYPE_hIST] = false,
[PNG_CHUNK_TYPE_tRNS] = false,
[PNG_CHUNK_TYPE_pHYs] = false,
[PNG_CHUNK_TYPE_sPLT] = true,
[PNG_CHUNK_TYPE_tIME] = false,
[PNG_CHUNK_TYPE_iTXt] = true,
[PNG_CHUNK_TYPE_tEXt] = true,
[PNG_CHUNK_TYPE_zTXt] = true,
[PNG_CHUNK_TYPE_MAX] = false,
}

◆ png_chunk_type_strings

const uint32_t png_chunk_type_strings[]
Initial value:
= {
[PNG_CHUNK_TYPE_IHDR] = 0x52444849,
[PNG_CHUNK_TYPE_PLTE] = 0x45544C50,
[PNG_CHUNK_TYPE_IDAT] = 0x54414449,
[PNG_CHUNK_TYPE_IEND] = 0x444E4549,
[PNG_CHUNK_TYPE_cHRM] = 0x4D524863,
[PNG_CHUNK_TYPE_gAMA] = 0x414D4167,
[PNG_CHUNK_TYPE_iCCP] = 0x50434369,
[PNG_CHUNK_TYPE_sBIT] = 0x54494273,
[PNG_CHUNK_TYPE_sRGB] = 0x42475273,
[PNG_CHUNK_TYPE_bKGD] = 0x44474B62,
[PNG_CHUNK_TYPE_hIST] = 0x54534968,
[PNG_CHUNK_TYPE_tRNS] = 0x534E5254,
[PNG_CHUNK_TYPE_pHYs] = 0x73594870,
[PNG_CHUNK_TYPE_sPLT] = 0x544C5073,
[PNG_CHUNK_TYPE_tIME] = 0x454D4974,
[PNG_CHUNK_TYPE_iTXt] = 0x74545869,
[PNG_CHUNK_TYPE_tEXt] = 0x74584574,
[PNG_CHUNK_TYPE_zTXt] = 0x7448547A,
[PNG_CHUNK_TYPE_MAX] = 0x00000000,
}