64struct state_video_compress_rtdxt {
71 unique_ptr<char []> decoded;
72 unsigned int configured:1;
73 unsigned int interlaced_input:1;
76 int encoder_input_linesize;
84static void dxt_glsl_compress_done(
struct module *mod);
95 fprintf(stderr,
"[RTDXT] Requested to compress tiles of different size!");
103 " to 8 bits. You may directly capture 8-bit signal to improve performance.\n";
122 for (
size_t i = 0; i <
sizeof codec_try /
sizeof codec_try[0]; ++i) {
124 switch (codec_try[i]) {
129 default: assert(0 &&
"Shouldn't get other codecs than the above.");
142 if(s->color_spec ==
DXT1) {
149 }
else if(s->color_spec ==
DXT1_YUV) {
158 }
else if(s->color_spec ==
DXT5){
169 if(s->encoder[i] == NULL) {
170 fprintf(stderr,
"[RTDXT] Unable to create decoder.\n");
179 s->encoder_input_linesize *= 4;
182 s->encoder_input_linesize *= 3;
185 s->encoder_input_linesize *= 2;
193 assert(data_len > 0);
194 assert(s->encoder_input_linesize > 0);
198 compressed_desc.color_spec = s->color_spec;
202 s->interlaced_input =
TRUE;
203 fprintf(stderr,
"[DXT compress] Enabling automatic deinterlacing.\n");
205 s->interlaced_input =
FALSE;
209 s->decoded = unique_ptr<char []>(
new char[4 * compressed_desc.width * compressed_desc.height]);
211 s->configured =
TRUE;
217 struct state_video_compress_rtdxt *s;
219 if(strcmp(opts,
"help") == 0) {
220 printf(
"DXT GLSL comperssion usage:\n");
221 printf(
"\t-c RTDXT:DXT1\n");
222 printf(
"\t\tcompress with DXT1\n");
223 printf(
"\t-c RTDXT:DXT1_YUV\n");
224 printf(
"\t\tcompress with DXT1_YUV\n");
225 printf(
"\t-c RTDXT:DXT5\n");
226 printf(
"\t\tcompress with DXT5 YCoCg\n");
230 s =
new state_video_compress_rtdxt();
232 if (strcasecmp(opts,
"DXT5") == 0) {
233 s->color_spec =
DXT5;
234 }
else if (strcasecmp(opts,
"DXT1") == 0) {
235 s->color_spec =
DXT1;
236 }
else if (strcasecmp(opts,
"DXT1_YUV") == 0) {
238 }
else if (opts[0] ==
'\0') {
239 s->color_spec =
DXT1;
241 fprintf(stderr,
"Unknown compression: %s\n", opts);
247 fprintf(stderr,
"[RTDXT] Error initializing GL context");
257 s->module_data.
deleter = dxt_glsl_compress_done;
260 return &s->module_data;
263shared_ptr<video_frame> dxt_glsl_compress(
struct module *mod, shared_ptr<video_frame>
tx)
269 struct state_video_compress_rtdxt *s = (
struct state_video_compress_rtdxt *) mod->
priv_data;
271 unsigned char *line1, *line2;
284 shared_ptr<video_frame> out_frame = s->pool.
get_frame();
286 for (x = 0; x <
tx->tile_count; ++x) {
290 line1 = (
unsigned char *) in_tile->
data;
291 line2 = (
unsigned char *) s->decoded.get();
293 for (i = 0; i < (int) in_tile->height; ++i) {
294 s->decoder(line2, line1, s->encoder_input_linesize,
297 line2 += s->encoder_input_linesize;
300 if(s->interlaced_input)
301 vc_deinterlace((
unsigned char *) s->decoded.get(), s->encoder_input_linesize,
305 (
unsigned char *) s->decoded.get(),
306 (
unsigned char *) out_tile->data);
314static void dxt_glsl_compress_done(
struct module *mod)
316 struct state_video_compress_rtdxt *s = (
struct state_video_compress_rtdxt *) mod->
priv_data;
319 for(
int i = 0; i < s->encoder_count; ++i) {
331 dxt_glsl_compress_init,
struct video_frame * frame
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
int vc_get_linesize(unsigned int width, codec_t codec)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_NOTICE
information that may be interesting
#define LOG_LEVEL_WARNING
less severe errors
int dxt_encoder_compress(struct dxt_encoder *encoder, DXT_IMAGE_TYPE *image, unsigned char *image_compressed)
struct dxt_encoder * dxt_encoder_create(enum dxt_type type, int width, int height, enum dxt_format format, int legacy)
int dxt_encoder_destroy(struct dxt_encoder *encoder)
static int dxt_get_size(int width, int height, enum dxt_type format)
bool init_gl_context(struct gl_context *context, int which)
initializes specified OpenGL context
void destroy_gl_context(struct gl_context *context)
void gl_context_make_current(struct gl_context *context)
void module_init_default(struct module *module_data)
void module_register(struct module *module_data, struct module *parent)
#define VIDEO_COMPRESS_ABI_VERSION
@ LIBRARY_CLASS_VIDEO_COMPRESS
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
decoder_t get_decoder_from_to(codec_t in, codec_t out)
decoder_func_t * decoder_t
Struct tile is an area of video_frame.
char * data
Raw tile data. Pointer must be at least 4B aligned.
std::shared_ptr< video_frame > get_frame()
void reconfigure(struct video_desc new_desc, size_t new_size=SIZE_MAX)
Struct video_frame represents a video frame and contains video description.
enum interlacing_t interlacing
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
@ PROGRESSIVE
progressive frame
@ INTERLACED_MERGED
Columngs of both fields are interlaced together.
@ DXT1
S3 Texture Compression DXT1.
@ RGB
RGB 8-bit (packed into 24-bit word)
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
@ VIDEO_CODEC_NONE
dummy color spec
@ DXT5
S3 Texture Compression DXT5.
@ DXT1_YUV
Structure same as DXT1, instead of RGB, YCbCr values are stored.
@ RGBA
RGBA 8-bit, big-endian.
This is an umbrella header for video functions.
void vc_deinterlace(unsigned char *src, long src_linesize, int lines)
Deinterlaces framebuffer.
bool codec_is_a_rgb(codec_t codec)
Returns TRUE if specified pixelformat is some form of RGB (not YUV).
int get_bits_per_component(codec_t codec)
API for video compress drivers.
struct tile * vf_get_tile(struct video_frame *buf, int pos)
Returns pointer to n-th tile from video frame Equivalent to &video_frame::tiles[pos].