UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
dxt_glsl.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2011-2023 CESNET z.s.p.o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#include "config_unix.h"
41#include "config_win32.h"
42#endif
43#include "debug.h"
44#include "host.h"
45#include "video_decompress.h"
46
49//#include "compat/platform_semaphore.h"
50#include "video.h"
51#include <pthread.h>
52#include <stdlib.h>
53#include "lib_common.h"
54
55#include "gl_context.h"
56
69
70static int configure_with(struct state_decompress_rtdxt *decompressor, struct video_desc desc)
71{
72 enum dxt_type type;
73
74 if(!init_gl_context(&decompressor->context, GL_CONTEXT_ANY)) {
75 fprintf(stderr, "[RTDXT decompress] Failed to create GL context.\n");
76 exit_uv(EXIT_FAILURE);
77 decompressor->compressed_len = 0;
78 return FALSE;
79 }
80
81 if(desc.color_spec == DXT5) {
83 } else if(desc.color_spec == DXT1) {
85 } else if(desc.color_spec == DXT1_YUV) {
87 } else {
88 fprintf(stderr, "Wrong compressiong to decompress.\n");
89 return FALSE;
90 }
91
92 decompressor->desc = desc;
93
94 decompressor->decoder = dxt_decoder_create(type, desc.width,
95 desc.height, decompressor->out_codec == RGBA ?
97 decompressor->context.legacy);
98
99 if (decompressor->decoder == NULL) {
100 fprintf(stderr, "[RTDXT decompress] State initialization failed.\n");
101 return FALSE;
102 }
103
105 decompressor->configured = TRUE;
106
107 return TRUE;
108}
109
110static void * dxt_glsl_decompress_init(void)
111{
112 struct state_decompress_rtdxt *s;
113
114 s = (struct state_decompress_rtdxt *) malloc(sizeof(struct state_decompress_rtdxt));
115 s->configured = FALSE;
116
117 return s;
118}
119
121 int rshift, int gshift, int bshift, int pitch, codec_t out_codec)
122{
124 int ret = TRUE;
125
126 s->pitch = pitch;
127 s->rshift = rshift;
128 s->gshift = gshift;
129 s->bshift = bshift;
130 s->out_codec = out_codec;
131 if(!s->configured) {
132 ret = configure_with(s, desc);
133 } else {
137 ret = configure_with(s, desc);
138 }
139
141
142 return ret;
143}
144
145static decompress_status dxt_glsl_decompress(void *state, unsigned char *dst, unsigned char *buffer,
146 unsigned int src_len, int frame_seq, struct video_frame_callbacks *callbacks, struct pixfmt_desc *internal_prop)
147{
149 UNUSED(src_len);
150 UNUSED(frame_seq);
151 UNUSED(callbacks);
152 UNUSED(internal_prop);
153
154 if (!s->configured) {
155 fprintf(stderr, "DXT decoder not configured!\n");
156 return DECODER_NO_FRAME;
157 }
158
160
161 if(s->pitch == vc_get_linesize(s->desc.width, s->out_codec)) {
162 dxt_decoder_decompress(s->decoder, buffer, dst);
163 } else {
164 int i;
165 int linesize;
166 unsigned char *line_src, *line_dst;
167
168 unsigned char *tmp;
169
170 if(s->out_codec == UYVY)
171 linesize = s->desc.width * 2;
172 else
173 linesize = s->desc.width * 4;
174 tmp = malloc(linesize * s->desc.height);
175
176 dxt_decoder_decompress(s->decoder, buffer, tmp);
177 line_dst = dst;
178 line_src = tmp;
179 for(i = 0; i < (int) s->desc.height; i++) {
180 if(s->out_codec == RGBA) {
181 vc_copylineRGBA(line_dst, line_src, linesize,
182 s->rshift, s->gshift, s->bshift);
183 } else { /* UYVY */
184 memcpy(line_dst, line_src, linesize);
185 }
186 line_dst += s->pitch;
187 line_src += linesize;
188
189 }
190 free(tmp);
191 }
192
194 return DECODER_GOT_FRAME;
195}
196
197static int dxt_glsl_decompress_get_property(void *state, int property, void *val, size_t *len)
198{
200 UNUSED(s);
201 int ret = FALSE;
202
203 switch(property) {
205 if(*len >= sizeof(int)) {
206 *(int *) val = TRUE;
207 *len = sizeof(int);
208 ret = TRUE;
209 }
210 break;
211 default:
212 ret = FALSE;
213 }
214
215 return ret;
216}
217
219{
221
222 if(s->configured) {
227 }
228 free(s);
229}
230
231static int dxt_glsl_decompress_get_priority(codec_t compression, struct pixfmt_desc internal, codec_t ugc) {
232 UNUSED(internal);
233 if (compression != DXT1 && compression != DXT1_YUV && compression != DXT5) {
234 return -1;
235 }
236 if (ugc != RGBA && ugc != UYVY) {
237 return -1;
238 }
239 return 500;
240}
241
250
252
#define UNUSED(x)
void ** state
int void * val
struct video_desc desc
int void size_t * len
int property
int vc_get_linesize(unsigned int width, codec_t codec)
#define TRUE
#define FALSE
@ DXT_FORMAT_RGBA
Definition dxt_common.h:80
@ DXT_FORMAT_YUV422
Definition dxt_common.h:82
dxt_type
Definition dxt_common.h:88
@ DXT_TYPE_DXT1_YUV
Definition dxt_common.h:90
@ DXT_TYPE_DXT1
Definition dxt_common.h:89
@ DXT_TYPE_DXT5_YCOCG
Definition dxt_common.h:91
struct dxt_decoder * dxt_decoder_create(enum dxt_type type, int width, int height, enum dxt_format out_format, int legacy)
int dxt_decoder_destroy(struct dxt_decoder *decoder)
int dxt_decoder_decompress(struct dxt_decoder *decoder, unsigned char *image_compressed, DXT_IMAGE_TYPE *image)
static void * dxt_glsl_decompress_init(void)
Definition dxt_glsl.c:110
static int configure_with(struct state_decompress_rtdxt *decompressor, struct video_desc desc)
Definition dxt_glsl.c:70
static const struct video_decompress_info dxt_glsl_info
Definition dxt_glsl.c:242
static int dxt_glsl_decompress_get_property(void *state, int property, void *val, size_t *len)
Definition dxt_glsl.c:197
static int dxt_glsl_decompress_get_priority(codec_t compression, struct pixfmt_desc internal, codec_t ugc)
Definition dxt_glsl.c:231
static int dxt_glsl_decompress_reconfigure(void *state, struct video_desc desc, int rshift, int gshift, int bshift, int pitch, codec_t out_codec)
Definition dxt_glsl.c:120
static void dxt_glsl_decompress_done(void *state)
Definition dxt_glsl.c:218
static decompress_status dxt_glsl_decompress(void *state, unsigned char *dst, unsigned char *buffer, unsigned int src_len, int frame_seq, struct video_frame_callbacks *callbacks, struct pixfmt_desc *internal_prop)
Definition dxt_glsl.c:145
static int dxt_get_size(int width, int height, enum dxt_type format)
Definition dxt_util.h:60
bool init_gl_context(struct gl_context *context, int which)
initializes specified OpenGL context
Definition gl_context.c:69
void destroy_gl_context(struct gl_context *context)
Definition gl_context.c:223
void gl_context_make_current(struct gl_context *context)
Definition gl_context.c:236
#define GL_CONTEXT_ANY
Definition gl_context.h:72
decompress_status
#define DECOMPRESS_PROPERTY_ACCEPTS_CORRUPTED_FRAME
@ DECODER_NO_FRAME
@ DECODER_GOT_FRAME
void exit_uv(int status)
Definition host.cpp:625
@ LIBRARY_CLASS_VIDEO_DECOMPRESS
Definition lib_common.h:81
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
decoder_func_t vc_copylineRGBA
Option::OptType type
Definition settings.cpp:194
unsigned legacy
Definition gl_context.h:66
struct video_desc desc
Definition dxt_glsl.c:60
unsigned int configured
Definition dxt_glsl.c:65
struct dxt_decoder * decoder
Definition dxt_glsl.c:58
struct gl_context context
Definition dxt_glsl.c:67
codec_t color_spec
Definition types.h:182
unsigned int width
width of every tile (!)
Definition types.h:179
unsigned int height
height of every tile (!)
Definition types.h:180
Struct containing callbacks of a video_frame.
Definition types.h:230
codec_t
Definition types.h:65
@ DXT1
S3 Texture Compression DXT1.
Definition types.h:77
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
@ DXT5
S3 Texture Compression DXT5.
Definition types.h:79
@ DXT1_YUV
Structure same as DXT1, instead of RGB, YCbCr values are stored.
Definition types.h:78
@ RGBA
RGBA 8-bit, big-endian.
Definition types.h:70
This is an umbrella header for video functions.
API for video decompress drivers.
#define VIDEO_DECOMPRESS_ABI_VERSION