UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
dxt_common.c File Reference
#include "dxt_common.h"
#include "dxt_util.h"
Include dependency graph for dxt_common.c:

Go to the source code of this file.

Macros

#define CHECK_EXTENSION(extension)
 

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

◆ CHECK_EXTENSION

#define CHECK_EXTENSION ( extension)
Value:
if ( !glewIsSupported(extension) ) { \
fprintf(stderr, "OpenGL extension '%s' is missing!\n", extension); \
result = -1; \
} \

Referenced by dxt_init().

Function Documentation

◆ dxt_image_compressed_destroy()

int dxt_image_compressed_destroy ( unsigned char * image_compressed)

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 )

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 )

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)

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 )

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 )

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 ( )

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().