James Zern | ad1e163 | 2012-01-06 14:49:06 -0800 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 2 | // |
| 3 | // This code is licensed under the same terms as WebM: |
| 4 | // Software License Agreement: http://www.webmproject.org/license/software/ |
| 5 | // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
| 6 | // ----------------------------------------------------------------------------- |
| 7 | // |
| 8 | // Simple WebP file viewer. |
| 9 | // |
| 10 | // Compiling on linux: |
| 11 | // sudo apt-get install libglut3-dev mesa-common-dev |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 12 | // gcc -o vwebp vwebp.c -O3 -lwebp -lwebpmux -lglut -lGL -lpthread -lm |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 13 | // Compiling on Mac + XCode: |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 14 | // gcc -o vwebp vwebp.c -lwebp -lwebpmux -framework GLUT -framework OpenGL |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 15 | // |
| 16 | // Author: Skal (pascal.massimino@gmail.com) |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | |
| 22 | #include "webp/decode.h" |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 23 | #include "webp/mux.h" |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 24 | |
| 25 | #ifdef __APPLE__ |
| 26 | #include <GLUT/glut.h> |
| 27 | #else |
| 28 | #include <GL/glut.h> |
| 29 | #ifdef FREEGLUT |
| 30 | #include <GL/freeglut.h> |
| 31 | #endif |
| 32 | #endif |
| 33 | |
James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 34 | #include "./example_util.h" |
| 35 | |
James Zern | 9117954 | 2011-12-16 19:30:33 -0800 | [diff] [blame] | 36 | #ifdef _MSC_VER |
| 37 | #define snprintf _snprintf |
| 38 | #endif |
| 39 | |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 40 | static void Help(void); |
| 41 | |
| 42 | // Unfortunate global variables. Gathered into a struct for comfort. |
| 43 | static struct { |
| 44 | int has_animation; |
| 45 | int done; |
| 46 | int decoding_error; |
| 47 | int print_info; |
| 48 | |
| 49 | uint32_t flags; |
Urvang Joshi | 6808e69 | 2012-07-06 11:35:36 +0530 | [diff] [blame] | 50 | int loop_count; |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 51 | int frame_num; |
| 52 | int frame_max; |
| 53 | |
| 54 | const char* file_name; |
| 55 | WebPData data; |
| 56 | WebPMux* mux; |
| 57 | WebPDecoderConfig* config; |
| 58 | const WebPDecBuffer* pic; |
| 59 | } kParams = { |
| 60 | 0, 0, 0, 0, // has_animation, ... |
| 61 | 0, 1, 1, 0, // flags, ... |
| 62 | NULL, { NULL, 0 }, // file_name, ... |
| 63 | NULL, NULL, NULL // mux, ... |
| 64 | }; |
| 65 | |
| 66 | static void ClearPreviousPic(void) { |
| 67 | WebPFreeDecBuffer((WebPDecBuffer*)kParams.pic); |
| 68 | kParams.pic = NULL; |
| 69 | } |
| 70 | |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 71 | static void ClearParams(void) { |
| 72 | ClearPreviousPic(); |
Urvang Joshi | f3bab8e | 2012-06-07 17:19:02 +0530 | [diff] [blame] | 73 | WebPDataClear(&kParams.data); |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 74 | WebPMuxDelete(kParams.mux); |
| 75 | kParams.mux = NULL; |
| 76 | } |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 77 | |
| 78 | //------------------------------------------------------------------------------ |
| 79 | // Callbacks |
| 80 | |
| 81 | static void HandleKey(unsigned char key, int pos_x, int pos_y) { |
| 82 | (void)pos_x; |
| 83 | (void)pos_y; |
| 84 | if (key == 'q' || key == 'Q' || key == 27 /* Esc */) { |
| 85 | #ifdef FREEGLUT |
| 86 | glutLeaveMainLoop(); |
| 87 | #else |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 88 | ClearParams(); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 89 | exit(0); |
| 90 | #endif |
| 91 | } else if (key == 'i') { |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 92 | kParams.print_info = 1 - kParams.print_info; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 93 | glutPostRedisplay(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static void HandleReshape(int width, int height) { |
| 98 | // TODO(skal): proper handling of resize, esp. for large pictures. |
| 99 | // + key control of the zoom. |
| 100 | glViewport(0, 0, width, height); |
| 101 | glMatrixMode(GL_PROJECTION); |
| 102 | glLoadIdentity(); |
| 103 | glMatrixMode(GL_MODELVIEW); |
| 104 | glLoadIdentity(); |
| 105 | } |
| 106 | |
| 107 | static void PrintString(const char* const text) { |
| 108 | void* const font = GLUT_BITMAP_9_BY_15; |
| 109 | int i; |
| 110 | for (i = 0; text[i]; ++i) { |
| 111 | glutBitmapCharacter(font, text[i]); |
| 112 | } |
| 113 | } |
| 114 | |
James Zern | a73b897 | 2012-07-09 23:01:52 -0700 | [diff] [blame] | 115 | static void DrawCheckerBoard(void) { |
| 116 | const int square_size = 8; // must be a power of 2 |
| 117 | int x, y; |
| 118 | GLint viewport[4]; // x, y, width, height |
| 119 | |
| 120 | glPushMatrix(); |
| 121 | |
| 122 | glGetIntegerv(GL_VIEWPORT, viewport); |
| 123 | // shift to integer coordinates with (0,0) being top-left. |
| 124 | glOrtho(0, viewport[2], viewport[3], 0, -1, 1); |
| 125 | for (y = 0; y < viewport[3]; y += square_size) { |
| 126 | for (x = 0; x < viewport[2]; x += square_size) { |
| 127 | const GLubyte color = 128 + 64 * (!((x + y) & square_size)); |
| 128 | glColor3ub(color, color, color); |
| 129 | glRecti(x, y, x + square_size, y + square_size); |
| 130 | } |
| 131 | } |
| 132 | glPopMatrix(); |
| 133 | } |
| 134 | |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 135 | static void HandleDisplay(void) { |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 136 | const WebPDecBuffer* pic = kParams.pic; |
| 137 | if (pic == NULL) return; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 138 | glClear(GL_COLOR_BUFFER_BIT); |
| 139 | glPushMatrix(); |
| 140 | glPixelZoom(1, -1); |
| 141 | glRasterPos2f(-1, 1); |
| 142 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 143 | glPixelStorei(GL_UNPACK_ROW_LENGTH, pic->u.RGBA.stride / 4); |
James Zern | a73b897 | 2012-07-09 23:01:52 -0700 | [diff] [blame] | 144 | DrawCheckerBoard(); |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 145 | glDrawPixels(pic->width, pic->height, |
| 146 | GL_RGBA, GL_UNSIGNED_BYTE, |
| 147 | (GLvoid*)pic->u.RGBA.rgba); |
| 148 | if (kParams.print_info) { |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 149 | char tmp[32]; |
| 150 | |
James Zern | b35c07d | 2012-07-09 22:36:58 -0700 | [diff] [blame] | 151 | glColor4f(0.0, 0.0, 0.0, 1.0); |
James Zern | 9117954 | 2011-12-16 19:30:33 -0800 | [diff] [blame] | 152 | glRasterPos2f(-0.95f, 0.90f); |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 153 | PrintString(kParams.file_name); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 154 | |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 155 | snprintf(tmp, sizeof(tmp), "Dimension:%d x %d", pic->width, pic->height); |
James Zern | b35c07d | 2012-07-09 22:36:58 -0700 | [diff] [blame] | 156 | glColor4f(0.0, 0.0, 0.0, 1.0); |
James Zern | 9117954 | 2011-12-16 19:30:33 -0800 | [diff] [blame] | 157 | glRasterPos2f(-0.95f, 0.80f); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 158 | PrintString(tmp); |
| 159 | } |
James Zern | a73b897 | 2012-07-09 23:01:52 -0700 | [diff] [blame] | 160 | glPopMatrix(); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 161 | glFlush(); |
| 162 | } |
| 163 | |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 164 | static void StartDisplay(const WebPDecBuffer* const pic) { |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 165 | glutInitDisplayMode(GLUT_RGBA); |
| 166 | glutInitWindowSize(pic->width, pic->height); |
| 167 | glutCreateWindow("WebP viewer"); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 168 | glutDisplayFunc(HandleDisplay); |
| 169 | glutIdleFunc(NULL); |
| 170 | glutKeyboardFunc(HandleKey); |
Urvang Joshi | 0822010 | 2012-06-20 11:18:35 -0700 | [diff] [blame] | 171 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 172 | glEnable(GL_BLEND); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 173 | glClearColor(0.0, 0.0, 0.0, 0.0); |
| 174 | HandleReshape(pic->width, pic->height); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | //------------------------------------------------------------------------------ |
| 178 | // File decoding |
| 179 | |
Urvang Joshi | 6808e69 | 2012-07-06 11:35:36 +0530 | [diff] [blame] | 180 | static int Decode(const int frame_number, int* const duration) { |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 181 | WebPDecoderConfig* const config = kParams.config; |
| 182 | WebPData *data, image_data; |
Urvang Joshi | 6808e69 | 2012-07-06 11:35:36 +0530 | [diff] [blame] | 183 | int x_off = 0, y_off = 0; |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 184 | WebPDecBuffer* const output_buffer = &config->output; |
| 185 | int ok = 0; |
| 186 | |
| 187 | ClearPreviousPic(); |
| 188 | if (kParams.has_animation) { |
Urvang Joshi | b74ed6e | 2012-06-20 10:59:40 -0700 | [diff] [blame] | 189 | if (WebPMuxGetFrame(kParams.mux, frame_number, &image_data, |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 190 | &x_off, &y_off, duration) != WEBP_MUX_OK) { |
| 191 | goto end; |
| 192 | } |
| 193 | if (x_off != 0 || y_off != 0) { |
| 194 | fprintf(stderr, |
Pascal Massimino | 3927ff3 | 2012-05-09 01:57:15 -0700 | [diff] [blame] | 195 | "Frame offsets not yet supported! Forcing offset to 0,0\n"); |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 196 | x_off = y_off = 0; |
| 197 | } |
| 198 | data = &image_data; |
| 199 | } else { |
| 200 | data = &kParams.data; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | output_buffer->colorspace = MODE_RGBA; |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 204 | ok = (WebPDecode(data->bytes_, data->size_, config) == VP8_STATUS_OK); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 205 | |
| 206 | end: |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 207 | if (!ok) { |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 208 | fprintf(stderr, "Decoding of frame #%d failed!\n", frame_number); |
| 209 | } else { |
| 210 | kParams.pic = output_buffer; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 211 | } |
| 212 | return ok; |
| 213 | } |
| 214 | |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 215 | static void decode_callback(int what) { |
| 216 | if (what == 0 && !kParams.done) { |
Urvang Joshi | 6808e69 | 2012-07-06 11:35:36 +0530 | [diff] [blame] | 217 | int duration = 0; |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 218 | if (kParams.mux != NULL) { |
| 219 | if (!Decode(kParams.frame_num, &duration)) { |
| 220 | kParams.decoding_error = 1; |
| 221 | kParams.done = 1; |
| 222 | } else { |
| 223 | ++kParams.frame_num; |
| 224 | if (kParams.frame_num > kParams.frame_max) { |
| 225 | kParams.frame_num = 1; |
| 226 | --kParams.loop_count; |
| 227 | kParams.done = (kParams.loop_count == 0); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | glutPostRedisplay(); |
| 232 | glutTimerFunc(duration, decode_callback, what); |
| 233 | } |
| 234 | } |
| 235 | |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 236 | //------------------------------------------------------------------------------ |
| 237 | // Main |
| 238 | |
| 239 | static void Help(void) { |
| 240 | printf("Usage: vwebp in_file [options]\n\n" |
| 241 | "Decodes the WebP image file and visualize it using OpenGL\n" |
| 242 | "Options are:\n" |
| 243 | " -version .... print version number and exit.\n" |
| 244 | " -nofancy ..... don't use the fancy YUV420 upscaler.\n" |
| 245 | " -nofilter .... disable in-loop filtering.\n" |
| 246 | " -mt .......... use multi-threading\n" |
| 247 | " -crop <x> <y> <w> <h> ... crop output with the given rectangle\n" |
| 248 | " -scale <w> <h> .......... scale the output (*after* any cropping)\n" |
| 249 | " -h ....... this help message.\n" |
| 250 | ); |
| 251 | } |
| 252 | |
| 253 | int main(int argc, char *argv[]) { |
| 254 | WebPDecoderConfig config; |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 255 | WebPMuxError mux_err; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 256 | int c; |
| 257 | |
| 258 | if (!WebPInitDecoderConfig(&config)) { |
| 259 | fprintf(stderr, "Library version mismatch!\n"); |
| 260 | return -1; |
| 261 | } |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 262 | kParams.config = &config; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 263 | |
| 264 | for (c = 1; c < argc; ++c) { |
| 265 | if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { |
| 266 | Help(); |
| 267 | return 0; |
| 268 | } else if (!strcmp(argv[c], "-nofancy")) { |
| 269 | config.options.no_fancy_upsampling = 1; |
| 270 | } else if (!strcmp(argv[c], "-nofilter")) { |
| 271 | config.options.bypass_filtering = 1; |
| 272 | } else if (!strcmp(argv[c], "-version")) { |
| 273 | const int version = WebPGetDecoderVersion(); |
| 274 | printf("%d.%d.%d\n", |
| 275 | (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff); |
| 276 | return 0; |
| 277 | } else if (!strcmp(argv[c], "-mt")) { |
| 278 | config.options.use_threads = 1; |
| 279 | } else if (!strcmp(argv[c], "-crop") && c < argc - 4) { |
| 280 | config.options.use_cropping = 1; |
| 281 | config.options.crop_left = strtol(argv[++c], NULL, 0); |
| 282 | config.options.crop_top = strtol(argv[++c], NULL, 0); |
| 283 | config.options.crop_width = strtol(argv[++c], NULL, 0); |
| 284 | config.options.crop_height = strtol(argv[++c], NULL, 0); |
| 285 | } else if (!strcmp(argv[c], "-scale") && c < argc - 2) { |
| 286 | config.options.use_scaling = 1; |
| 287 | config.options.scaled_width = strtol(argv[++c], NULL, 0); |
| 288 | config.options.scaled_height = strtol(argv[++c], NULL, 0); |
| 289 | } else if (argv[c][0] == '-') { |
| 290 | printf("Unknown option '%s'\n", argv[c]); |
| 291 | Help(); |
| 292 | return -1; |
| 293 | } else { |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 294 | kParams.file_name = argv[c]; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
James Zern | 061263a | 2012-05-11 16:00:57 -0700 | [diff] [blame] | 298 | if (kParams.file_name == NULL) { |
| 299 | printf("missing input file!!\n"); |
| 300 | Help(); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | if (!ExUtilReadFile(kParams.file_name, |
| 305 | &kParams.data.bytes_, &kParams.data.size_)) { |
| 306 | goto Error; |
| 307 | } |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 308 | |
Urvang Joshi | f3bab8e | 2012-06-07 17:19:02 +0530 | [diff] [blame] | 309 | kParams.mux = WebPMuxCreate(&kParams.data, 0); |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 310 | if (kParams.mux == NULL) { |
| 311 | fprintf(stderr, "Could not create demuxing object!\n"); |
| 312 | goto Error; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 315 | mux_err = WebPMuxGetFeatures(kParams.mux, &kParams.flags); |
| 316 | if (mux_err != WEBP_MUX_OK) { |
| 317 | goto Error; |
| 318 | } |
| 319 | if (kParams.flags & TILE_FLAG) { |
| 320 | fprintf(stderr, "Tiling is not supported for now!\n"); |
| 321 | goto Error; |
| 322 | } |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 323 | |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 324 | kParams.has_animation = !!(kParams.flags & ANIMATION_FLAG); |
| 325 | |
| 326 | if (kParams.has_animation) { |
| 327 | mux_err = WebPMuxGetLoopCount(kParams.mux, &kParams.loop_count); |
| 328 | if (mux_err != WEBP_MUX_OK && mux_err != WEBP_MUX_NOT_FOUND) { |
| 329 | goto Error; |
| 330 | } |
Urvang Joshi | fbdcb7e | 2012-06-11 12:24:45 +0530 | [diff] [blame] | 331 | mux_err = WebPMuxNumChunks(kParams.mux, WEBP_CHUNK_IMAGE, |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 332 | &kParams.frame_max); |
Pascal Massimino | 3927ff3 | 2012-05-09 01:57:15 -0700 | [diff] [blame] | 333 | if (mux_err != WEBP_MUX_OK) { |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 334 | goto Error; |
| 335 | } |
| 336 | printf("VP8X: Found %d images in file (loop count = %d)\n", |
| 337 | kParams.frame_max, kParams.loop_count); |
| 338 | } |
| 339 | |
| 340 | // Decode first frame |
| 341 | { |
Urvang Joshi | 6808e69 | 2012-07-06 11:35:36 +0530 | [diff] [blame] | 342 | int duration; |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 343 | if (!Decode(1, &duration)) goto Error; |
| 344 | } |
| 345 | |
| 346 | // Start display (and timer) |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 347 | glutInit(&argc, argv); |
James Zern | 880fd98 | 2012-05-25 14:53:46 -0700 | [diff] [blame] | 348 | #ifdef FREEGLUT |
| 349 | glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); |
| 350 | #endif |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 351 | StartDisplay(kParams.pic); |
| 352 | if (kParams.has_animation) glutTimerFunc(0, decode_callback, 0); |
| 353 | glutMainLoop(); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 354 | |
| 355 | // Should only be reached when using FREEGLUT: |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 356 | ClearParams(); |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 357 | return 0; |
Pascal Massimino | 861a5b7 | 2012-05-09 00:41:12 -0700 | [diff] [blame] | 358 | |
| 359 | Error: |
| 360 | ClearParams(); |
| 361 | return -1; |
Pascal Massimino | 7937b40 | 2011-12-13 14:02:04 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | //------------------------------------------------------------------------------ |