UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
dxt_common.h File Reference
#include <GL/glew.h>
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/time.h>
Include dependency graph for dxt_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DXT_COMPRESS_STANDALONE
 
#define DXT_IMAGE_GL_FORMAT   GL_RGBA
 
#define DXT_IMAGE_GL_TYPE   GL_UNSIGNED_INT_8_8_8_8_REV
 
#define DXT_IMAGE_TYPE   unsigned char
 
#define TIMER_DURATION()
 
#define TIMER_INIT()
 
#define TIMER_START()
 
#define TIMER_STOP()
 
#define TIMER_STOP_PRINT(text)
 

Enumerations

enum  dxt_format { DXT_FORMAT_RGB , DXT_FORMAT_RGBA , DXT_FORMAT_YUV , DXT_FORMAT_YUV422 }
 
enum  dxt_type { DXT_TYPE_DXT1 , DXT_TYPE_DXT1_YUV , DXT_TYPE_DXT5_YCOCG }
 

Functions

int dxt_image_compressed_destroy (unsigned char *image_compressed)
 
int dxt_image_compressed_load_from_file (const char *filename, unsigned char **data, int *data_size)
 
int dxt_image_compressed_save_to_file (const char *filename, unsigned char *image, int image_size)
 
int dxt_image_destroy (DXT_IMAGE_TYPE *image)
 
int dxt_image_load_from_file (const char *filename, int width, int height, DXT_IMAGE_TYPE **image)
 
int dxt_image_save_to_file (const char *filename, DXT_IMAGE_TYPE *image, int width, int height)
 
int dxt_init ()
 

Macro Definition Documentation

◆ DXT_COMPRESS_STANDALONE

#define DXT_COMPRESS_STANDALONE

Copyright (c) 2011, Martin Srom All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 35 of file dxt_common.h.

◆ DXT_IMAGE_GL_FORMAT

#define DXT_IMAGE_GL_FORMAT   GL_RGBA

◆ DXT_IMAGE_GL_TYPE

#define DXT_IMAGE_GL_TYPE   GL_UNSIGNED_INT_8_8_8_8_REV

◆ DXT_IMAGE_TYPE

#define DXT_IMAGE_TYPE   unsigned char

◆ TIMER_DURATION

#define TIMER_DURATION ( )
Value:
__elapsedTime

Definition at line 63 of file dxt_common.h.

Referenced by perform_decode(), and perform_encode().

◆ TIMER_INIT

#define TIMER_INIT ( )
Value:
struct timeval __start, __stop; \
long __seconds, __useconds; \
float __elapsedTime;

Timer

Definition at line 52 of file dxt_common.h.

52#define TIMER_INIT() \
53 struct timeval __start, __stop; \
54 long __seconds, __useconds; \
55 float __elapsedTime;

Referenced by dxt_decoder_decompress(), dxt_encoder_compress(), perform_decode(), and perform_encode().

◆ TIMER_START

#define TIMER_START ( )
Value:
gettimeofday(&__start, NULL);

Definition at line 56 of file dxt_common.h.

56#define TIMER_START() \
57 gettimeofday(&__start, NULL);

Referenced by dxt_decoder_decompress(), dxt_encoder_compress(), dxt_encoder_compress_texture(), perform_decode(), and perform_encode().

◆ TIMER_STOP

#define TIMER_STOP ( )
Value:
gettimeofday(&__stop, NULL); \
__seconds = __stop.tv_sec - __start.tv_sec; \
__useconds = __stop.tv_usec - __start.tv_usec; \
__elapsedTime = ((__seconds) * 1000.0 + __useconds/1000.0) + 0.5;

Definition at line 58 of file dxt_common.h.

58#define TIMER_STOP() \
59 gettimeofday(&__stop, NULL); \
60 __seconds = __stop.tv_sec - __start.tv_sec; \
61 __useconds = __stop.tv_usec - __start.tv_usec; \
62 __elapsedTime = ((__seconds) * 1000.0 + __useconds/1000.0) + 0.5;

Referenced by perform_decode(), and perform_encode().

◆ TIMER_STOP_PRINT

#define TIMER_STOP_PRINT ( text)
Value:
printf("%s %f ms\n", text, __elapsedTime)
#define TIMER_STOP()
Definition dxt_common.h:58

Definition at line 64 of file dxt_common.h.

64#define TIMER_STOP_PRINT(text) \
65 TIMER_STOP(); \
66 printf("%s %f ms\n", text, __elapsedTime)

Referenced by dxt_decoder_decompress(), dxt_encoder_compress(), and dxt_encoder_compress_texture().

Enumeration Type Documentation

◆ dxt_format

enum dxt_format

