UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
gamma.cpp File Reference
#include <iostream>
#include <stdexcept>
#include <thread>
#include <vector>
#include "capture_filter.h"
#include "debug.h"
#include "lib_common.h"
#include "utils/color_out.h"
#include "utils/worker.h"
#include "video.h"
#include "video_codec.h"
#include "vo_postprocess/capture_filter_wrapper.h"
Include dependency graph for gamma.cpp:

Go to the source code of this file.

Classes

struct  state_capture_filter_gamma
 
struct  state_capture_filter_gamma::data< inT, outT >
 

Functions

static void done (void *state)
 
static auto filter (void *state, struct video_frame *in) -> video_frame *
 
static auto init (struct module *parent, const char *cfg, void **state)
 
 REGISTER_MODULE (gamma, &capture_filter_gamma, LIBRARY_CLASS_CAPTURE_FILTER, CAPTURE_FILTER_ABI_VERSION)
 
static void vo_pp_set_out_buffer (void *state, char *buffer)
 

Variables

static const struct capture_filter_info capture_filter_gamma
 
constexpr const char * MOD_NAME = "[gamma cap. f.] "
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file gamma.cpp.

Function Documentation

◆ done()

static void done ( void * state)
static

Definition at line 189 of file gamma.cpp.

190{
191 delete static_cast<state_capture_filter_gamma *>(state);
192}
void ** state

References state.

◆ filter()

static auto filter ( void * state,
struct video_frame * in ) -> video_frame *
static

Definition at line 194 of file gamma.cpp.

195{
196 if (in->color_spec != RGB && in->color_spec != RG48) {
197 LOG(LOG_LEVEL_ERROR) << MOD_NAME << "Unable to apply lut on: " << get_codec_name(in->color_spec) << "\n";
199 return nullptr;
200 }
201
202 auto *s = static_cast<state_capture_filter_gamma *>(state);
203 struct video_desc out_desc = video_desc_from_frame(in);
204 if (s->out_depth != 0) {
205 out_desc.color_spec = s->out_depth == 8 ? RGB : RG48;
206 }
207 struct video_frame *out = vf_alloc_desc(out_desc);
208 if (s->vo_pp_out_buffer != nullptr) {
209 out->tiles[0].data = (char *) s->vo_pp_out_buffer;
210 } else {
211 out->tiles[0].data = (char *) malloc(out->tiles[0].data_len);
213 }
215
216 try {
217 s->apply_gamma(get_bits_per_component(in->color_spec), get_bits_per_component(out_desc.color_spec), in->tiles[0].data_len, in->tiles[0].data, out->tiles[0].data);
218 } catch(...) {
219 LOG(LOG_LEVEL_ERROR) << MOD_NAME << "Only 8-bit and 16-bit codecs are currently supported!\n";
220 vf_free(out);
221 out = nullptr;
222 }
223
225
226 return out;
227}
void vf_free(struct video_frame *buf)
Frees video_frame structure.
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
void vf_data_deleter(struct video_frame *buf)
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
const char * get_codec_name(codec_t codec)
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
#define LOG(level)
Definition debug.h:313
constexpr const char * MOD_NAME
Definition gamma.cpp:58
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
unsigned int data_len
length of the data
Definition types.h:288
codec_t color_spec
Definition types.h:182
void(* data_deleter)(struct video_frame *)
Definition types.h:256
void(* dispose)(struct video_frame *)
Definition types.h:245
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
struct video_frame_callbacks callbacks
Definition types.h:324
codec_t color_spec
Definition types.h:306
@ RGB
RGB 8-bit (packed into 24-bit word)
Definition types.h:80
@ RG48
16-bit RGB little-endian (RlRhGl...)
Definition types.h:95
int get_bits_per_component(codec_t codec)
#define VIDEO_FRAME_DISPOSE(frame)
Definition video_frame.h:76

References video_frame::callbacks, video_desc::color_spec, tile::data, video_frame_callbacks::data_deleter, tile::data_len, video_frame_callbacks::dispose, get_bits_per_component(), get_codec_name(), LOG, LOG_LEVEL_ERROR, MOD_NAME, RG48, RGB, state, video_frame::tiles, vf_alloc_desc(), vf_data_deleter(), vf_free(), video_desc_from_frame(), and VIDEO_FRAME_DISPOSE.

Here is the call graph for this function:

◆ init()

static auto init ( struct module * parent,
const char * cfg,
void ** state )
static

Definition at line 151 of file gamma.cpp.

152{
153 UNUSED(parent);
154
155 if (strlen(cfg) == 0 || strcmp(cfg, "help") == 0) {
156 col() << "Performs gamma transformation.\n\n"
157 "usage:\n";
158 col() << "\t" << SBOLD("-F gamma:value[:8|:16]") << "\n";
159 col() << "where:\n";
160 col() << SBOLD("8|16")
161 << " - force output to 8 (16) bits regardless the input\n";
162 return 1;
163 }
164 char *endptr = nullptr;
165 errno = 0;
166 double gamma = strtod(cfg, &endptr);
167
168 if (gamma <= 0.0 || errno != 0 || (*endptr != '\0' && *endptr != ':')) {
169 LOG(LOG_LEVEL_WARNING) << MOD_NAME << "Using gamma value " << gamma << "\n";
170 }
171
172 long int bits = 0;
173 if (*endptr != '\0') {
174 endptr += 1;
175 errno = 0;
176 bits = strtol(endptr, &endptr, 0);
177 if ((bits != 8 && bits != 16) || *endptr != '\0') {
178 LOG(LOG_LEVEL_ERROR) << MOD_NAME << "Wrong number of bits (only 8 or 16)!\n";
179 return -1;
180 }
181 }
182
183 auto *s = new state_capture_filter_gamma(gamma, bits);
184
185 *state = s;
186 return 0;
187}
#define UNUSED(x)
#define SBOLD(x)
Definition color_out.h:80
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
const char * parent
Definition settings.cpp:198

References LOG, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, MOD_NAME, parent, SBOLD, state, and UNUSED.

◆ REGISTER_MODULE()

REGISTER_MODULE ( gamma ,
& capture_filter_gamma,
LIBRARY_CLASS_CAPTURE_FILTER ,
CAPTURE_FILTER_ABI_VERSION  )

◆ vo_pp_set_out_buffer()

static void vo_pp_set_out_buffer ( void * state,
char * buffer )
static

Definition at line 229 of file gamma.cpp.

230{
231 auto *s = (state_capture_filter_gamma *) state;
232 s->vo_pp_out_buffer = buffer;
233}

References state.

Variable Documentation

◆ capture_filter_gamma

const struct capture_filter_info capture_filter_gamma
static
Initial value:
= {
.init = init,
.done = done,
.filter = filter,
}
static auto filter(void *state, struct video_frame *in) -> video_frame *
Definition gamma.cpp:194
static void done(void *state)
Definition gamma.cpp:189
static auto init(struct module *parent, const char *cfg, void **state)
Definition gamma.cpp:151

Definition at line 235 of file gamma.cpp.

235 {
236 .init = init,
237 .done = done,
238 .filter = filter,
239};

◆ MOD_NAME

const char* MOD_NAME = "[gamma cap. f.] "
constexpr

Definition at line 58 of file gamma.cpp.

Referenced by filter(), and init().