blob: 312649b988acbe12e72eeb040a5f64e4570e72a4 [file] [log] [blame]
James Zernad1e1632012-01-06 14:49:06 -08001// Copyright 2011 Google Inc. All Rights Reserved.
Pascal Massimino7937b402011-12-13 14:02:04 -08002//
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:
James Zernddfee5d2013-03-07 19:31:27 -080011// sudo apt-get install freeglut3-dev mesa-common-dev
Pascal Massimino861a5b72012-05-09 00:41:12 -070012// gcc -o vwebp vwebp.c -O3 -lwebp -lwebpmux -lglut -lGL -lpthread -lm
Pascal Massimino7937b402011-12-13 14:02:04 -080013// Compiling on Mac + XCode:
Pascal Massimino861a5b72012-05-09 00:41:12 -070014// gcc -o vwebp vwebp.c -lwebp -lwebpmux -framework GLUT -framework OpenGL
Pascal Massimino7937b402011-12-13 14:02:04 -080015//
16// Author: Skal (pascal.massimino@gmail.com)
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
Pascal Massimino7937b402011-12-13 14:02:04 -080022#ifdef __APPLE__
23#include <GLUT/glut.h>
24#else
25#include <GL/glut.h>
26#ifdef FREEGLUT
27#include <GL/freeglut.h>
28#endif
29#endif
30
James Zernddfee5d2013-03-07 19:31:27 -080031#ifdef WEBP_HAVE_QCMS
32#include <qcms.h>
33#endif
34
35#include "webp/decode.h"
36#include "webp/demux.h"
37
James Zern061263a2012-05-11 16:00:57 -070038#include "./example_util.h"
39
James Zern91179542011-12-16 19:30:33 -080040#ifdef _MSC_VER
41#define snprintf _snprintf
42#endif
43
Pascal Massimino861a5b72012-05-09 00:41:12 -070044static void Help(void);
45
46// Unfortunate global variables. Gathered into a struct for comfort.
47static struct {
48 int has_animation;
James Zernddfee5d2013-03-07 19:31:27 -080049 int has_color_profile;
Pascal Massimino861a5b72012-05-09 00:41:12 -070050 int done;
51 int decoding_error;
52 int print_info;
James Zernddfee5d2013-03-07 19:31:27 -080053 int use_color_profile;
Pascal Massimino861a5b72012-05-09 00:41:12 -070054
skal68f282f2012-11-15 09:15:04 +010055 int canvas_width, canvas_height;
Urvang Joshi6808e692012-07-06 11:35:36 +053056 int loop_count;
skal68f282f2012-11-15 09:15:04 +010057 uint32_t bg_color;
Pascal Massimino861a5b72012-05-09 00:41:12 -070058
59 const char* file_name;
60 WebPData data;
Pascal Massimino861a5b72012-05-09 00:41:12 -070061 WebPDecoderConfig* config;
62 const WebPDecBuffer* pic;
James Zernd7a5ac82012-09-26 23:44:59 -070063 WebPDemuxer* dmux;
64 WebPIterator frameiter;
James Zernddfee5d2013-03-07 19:31:27 -080065 WebPChunkIterator iccp;
James Zernd7a5ac82012-09-26 23:44:59 -070066} kParams;
Pascal Massimino861a5b72012-05-09 00:41:12 -070067
68static void ClearPreviousPic(void) {
69 WebPFreeDecBuffer((WebPDecBuffer*)kParams.pic);
70 kParams.pic = NULL;
71}
72
Pascal Massimino861a5b72012-05-09 00:41:12 -070073static void ClearParams(void) {
74 ClearPreviousPic();
Urvang Joshif3bab8e2012-06-07 17:19:02 +053075 WebPDataClear(&kParams.data);
James Zernd7a5ac82012-09-26 23:44:59 -070076 WebPDemuxReleaseIterator(&kParams.frameiter);
James Zernddfee5d2013-03-07 19:31:27 -080077 WebPDemuxReleaseChunkIterator(&kParams.iccp);
James Zernd7a5ac82012-09-26 23:44:59 -070078 WebPDemuxDelete(kParams.dmux);
79 kParams.dmux = NULL;
Pascal Massimino861a5b72012-05-09 00:41:12 -070080}
Pascal Massimino7937b402011-12-13 14:02:04 -080081
James Zernddfee5d2013-03-07 19:31:27 -080082// -----------------------------------------------------------------------------
83// Color profile handling
84static int ApplyColorProfile(const WebPData* const profile,
85 WebPDecBuffer* const rgba) {
86#ifdef WEBP_HAVE_QCMS
87 int i, ok = 0;
88 uint8_t* line;
89 uint8_t major_revision;
90 qcms_profile* input_profile = NULL;
91 qcms_profile* output_profile = NULL;
92 qcms_transform* transform = NULL;
93 const qcms_data_type input_type = QCMS_DATA_RGBA_8;
94 const qcms_data_type output_type = QCMS_DATA_RGBA_8;
95 const qcms_intent intent = QCMS_INTENT_DEFAULT;
96
97 if (profile == NULL || rgba == NULL) return 0;
98 if (profile->bytes == NULL || profile->size < 10) return 1;
99 major_revision = profile->bytes[8];
100
101 qcms_enable_iccv4();
102 input_profile = qcms_profile_from_memory(profile->bytes, profile->size);
103 // qcms_profile_is_bogus() is broken with ICCv4.
104 if (input_profile == NULL ||
105 (major_revision < 4 && qcms_profile_is_bogus(input_profile))) {
106 fprintf(stderr, "Color profile is bogus!\n");
107 goto Error;
108 }
109
110 output_profile = qcms_profile_sRGB();
111 if (output_profile == NULL) {
112 fprintf(stderr, "Error creating output color profile!\n");
113 goto Error;
114 }
115
116 qcms_profile_precache_output_transform(output_profile);
117 transform = qcms_transform_create(input_profile, input_type,
118 output_profile, output_type,
119 intent);
120 if (transform == NULL) {
121 fprintf(stderr, "Error creating color transform!\n");
122 goto Error;
123 }
124
125 line = rgba->u.RGBA.rgba;
126 for (i = 0; i < rgba->height; ++i, line += rgba->u.RGBA.stride) {
127 qcms_transform_data(transform, line, line, rgba->width);
128 }
129 ok = 1;
130
131 Error:
132 if (input_profile != NULL) qcms_profile_release(input_profile);
133 if (output_profile != NULL) qcms_profile_release(output_profile);
134 if (transform != NULL) qcms_transform_release(transform);
135 return ok;
136#else
137 (void)profile;
138 (void)rgba;
139 return 1;
140#endif // WEBP_HAVE_QCMS
141}
142
143//------------------------------------------------------------------------------
144// File decoding
145
146static int Decode(void) { // Fills kParams.frameiter
147 const WebPIterator* const iter = &kParams.frameiter;
148 WebPDecoderConfig* const config = kParams.config;
149 WebPDecBuffer* const output_buffer = &config->output;
150 int ok = 0;
151
152 ClearPreviousPic();
153 output_buffer->colorspace = MODE_RGBA;
154 ok = (WebPDecode(iter->fragment.bytes, iter->fragment.size,
155 config) == VP8_STATUS_OK);
156 if (!ok) {
157 fprintf(stderr, "Decoding of frame #%d failed!\n", iter->frame_num);
158 } else {
159 kParams.pic = output_buffer;
160 if (kParams.use_color_profile) {
161 ok = ApplyColorProfile(&kParams.iccp.chunk, output_buffer);
162 if (!ok) {
163 fprintf(stderr, "Applying color profile to frame #%d failed!\n",
164 iter->frame_num);
165 }
166 }
167 }
168 return ok;
169}
170
171static void decode_callback(int what) {
172 if (what == 0 && !kParams.done) {
173 int duration = 0;
174 if (kParams.dmux != NULL) {
175 WebPIterator* const iter = &kParams.frameiter;
176 if (!WebPDemuxNextFrame(iter)) {
177 WebPDemuxReleaseIterator(iter);
178 if (WebPDemuxGetFrame(kParams.dmux, 1, iter)) {
179 --kParams.loop_count;
180 kParams.done = (kParams.loop_count == 0);
181 } else {
182 kParams.decoding_error = 1;
183 kParams.done = 1;
184 return;
185 }
186 }
187 duration = iter->duration;
188 }
189 if (!Decode()) {
190 kParams.decoding_error = 1;
191 kParams.done = 1;
192 } else {
193 glutPostRedisplay();
194 glutTimerFunc(duration, decode_callback, what);
195 }
196 }
197}
198
Pascal Massimino7937b402011-12-13 14:02:04 -0800199//------------------------------------------------------------------------------
200// Callbacks
201
202static void HandleKey(unsigned char key, int pos_x, int pos_y) {
203 (void)pos_x;
204 (void)pos_y;
205 if (key == 'q' || key == 'Q' || key == 27 /* Esc */) {
206#ifdef FREEGLUT
207 glutLeaveMainLoop();
208#else
Pascal Massimino861a5b72012-05-09 00:41:12 -0700209 ClearParams();
Pascal Massimino7937b402011-12-13 14:02:04 -0800210 exit(0);
211#endif
James Zernddfee5d2013-03-07 19:31:27 -0800212 } else if (key == 'c') {
213 if (kParams.has_color_profile && !kParams.decoding_error) {
214 kParams.use_color_profile = 1 - kParams.use_color_profile;
215
216 if (kParams.has_animation) {
217 // Restart the completed animation to pickup the color profile change.
218 if (kParams.done && kParams.loop_count == 0) {
219 kParams.loop_count =
220 (int)WebPDemuxGetI(kParams.dmux, WEBP_FF_LOOP_COUNT) + 1;
221 kParams.done = 0;
222 // Start the decode loop immediately.
223 glutTimerFunc(0, decode_callback, 0);
224 }
225 } else {
226 Decode();
227 glutPostRedisplay();
228 }
229 }
Pascal Massimino7937b402011-12-13 14:02:04 -0800230 } else if (key == 'i') {
Pascal Massimino861a5b72012-05-09 00:41:12 -0700231 kParams.print_info = 1 - kParams.print_info;
Pascal Massimino7937b402011-12-13 14:02:04 -0800232 glutPostRedisplay();
233 }
234}
235
236static void HandleReshape(int width, int height) {
237 // TODO(skal): proper handling of resize, esp. for large pictures.
238 // + key control of the zoom.
239 glViewport(0, 0, width, height);
240 glMatrixMode(GL_PROJECTION);
241 glLoadIdentity();
242 glMatrixMode(GL_MODELVIEW);
243 glLoadIdentity();
244}
245
246static void PrintString(const char* const text) {
247 void* const font = GLUT_BITMAP_9_BY_15;
248 int i;
249 for (i = 0; text[i]; ++i) {
250 glutBitmapCharacter(font, text[i]);
251 }
252}
253
skal68f282f2012-11-15 09:15:04 +0100254static float GetColorf(uint32_t color, int shift) {
255 return (color >> shift) / 255.f;
256}
257
James Zerna73b8972012-07-09 23:01:52 -0700258static void DrawCheckerBoard(void) {
259 const int square_size = 8; // must be a power of 2
260 int x, y;
261 GLint viewport[4]; // x, y, width, height
262
263 glPushMatrix();
264
265 glGetIntegerv(GL_VIEWPORT, viewport);
266 // shift to integer coordinates with (0,0) being top-left.
267 glOrtho(0, viewport[2], viewport[3], 0, -1, 1);
268 for (y = 0; y < viewport[3]; y += square_size) {
269 for (x = 0; x < viewport[2]; x += square_size) {
270 const GLubyte color = 128 + 64 * (!((x + y) & square_size));
271 glColor3ub(color, color, color);
272 glRecti(x, y, x + square_size, y + square_size);
273 }
274 }
275 glPopMatrix();
276}
277
Pascal Massimino7937b402011-12-13 14:02:04 -0800278static void HandleDisplay(void) {
skal68f282f2012-11-15 09:15:04 +0100279 const WebPDecBuffer* const pic = kParams.pic;
280 const WebPIterator* const iter = &kParams.frameiter;
skal41a6ced2012-11-15 09:35:01 +0100281 GLfloat xoff, yoff;
Pascal Massimino861a5b72012-05-09 00:41:12 -0700282 if (pic == NULL) return;
Pascal Massimino7937b402011-12-13 14:02:04 -0800283 glPushMatrix();
284 glPixelZoom(1, -1);
skal41a6ced2012-11-15 09:35:01 +0100285 xoff = (GLfloat)(2. * iter->x_offset / kParams.canvas_width);
286 yoff = (GLfloat)(2. * iter->y_offset / kParams.canvas_height);
James Zern013023e2013-03-15 12:17:45 -0700287 glRasterPos2f(-1.f + xoff, 1.f - yoff);
Pascal Massimino7937b402011-12-13 14:02:04 -0800288 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Pascal Massimino861a5b72012-05-09 00:41:12 -0700289 glPixelStorei(GL_UNPACK_ROW_LENGTH, pic->u.RGBA.stride / 4);
skal68f282f2012-11-15 09:15:04 +0100290 if (iter->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND) {
291 glClear(GL_COLOR_BUFFER_BIT); // use clear color
292 }
Pascal Massimino861a5b72012-05-09 00:41:12 -0700293 glDrawPixels(pic->width, pic->height,
294 GL_RGBA, GL_UNSIGNED_BYTE,
295 (GLvoid*)pic->u.RGBA.rgba);
296 if (kParams.print_info) {
Pascal Massimino7937b402011-12-13 14:02:04 -0800297 char tmp[32];
298
James Zern013023e2013-03-15 12:17:45 -0700299 glColor4f(0.90f, 0.0f, 0.90f, 1.0f);
James Zern91179542011-12-16 19:30:33 -0800300 glRasterPos2f(-0.95f, 0.90f);
Pascal Massimino861a5b72012-05-09 00:41:12 -0700301 PrintString(kParams.file_name);
Pascal Massimino7937b402011-12-13 14:02:04 -0800302
Pascal Massimino861a5b72012-05-09 00:41:12 -0700303 snprintf(tmp, sizeof(tmp), "Dimension:%d x %d", pic->width, pic->height);
James Zern013023e2013-03-15 12:17:45 -0700304 glColor4f(0.90f, 0.0f, 0.90f, 1.0f);
James Zern91179542011-12-16 19:30:33 -0800305 glRasterPos2f(-0.95f, 0.80f);
Pascal Massimino7937b402011-12-13 14:02:04 -0800306 PrintString(tmp);
skal68f282f2012-11-15 09:15:04 +0100307 if (iter->x_offset != 0 || iter->y_offset != 0) {
308 snprintf(tmp, sizeof(tmp), " (offset:%d,%d)",
309 iter->x_offset, iter->y_offset);
310 glRasterPos2f(-0.95f, 0.70f);
311 PrintString(tmp);
312 }
Pascal Massimino7937b402011-12-13 14:02:04 -0800313 }
James Zerna73b8972012-07-09 23:01:52 -0700314 glPopMatrix();
Pascal Massimino7937b402011-12-13 14:02:04 -0800315 glFlush();
316}
317
skal68f282f2012-11-15 09:15:04 +0100318static void StartDisplay(void) {
319 const int width = kParams.canvas_width;
320 const int height = kParams.canvas_height;
Pascal Massimino7937b402011-12-13 14:02:04 -0800321 glutInitDisplayMode(GLUT_RGBA);
skal68f282f2012-11-15 09:15:04 +0100322 glutInitWindowSize(width, height);
Pascal Massimino7937b402011-12-13 14:02:04 -0800323 glutCreateWindow("WebP viewer");
Pascal Massimino7937b402011-12-13 14:02:04 -0800324 glutDisplayFunc(HandleDisplay);
325 glutIdleFunc(NULL);
326 glutKeyboardFunc(HandleKey);
Urvang Joshi08220102012-06-20 11:18:35 -0700327 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
328 glEnable(GL_BLEND);
skal68f282f2012-11-15 09:15:04 +0100329 glClearColor(GetColorf(kParams.bg_color, 0),
330 GetColorf(kParams.bg_color, 8),
331 GetColorf(kParams.bg_color, 16),
332 GetColorf(kParams.bg_color, 24));
333 HandleReshape(width, height);
334 glClear(GL_COLOR_BUFFER_BIT);
335 DrawCheckerBoard();
Pascal Massimino7937b402011-12-13 14:02:04 -0800336}
337
338//------------------------------------------------------------------------------
Pascal Massimino7937b402011-12-13 14:02:04 -0800339// Main
340
341static void Help(void) {
342 printf("Usage: vwebp in_file [options]\n\n"
343 "Decodes the WebP image file and visualize it using OpenGL\n"
344 "Options are:\n"
345 " -version .... print version number and exit.\n"
James Zernddfee5d2013-03-07 19:31:27 -0800346 " -noicc ....... don't use the icc profile if present.\n"
Pascal Massimino7937b402011-12-13 14:02:04 -0800347 " -nofancy ..... don't use the fancy YUV420 upscaler.\n"
348 " -nofilter .... disable in-loop filtering.\n"
James Zern03cc23d2013-03-07 19:10:59 -0800349 " -mt .......... use multi-threading.\n"
skal68f282f2012-11-15 09:15:04 +0100350 " -info ........ print info.\n"
Pascal Massimino7937b402011-12-13 14:02:04 -0800351 " -h ....... this help message.\n"
James Zern03cc23d2013-03-07 19:10:59 -0800352 "\n"
353 "Keyboard shortcuts:\n"
James Zernddfee5d2013-03-07 19:31:27 -0800354 " 'c' ................ toggle use of color profile.\n"
James Zern03cc23d2013-03-07 19:10:59 -0800355 " 'i' ................ overlay file information.\n"
356 " 'q' / 'Q' / ESC .... quit.\n"
Pascal Massimino7937b402011-12-13 14:02:04 -0800357 );
358}
359
360int main(int argc, char *argv[]) {
361 WebPDecoderConfig config;
362 int c;
363
364 if (!WebPInitDecoderConfig(&config)) {
365 fprintf(stderr, "Library version mismatch!\n");
366 return -1;
367 }
Pascal Massimino861a5b72012-05-09 00:41:12 -0700368 kParams.config = &config;
James Zernddfee5d2013-03-07 19:31:27 -0800369 kParams.use_color_profile = 1;
Pascal Massimino7937b402011-12-13 14:02:04 -0800370
371 for (c = 1; c < argc; ++c) {
372 if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
373 Help();
374 return 0;
James Zernddfee5d2013-03-07 19:31:27 -0800375 } else if (!strcmp(argv[c], "-noicc")) {
376 kParams.use_color_profile = 0;
Pascal Massimino7937b402011-12-13 14:02:04 -0800377 } else if (!strcmp(argv[c], "-nofancy")) {
378 config.options.no_fancy_upsampling = 1;
379 } else if (!strcmp(argv[c], "-nofilter")) {
380 config.options.bypass_filtering = 1;
skal68f282f2012-11-15 09:15:04 +0100381 } else if (!strcmp(argv[c], "-info")) {
382 kParams.print_info = 1;
Pascal Massimino7937b402011-12-13 14:02:04 -0800383 } else if (!strcmp(argv[c], "-version")) {
Urvang Joshia5042a32013-02-26 14:22:06 -0800384 const int dec_version = WebPGetDecoderVersion();
385 const int dmux_version = WebPGetDemuxVersion();
386 printf("WebP Decoder version: %d.%d.%d\nWebP Demux version: %d.%d.%d\n",
387 (dec_version >> 16) & 0xff, (dec_version >> 8) & 0xff,
388 dec_version & 0xff, (dmux_version >> 16) & 0xff,
389 (dmux_version >> 8) & 0xff, dmux_version & 0xff);
Pascal Massimino7937b402011-12-13 14:02:04 -0800390 return 0;
391 } else if (!strcmp(argv[c], "-mt")) {
392 config.options.use_threads = 1;
Pascal Massimino7937b402011-12-13 14:02:04 -0800393 } else if (argv[c][0] == '-') {
394 printf("Unknown option '%s'\n", argv[c]);
395 Help();
396 return -1;
397 } else {
Pascal Massimino861a5b72012-05-09 00:41:12 -0700398 kParams.file_name = argv[c];
Pascal Massimino7937b402011-12-13 14:02:04 -0800399 }
400 }
401
James Zern061263a2012-05-11 16:00:57 -0700402 if (kParams.file_name == NULL) {
403 printf("missing input file!!\n");
404 Help();
405 return 0;
406 }
407
408 if (!ExUtilReadFile(kParams.file_name,
Urvang Joshia0770722012-10-30 14:54:46 -0700409 &kParams.data.bytes, &kParams.data.size)) {
James Zern061263a2012-05-11 16:00:57 -0700410 goto Error;
411 }
Pascal Massimino861a5b72012-05-09 00:41:12 -0700412
James Zernd7a5ac82012-09-26 23:44:59 -0700413 kParams.dmux = WebPDemux(&kParams.data);
414 if (kParams.dmux == NULL) {
Pascal Massimino861a5b72012-05-09 00:41:12 -0700415 fprintf(stderr, "Could not create demuxing object!\n");
416 goto Error;
Pascal Massimino7937b402011-12-13 14:02:04 -0800417 }
418
Urvang Joshia00a3da2012-10-31 17:49:15 -0700419 if (WebPDemuxGetI(kParams.dmux, WEBP_FF_FORMAT_FLAGS) & FRAGMENTS_FLAG) {
420 fprintf(stderr, "Image fragments are not supported for now!\n");
Pascal Massimino861a5b72012-05-09 00:41:12 -0700421 goto Error;
422 }
skal68f282f2012-11-15 09:15:04 +0100423 kParams.canvas_width = WebPDemuxGetI(kParams.dmux, WEBP_FF_CANVAS_WIDTH);
424 kParams.canvas_height = WebPDemuxGetI(kParams.dmux, WEBP_FF_CANVAS_HEIGHT);
425 if (kParams.print_info) {
426 printf("Canvas: %d x %d\n", kParams.canvas_width, kParams.canvas_height);
427 }
Pascal Massimino7937b402011-12-13 14:02:04 -0800428
James Zernddfee5d2013-03-07 19:31:27 -0800429 memset(&kParams.iccp, 0, sizeof(kParams.iccp));
430 kParams.has_color_profile =
431 !!(WebPDemuxGetI(kParams.dmux, WEBP_FF_FORMAT_FLAGS) & ICCP_FLAG);
432 if (kParams.has_color_profile) {
433#ifdef WEBP_HAVE_QCMS
434 if (!WebPDemuxGetChunk(kParams.dmux, "ICCP", 1, &kParams.iccp)) goto Error;
435 printf("VP8X: Found color profile\n");
436#else
437 fprintf(stderr, "Warning: color profile present, but qcms is unavailable!\n"
438 "Build libqcms from Mozilla or Chromium and define WEBP_HAVE_QCMS "
439 "before building.\n");
440#endif
441 }
442
James Zernd7a5ac82012-09-26 23:44:59 -0700443 if (!WebPDemuxGetFrame(kParams.dmux, 1, &kParams.frameiter)) goto Error;
Pascal Massimino861a5b72012-05-09 00:41:12 -0700444
Urvang Joshia0770722012-10-30 14:54:46 -0700445 kParams.has_animation = (kParams.frameiter.num_frames > 1);
James Zernd7a5ac82012-09-26 23:44:59 -0700446 kParams.loop_count = (int)WebPDemuxGetI(kParams.dmux, WEBP_FF_LOOP_COUNT);
skal68f282f2012-11-15 09:15:04 +0100447 kParams.bg_color = WebPDemuxGetI(kParams.dmux, WEBP_FF_BACKGROUND_COLOR);
James Zernd7a5ac82012-09-26 23:44:59 -0700448 printf("VP8X: Found %d images in file (loop count = %d)\n",
Urvang Joshia0770722012-10-30 14:54:46 -0700449 kParams.frameiter.num_frames, kParams.loop_count);
Pascal Massimino861a5b72012-05-09 00:41:12 -0700450
451 // Decode first frame
skal68f282f2012-11-15 09:15:04 +0100452 if (!Decode()) goto Error;
453
454 // Position iterator to last frame. Next call to HandleDisplay will wrap over.
455 // We take this into account by bumping up loop_count.
456 WebPDemuxGetFrame(kParams.dmux, 0, &kParams.frameiter);
457 if (kParams.loop_count) ++kParams.loop_count;
Pascal Massimino861a5b72012-05-09 00:41:12 -0700458
459 // Start display (and timer)
Pascal Massimino7937b402011-12-13 14:02:04 -0800460 glutInit(&argc, argv);
James Zern880fd982012-05-25 14:53:46 -0700461#ifdef FREEGLUT
462 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
463#endif
skal68f282f2012-11-15 09:15:04 +0100464 StartDisplay();
465
Pascal Massimino861a5b72012-05-09 00:41:12 -0700466 if (kParams.has_animation) glutTimerFunc(0, decode_callback, 0);
467 glutMainLoop();
Pascal Massimino7937b402011-12-13 14:02:04 -0800468
469 // Should only be reached when using FREEGLUT:
Pascal Massimino861a5b72012-05-09 00:41:12 -0700470 ClearParams();
Pascal Massimino7937b402011-12-13 14:02:04 -0800471 return 0;
Pascal Massimino861a5b72012-05-09 00:41:12 -0700472
473 Error:
474 ClearParams();
475 return -1;
Pascal Massimino7937b402011-12-13 14:02:04 -0800476}
477
478//------------------------------------------------------------------------------