DXT format

Enumerator
DXT_FORMAT_RGB 
DXT_FORMAT_RGBA 
DXT_FORMAT_YUV 
DXT_FORMAT_YUV422 

Definition at line 78 of file dxt_common.h.

78 {
83};
@ DXT_FORMAT_RGBA
Definition dxt_common.h:80
@ DXT_FORMAT_YUV
Definition dxt_common.h:81
@ DXT_FORMAT_YUV422
Definition dxt_common.h:82
@ DXT_FORMAT_RGB
Definition dxt_common.h:79

◆ dxt_type

enum dxt_type

DXT type

Enumerator
DXT_TYPE_DXT1 
DXT_TYPE_DXT1_YUV 
DXT_TYPE_DXT5_YCOCG 

Definition at line 88 of file dxt_common.h.

88 {
92};
@ 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

Function Documentation

◆ dxt_image_compressed_destroy()

int dxt_image_compressed_destroy ( unsigned char * image_compressed)

Destroy DXT compressed image

Parameters
image_compressedCompressed image data buffer

Documented at declaration

Definition at line 206 of file dxt_common.c.

207{
208 free(image_compressed);
209
210 return 0;
211}

Referenced by perform_comparison(), perform_decode(), and perform_display().

◆ dxt_image_compressed_load_from_file()

int dxt_image_compressed_load_from_file ( const char * filename,
unsigned char ** data,
int * data_size )

Load compressed image from file

Parameters
filanameImage filename
widthImage width in pixels
heightImage height in pixels
Returns
0 if succeeds, otherwise nonzero

Documented at declaration

Definition at line 145 of file dxt_common.c.

146{
147 FILE* file;
148 file = fopen(filename, "rb");
149 if ( !file ) {
150 fprintf(stderr, "Failed open %s for reading!\n", filename);
151 return -1;
152 }
153
154 fseek(file, 0, SEEK_END);
155 *data_size = ftell(file);
156 rewind(file);
157 *data = (unsigned char*)malloc(*data_size * sizeof(unsigned char));
158 if ( (size_t) *data_size != fread(*data, sizeof(unsigned char), *data_size, file) ) {
159 fprintf(stderr, "Failed to load image data [%d bytes] from file %s!\n", *data_size, filename);
160 return -1;
161 }
162 fclose(file);
163
164#ifdef DEBUG
165 printf("Load Compressed Image [file: %s, size: %d bytes]\n", filename, *data_size);
166#endif
167
168 return 0;
169}

Referenced by perform_comparison(), perform_decode(), and perform_display().

◆ dxt_image_compressed_save_to_file()

int dxt_image_compressed_save_to_file ( const char * filename,
unsigned char * image,
int image_size )

Save compressed image to file

Parameters
filenameImage filename
imageImage data
image_sizeImage data size
Returns
0 if succeeds, otherwise nonzero

Documented at declaration

Definition at line 173 of file dxt_common.c.

174{
175 FILE* file;
176 file = fopen(filename, "wb");
177 if ( !file ) {
178 fprintf(stderr, "Failed open %s for writing!\n", filename);
179 return -1;
180 }
181
182 if ( (size_t) image_size != fwrite(image, sizeof(unsigned char), image_size, file) ) {
183 fprintf(stderr, "Failed to write image data [%d bytes] to file %s!\n", image_size, filename);
184 return -1;
185 }
186 fclose(file);
187
188#ifdef DEBUG
189 printf("Save Compressed Image [file: %s, size: %d bytes]\n", filename, image_size);
190#endif
191
192 return 0;
193}

Referenced by main(), and perform_encode().

◆ dxt_image_destroy()

int dxt_image_destroy ( DXT_IMAGE_TYPE * image)

Destroy DXT image

Parameters
imageImage data buffer

Documented at declaration

Definition at line 197 of file dxt_common.c.

198{
199 free(image);
200
201 return 0;
202}

Referenced by main(), perform_comparison(), perform_display(), and perform_encode().

◆ dxt_image_load_from_file()

int dxt_image_load_from_file ( const char * filename,
int width,
int height,
DXT_IMAGE_TYPE ** image )

Load RGB image from file

Parameters
filanameImage filename
widthImage width in pixels
heightImage height in pixels
Returns
image data buffer or zero if fails

Documented at declaration

Definition at line 67 of file dxt_common.c.

