GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_gamma_correction.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2024 Cyril Hrubis <metan@ucw.cz>
4 */
5
85#ifndef CORE_GP_GAMMA_CORRECTION_H
86#define CORE_GP_GAMMA_CORRECTION_H
87
88#include <stdint.h>
89#include <core/gp_types.h>
90#include <core/gp_pixel.gen.h>
92
103
113
117typedef struct gp_gamma_table {
121 float gamma;
122
124 uint8_t in_bits;
126 uint8_t out_bits;
127
129 unsigned int ref_count;
130 struct gp_gamma_table *next;
131
133 union {
137 uint8_t u8[0];
141 uint16_t u16[0];
142 };
144
165
175 gp_correction_desc *corr_desc);
176
188
197
205
211void gp_gamma_print(const gp_gamma *self);
212
213/* Generated sRGB lookup tables */
214extern uint16_t gp_srgb8_to_lin10_tbl[256];
215extern uint8_t gp_lin10_to_srgb8_tbl[1024];
216
223static inline uint8_t gp_lin16_to_srgb8(uint16_t val)
224{
225 return gp_lin10_to_srgb8_tbl[(val + (1<<3))>>6];
226}
227
234static inline uint16_t gp_srgb8_to_lin16(uint8_t val)
235{
236 return gp_srgb8_to_lin10_tbl[val]<<6;
237}
238
239#endif /* CORE_GP_GAMMA_CORRECTION_H */
A common types.
Gamma corrections.
gp_gamma * gp_gamma_incref(gp_gamma *gamma)
Increases reference counters.
gp_gamma * gp_correction_acquire(gp_pixel_type pixel_type, gp_correction_desc *corr_desc)
Acquires a gamma, sRGB, ... correction tables for a given pixel type.
static uint8_t gp_lin16_to_srgb8(uint16_t val)
Converts 16 bit linear value to 8 bit sRGB.
void gp_gamma_decref(gp_gamma *self)
Decreases reference counters.
void gp_gamma_print(const gp_gamma *self)
Prints info about gamma table into the stdout.
static uint16_t gp_srgb8_to_lin16(uint8_t val)
Converts 8 bit sRGB to 16 bit linear value.
const char * gp_correction_type_name(gp_correction_type type)
Returns correction name.
A pixel defintions generated from gen/include/gfxprim_config.py.
#define GP_PIXEL_CHANS_MAX
Maximal number of channels per all defined pixel types.
gp_pixel_type
List of all pixel types.
gp_correction_type
A list of supported correction types.
@ GP_CORRECTION_TYPE_GAMMA
Classical gamma correction.
@ GP_CORRECTION_TYPE_SRGB
Standard RGB.
A correction description.
float gamma
gamma for GP_CORRECTION_TYPE_GAMMA
gp_correction_type corr_type
Correction type.
A lookup gamma table.
uint8_t in_bits
Number of input bits.
float gamma
Gamma for GP_CORRECTION_GAMMA.
gp_correction_type corr_type
Correction type.
uint8_t u8[0]
8-bit lookup table pointer
unsigned int ref_count
Reference counter.
uint8_t out_bits
Number of output bits.
uint16_t u16[0]
16-bit lookup table pointer
A correction tables for all pixel channels.
unsigned int ref_count
Reference counter.
gp_gamma_table * lin[4]
Tables to linearize channel values.
gp_gamma_table * enc[4]
Tables to encode the values back.
gp_pixel_type pixel_type
Pixel type the table could be used for.