68{
69 FILE* file;
70 file = fopen(filename, "rb");
71 if ( !file ) {
72 fprintf(stderr, "Failed open %s for reading!\n", filename);
73 return -1;
74 }
75
76 int data_size = width * height * 3;
77 unsigned char* data = (unsigned char*)malloc(data_size * sizeof(unsigned char));
78 if ( (size_t) data_size != fread(data, sizeof(unsigned char), data_size, file) ) {
79 fprintf(stderr, "Failed to load image data [%d bytes] from file %s!\n", data_size, filename);
80 return -1;
81 }
82 fclose(file);
83
84 *image = (DXT_IMAGE_TYPE*)malloc(width * height * 4 * sizeof(DXT_IMAGE_TYPE));
85 for ( int y = 0; y < height; y++ ) {
86 for ( int x = 0; x < width; x++ ) {
87 int index = 4 * ((y * width) + x);
88 int index_data = 3 * ((y * width) + x);
89 (*image)[index + 0] = (DXT_IMAGE_TYPE)data[index_data + 0];
90 (*image)[index + 1] = (DXT_IMAGE_TYPE)data[index_data + 1];
91 (*image)[index + 2] = (DXT_IMAGE_TYPE)data[index_data + 2];
92 (*image)[index + 3] = 1.0;
93 }
94 }
95
96 free(data);
97
98#ifdef DEBUG
99 printf("Load Image [file: %s, size: %d bytes, resolution: %dx%d]\n", filename, data_size, width, height);
100#endif
101
102 return 0;
103}
#define DXT_IMAGE_TYPE
Definition dxt_common.h:71

References DXT_IMAGE_TYPE.

Referenced by main(), perform_comparison(), perform_display(), and perform_encode().

◆ dxt_image_save_to_file()

int dxt_image_save_to_file ( const char * filename,
DXT_IMAGE_TYPE * image,
int width,
int height )

Load RGB image from file

Parameters
filanameImage filename
widthImage width in pixels
heightImage height in pixels
Returns
image data buffer or zero if fails

Documented at declaration

Definition at line 107 of file dxt_common.c.

108{
109 FILE* file;
110 file = fopen(filename, "wb");
111 if ( !file ) {
112 fprintf(stderr, "Failed open %s for writing!\n", filename);
113 return -1;
114 }
115
116 int data_size = width * height * 3;
117 unsigned char* data = (unsigned char*)malloc(data_size * sizeof(unsigned char));
118 for ( int y = 0; y < height; y++ ) {
119 for ( int x = 0; x < width; x++ ) {
120 int index = 4 * ((y * width) + x);
121 int index_data = 3 * ((y * width) + x);
122 data[index_data + 0] = (unsigned char)(image[index + 0]);
123 data[index_data + 1] = (unsigned char)(image[index + 1]);
124 data[index_data + 2] = (unsigned char)(image[index + 2]);
125 }
126 }
127
128 if ( (size_t) data_size != fwrite(data, sizeof(unsigned char), data_size, file) ) {
129 fprintf(stderr, "Failed to write image data [%d bytes] to file %s!\n", width * height * 3, filename);
130 free(data);
131 return -1;
132 }
133 free(data);
134 fclose(file);
135
136#ifdef DEBUG
137 printf("Save Image [file: %s, size: %d bytes, resolution: %dx%d]\n", filename, data_size, width, height);
138#endif
139
140 return 0;
141}

Referenced by perform_decode().

◆ dxt_init()

int dxt_init ( )

Initialize DXT

Returns
0 if succeeds, otherwise nonzero

Copyright (c) 2011, Martin Srom All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Documented at declaration

Definition at line 32 of file dxt_common.c.

33{
34 int argc = 0;
35 glutInit(&argc, NULL);
36 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
37 glutCreateWindow("DXT");
38 glutHideWindow();
39 glewInit();
40
41 int result = 0;
42
43#define CHECK_EXTENSION(extension) \
44 if ( !glewIsSupported(extension) ) { \
45 fprintf(stderr, "OpenGL extension '%s' is missing!\n", extension); \
46 result = -1; \
47 } \
48
49 CHECK_EXTENSION("GL_VERSION_2_0");
50 CHECK_EXTENSION("GL_ARB_vertex_program");
51 CHECK_EXTENSION("GL_ARB_fragment_program");
52 CHECK_EXTENSION("GL_EXT_gpu_shader4");
53 CHECK_EXTENSION("GL_EXT_framebuffer_object");
54 CHECK_EXTENSION("GL_ARB_texture_compression");
55 CHECK_EXTENSION("GL_EXT_texture_compression_s3tc");
56 CHECK_EXTENSION("GL_EXT_texture_integer");
57
58 printf("Graphic Card: %s\n", glGetString(GL_RENDERER));
59 printf("OpenGL version: %s\n", glGetString(GL_VERSION));
60 printf("GLSL version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
61
62 return result;
63}
#define CHECK_EXTENSION(extension)

References CHECK_EXTENSION.

Referenced by main().