2012-01-06 23:49:06 +01:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
2011-12-13 23:02:04 +01:00
|
|
|
//
|
2013-06-07 08:05:58 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
2011-12-13 23:02:04 +01:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
2013-04-02 01:10:35 +02:00
|
|
|
// Simple OpenGL-based WebP file viewer.
|
2011-12-13 23:02:04 +01:00
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
2013-05-01 23:47:56 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-06-11 02:53:44 +02:00
|
|
|
#include "webp/config.h"
|
2013-05-01 23:47:56 +02:00
|
|
|
#endif
|
2011-12-13 23:02:04 +01:00
|
|
|
|
2016-09-30 09:15:44 +02:00
|
|
|
#if defined(__unix__) || defined(__CYGWIN__)
|
|
|
|
#define _POSIX_C_SOURCE 200112L // for setenv
|
|
|
|
#endif
|
|
|
|
|
2024-03-19 11:27:58 +01:00
|
|
|
#include <assert.h>
|
2011-12-13 23:02:04 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-09-12 13:03:51 +02:00
|
|
|
#if defined(WEBP_HAVE_GL)
|
|
|
|
|
2013-05-01 23:47:56 +02:00
|
|
|
#if defined(HAVE_GLUT_GLUT_H)
|
2011-12-13 23:02:04 +01:00
|
|
|
#include <GLUT/glut.h>
|
|
|
|
#else
|
|
|
|
#include <GL/glut.h>
|
|
|
|
#ifdef FREEGLUT
|
|
|
|
#include <GL/freeglut.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-03-08 04:31:27 +01:00
|
|
|
#ifdef WEBP_HAVE_QCMS
|
|
|
|
#include <qcms.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "webp/decode.h"
|
|
|
|
#include "webp/demux.h"
|
|
|
|
|
2016-07-22 01:10:05 +02:00
|
|
|
#include "../examples/example_util.h"
|
2016-07-21 03:25:00 +02:00
|
|
|
#include "../imageio/imageio_util.h"
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
#include "./unicode.h"
|
2012-05-12 01:00:57 +02:00
|
|
|
|
2015-04-15 01:36:54 +02:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
2011-12-17 04:30:33 +01:00
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
2012-05-09 09:41:12 +02:00
|
|
|
// Unfortunate global variables. Gathered into a struct for comfort.
|
|
|
|
static struct {
|
|
|
|
int has_animation;
|
2013-03-08 04:31:27 +01:00
|
|
|
int has_color_profile;
|
2012-05-09 09:41:12 +02:00
|
|
|
int done;
|
|
|
|
int decoding_error;
|
|
|
|
int print_info;
|
2016-11-25 15:31:54 +01:00
|
|
|
int only_deltas;
|
2013-03-08 04:31:27 +01:00
|
|
|
int use_color_profile;
|
2018-07-20 12:54:30 +02:00
|
|
|
int draw_anim_background_color;
|
2012-05-09 09:41:12 +02:00
|
|
|
|
2012-11-15 09:15:04 +01:00
|
|
|
int canvas_width, canvas_height;
|
2012-07-06 08:05:36 +02:00
|
|
|
int loop_count;
|
2012-11-15 09:15:04 +01:00
|
|
|
uint32_t bg_color;
|
2012-05-09 09:41:12 +02:00
|
|
|
|
|
|
|
const char* file_name;
|
|
|
|
WebPData data;
|
2013-09-12 09:32:28 +02:00
|
|
|
WebPDecoderConfig config;
|
2012-05-09 09:41:12 +02:00
|
|
|
const WebPDecBuffer* pic;
|
2012-09-27 08:44:59 +02:00
|
|
|
WebPDemuxer* dmux;
|
2013-08-09 23:40:31 +02:00
|
|
|
WebPIterator curr_frame;
|
|
|
|
WebPIterator prev_frame;
|
2013-03-08 04:31:27 +01:00
|
|
|
WebPChunkIterator iccp;
|
2016-09-29 07:30:03 +02:00
|
|
|
int viewport_width, viewport_height;
|
2012-09-27 08:44:59 +02:00
|
|
|
} kParams;
|
2012-05-09 09:41:12 +02:00
|
|
|
|
|
|
|
static void ClearPreviousPic(void) {
|
|
|
|
WebPFreeDecBuffer((WebPDecBuffer*)kParams.pic);
|
|
|
|
kParams.pic = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearParams(void) {
|
|
|
|
ClearPreviousPic();
|
2012-06-07 13:49:02 +02:00
|
|
|
WebPDataClear(&kParams.data);
|
2013-08-09 23:40:31 +02:00
|
|
|
WebPDemuxReleaseIterator(&kParams.curr_frame);
|
|
|
|
WebPDemuxReleaseIterator(&kParams.prev_frame);
|
2013-03-08 04:31:27 +01:00
|
|
|
WebPDemuxReleaseChunkIterator(&kParams.iccp);
|
2012-09-27 08:44:59 +02:00
|
|
|
WebPDemuxDelete(kParams.dmux);
|
|
|
|
kParams.dmux = NULL;
|
2012-05-09 09:41:12 +02:00
|
|
|
}
|
2011-12-13 23:02:04 +01:00
|
|
|
|
2015-02-06 06:09:27 +01:00
|
|
|
// Sets the previous frame to the dimensions of the canvas and has it dispose
|
|
|
|
// to background to cause the canvas to be cleared.
|
|
|
|
static void ClearPreviousFrame(void) {
|
|
|
|
WebPIterator* const prev = &kParams.prev_frame;
|
|
|
|
prev->width = kParams.canvas_width;
|
|
|
|
prev->height = kParams.canvas_height;
|
|
|
|
prev->x_offset = prev->y_offset = 0;
|
|
|
|
prev->dispose_method = WEBP_MUX_DISPOSE_BACKGROUND;
|
|
|
|
}
|
|
|
|
|
2013-03-08 04:31:27 +01:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Color profile handling
|
|
|
|
static int ApplyColorProfile(const WebPData* const profile,
|
|
|
|
WebPDecBuffer* const rgba) {
|
|
|
|
#ifdef WEBP_HAVE_QCMS
|
|
|
|
int i, ok = 0;
|
|
|
|
uint8_t* line;
|
|
|
|
uint8_t major_revision;
|
|
|
|
qcms_profile* input_profile = NULL;
|
|
|
|
qcms_profile* output_profile = NULL;
|
|
|
|
qcms_transform* transform = NULL;
|
|
|
|
const qcms_data_type input_type = QCMS_DATA_RGBA_8;
|
|
|
|
const qcms_data_type output_type = QCMS_DATA_RGBA_8;
|
|
|
|
const qcms_intent intent = QCMS_INTENT_DEFAULT;
|
|
|
|
|
|
|
|
if (profile == NULL || rgba == NULL) return 0;
|
|
|
|
if (profile->bytes == NULL || profile->size < 10) return 1;
|
|
|
|
major_revision = profile->bytes[8];
|
|
|
|
|
|
|
|
qcms_enable_iccv4();
|
|
|
|
input_profile = qcms_profile_from_memory(profile->bytes, profile->size);
|
|
|
|
// qcms_profile_is_bogus() is broken with ICCv4.
|
|
|
|
if (input_profile == NULL ||
|
|
|
|
(major_revision < 4 && qcms_profile_is_bogus(input_profile))) {
|
|
|
|
fprintf(stderr, "Color profile is bogus!\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_profile = qcms_profile_sRGB();
|
|
|
|
if (output_profile == NULL) {
|
|
|
|
fprintf(stderr, "Error creating output color profile!\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
qcms_profile_precache_output_transform(output_profile);
|
|
|
|
transform = qcms_transform_create(input_profile, input_type,
|
|
|
|
output_profile, output_type,
|
|
|
|
intent);
|
|
|
|
if (transform == NULL) {
|
|
|
|
fprintf(stderr, "Error creating color transform!\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = rgba->u.RGBA.rgba;
|
|
|
|
for (i = 0; i < rgba->height; ++i, line += rgba->u.RGBA.stride) {
|
|
|
|
qcms_transform_data(transform, line, line, rgba->width);
|
|
|
|
}
|
|
|
|
ok = 1;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
if (input_profile != NULL) qcms_profile_release(input_profile);
|
|
|
|
if (output_profile != NULL) qcms_profile_release(output_profile);
|
|
|
|
if (transform != NULL) qcms_transform_release(transform);
|
|
|
|
return ok;
|
|
|
|
#else
|
|
|
|
(void)profile;
|
|
|
|
(void)rgba;
|
|
|
|
return 1;
|
|
|
|
#endif // WEBP_HAVE_QCMS
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// File decoding
|
|
|
|
|
2013-08-09 23:40:31 +02:00
|
|
|
static int Decode(void) { // Fills kParams.curr_frame
|
|
|
|
const WebPIterator* const curr = &kParams.curr_frame;
|
2013-09-12 09:32:28 +02:00
|
|
|
WebPDecoderConfig* const config = &kParams.config;
|
2013-03-08 04:31:27 +01:00
|
|
|
WebPDecBuffer* const output_buffer = &config->output;
|
|
|
|
int ok = 0;
|
|
|
|
|
|
|
|
ClearPreviousPic();
|
|
|
|
output_buffer->colorspace = MODE_RGBA;
|
2013-08-09 23:40:31 +02:00
|
|
|
ok = (WebPDecode(curr->fragment.bytes, curr->fragment.size,
|
2013-03-08 04:31:27 +01:00
|
|
|
config) == VP8_STATUS_OK);
|
|
|
|
if (!ok) {
|
2013-08-09 23:40:31 +02:00
|
|
|
fprintf(stderr, "Decoding of frame #%d failed!\n", curr->frame_num);
|
2013-03-08 04:31:27 +01:00
|
|
|
} else {
|
|
|
|
kParams.pic = output_buffer;
|
|
|
|
if (kParams.use_color_profile) {
|
|
|
|
ok = ApplyColorProfile(&kParams.iccp.chunk, output_buffer);
|
|
|
|
if (!ok) {
|
|
|
|
fprintf(stderr, "Applying color profile to frame #%d failed!\n",
|
2013-08-09 23:40:31 +02:00
|
|
|
curr->frame_num);
|
2013-03-08 04:31:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void decode_callback(int what) {
|
|
|
|
if (what == 0 && !kParams.done) {
|
|
|
|
int duration = 0;
|
|
|
|
if (kParams.dmux != NULL) {
|
2013-08-09 23:40:31 +02:00
|
|
|
WebPIterator* const curr = &kParams.curr_frame;
|
|
|
|
if (!WebPDemuxNextFrame(curr)) {
|
|
|
|
WebPDemuxReleaseIterator(curr);
|
|
|
|
if (WebPDemuxGetFrame(kParams.dmux, 1, curr)) {
|
2013-03-08 04:31:27 +01:00
|
|
|
--kParams.loop_count;
|
|
|
|
kParams.done = (kParams.loop_count == 0);
|
2015-02-03 05:05:54 +01:00
|
|
|
if (kParams.done) return;
|
2015-02-06 06:09:27 +01:00
|
|
|
ClearPreviousFrame();
|
2013-03-08 04:31:27 +01:00
|
|
|
} else {
|
|
|
|
kParams.decoding_error = 1;
|
|
|
|
kParams.done = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-08-09 23:40:31 +02:00
|
|
|
duration = curr->duration;
|
2018-04-20 10:55:42 +02:00
|
|
|
// Behavior copied from Chrome, cf:
|
|
|
|
// https://cs.chromium.org/chromium/src/third_party/WebKit/Source/
|
|
|
|
// platform/graphics/DeferredImageDecoder.cpp?
|
|
|
|
// rcl=b4c33049f096cd283f32be9a58b9a9e768227c26&l=246
|
|
|
|
if (duration <= 10) duration = 100;
|
2013-03-08 04:31:27 +01:00
|
|
|
}
|
|
|
|
if (!Decode()) {
|
|
|
|
kParams.decoding_error = 1;
|
|
|
|
kParams.done = 1;
|
|
|
|
} else {
|
|
|
|
glutPostRedisplay();
|
|
|
|
glutTimerFunc(duration, decode_callback, what);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 23:02:04 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Callbacks
|
|
|
|
|
|
|
|
static void HandleKey(unsigned char key, int pos_x, int pos_y) {
|
2018-07-20 12:54:30 +02:00
|
|
|
// Note: rescaling the window or toggling some features during an animation
|
|
|
|
// generates visual artifacts. This is not fixed because refreshing the frame
|
|
|
|
// may require rendering the whole animation from start till current frame.
|
2011-12-13 23:02:04 +01:00
|
|
|
(void)pos_x;
|
|
|
|
(void)pos_y;
|
|
|
|
if (key == 'q' || key == 'Q' || key == 27 /* Esc */) {
|
|
|
|
#ifdef FREEGLUT
|
|
|
|
glutLeaveMainLoop();
|
|
|
|
#else
|
2012-05-09 09:41:12 +02:00
|
|
|
ClearParams();
|
2011-12-13 23:02:04 +01:00
|
|
|
exit(0);
|
|
|
|
#endif
|
2013-03-08 04:31:27 +01:00
|
|
|
} else if (key == 'c') {
|
|
|
|
if (kParams.has_color_profile && !kParams.decoding_error) {
|
|
|
|
kParams.use_color_profile = 1 - kParams.use_color_profile;
|
|
|
|
|
|
|
|
if (kParams.has_animation) {
|
|
|
|
// Restart the completed animation to pickup the color profile change.
|
|
|
|
if (kParams.done && kParams.loop_count == 0) {
|
|
|
|
kParams.loop_count =
|
|
|
|
(int)WebPDemuxGetI(kParams.dmux, WEBP_FF_LOOP_COUNT) + 1;
|
|
|
|
kParams.done = 0;
|
|
|
|
// Start the decode loop immediately.
|
|
|
|
glutTimerFunc(0, decode_callback, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Decode();
|
|
|
|
glutPostRedisplay();
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 12:54:30 +02:00
|
|
|
} else if (key == 'b') {
|
|
|
|
kParams.draw_anim_background_color = 1 - kParams.draw_anim_background_color;
|
|
|
|
if (!kParams.has_animation) ClearPreviousFrame();
|
|
|
|
glutPostRedisplay();
|
2011-12-13 23:02:04 +01:00
|
|
|
} else if (key == 'i') {
|
2012-05-09 09:41:12 +02:00
|
|
|
kParams.print_info = 1 - kParams.print_info;
|
2016-08-24 11:04:17 +02:00
|
|
|
if (!kParams.has_animation) ClearPreviousFrame();
|
2011-12-13 23:02:04 +01:00
|
|
|
glutPostRedisplay();
|
2016-11-25 15:31:54 +01:00
|
|
|
} else if (key == 'd') {
|
|
|
|
kParams.only_deltas = 1 - kParams.only_deltas;
|
|
|
|
glutPostRedisplay();
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleReshape(int width, int height) {
|
2017-11-22 08:57:57 +01:00
|
|
|
// Note: reshape doesn't preserve aspect ratio, and might
|
|
|
|
// be handling larger-than-screen pictures incorrectly.
|
2011-12-13 23:02:04 +01:00
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2016-09-29 07:30:03 +02:00
|
|
|
kParams.viewport_width = width;
|
|
|
|
kParams.viewport_height = height;
|
2016-12-14 08:21:33 +01:00
|
|
|
if (!kParams.has_animation) ClearPreviousFrame();
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintString(const char* const text) {
|
|
|
|
void* const font = GLUT_BITMAP_9_BY_15;
|
|
|
|
int i;
|
|
|
|
for (i = 0; text[i]; ++i) {
|
|
|
|
glutBitmapCharacter(font, text[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 20:47:09 +02:00
|
|
|
static void PrintStringW(const char* const text) {
|
|
|
|
#if defined(_WIN32) && defined(_UNICODE)
|
|
|
|
void* const font = GLUT_BITMAP_9_BY_15;
|
|
|
|
const W_CHAR* const wtext = (const W_CHAR*)text;
|
|
|
|
int i;
|
|
|
|
for (i = 0; wtext[i]; ++i) {
|
|
|
|
glutBitmapCharacter(font, wtext[i]);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
PrintString(text);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-15 09:15:04 +01:00
|
|
|
static float GetColorf(uint32_t color, int shift) {
|
2018-07-07 06:25:41 +02:00
|
|
|
return ((color >> shift) & 0xff) / 255.f;
|
2012-11-15 09:15:04 +01:00
|
|
|
}
|
|
|
|
|
2012-07-10 08:01:52 +02:00
|
|
|
static void DrawCheckerBoard(void) {
|
|
|
|
const int square_size = 8; // must be a power of 2
|
|
|
|
int x, y;
|
|
|
|
GLint viewport[4]; // x, y, width, height
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
|
|
glGetIntegerv(GL_VIEWPORT, viewport);
|
|
|
|
// shift to integer coordinates with (0,0) being top-left.
|
|
|
|
glOrtho(0, viewport[2], viewport[3], 0, -1, 1);
|
|
|
|
for (y = 0; y < viewport[3]; y += square_size) {
|
|
|
|
for (x = 0; x < viewport[2]; x += square_size) {
|
|
|
|
const GLubyte color = 128 + 64 * (!((x + y) & square_size));
|
|
|
|
glColor3ub(color, color, color);
|
|
|
|
glRecti(x, y, x + square_size, y + square_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2018-07-20 12:54:30 +02:00
|
|
|
static void DrawBackground(void) {
|
|
|
|
// Whole window cleared with clear color, checkerboard rendered on top of it.
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
DrawCheckerBoard();
|
|
|
|
|
|
|
|
// ANIM background color rendered (blend) on top. Default is white for still
|
|
|
|
// images (without ANIM chunk). glClear() can't be used for that (no blend).
|
|
|
|
if (kParams.draw_anim_background_color) {
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
glColor4f(GetColorf(kParams.bg_color, 16), // BGRA from spec
|
|
|
|
GetColorf(kParams.bg_color, 8),
|
|
|
|
GetColorf(kParams.bg_color, 0),
|
|
|
|
GetColorf(kParams.bg_color, 24));
|
|
|
|
glRecti(-1, -1, +1, +1);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 19:50:33 +02:00
|
|
|
// Draw background in a scissored rectangle.
|
|
|
|
static void DrawBackgroundScissored(int window_x, int window_y, int frame_w,
|
|
|
|
int frame_h) {
|
|
|
|
// Only update the requested area, not the whole canvas.
|
|
|
|
window_x = window_x * kParams.viewport_width / kParams.canvas_width;
|
|
|
|
window_y = window_y * kParams.viewport_height / kParams.canvas_height;
|
|
|
|
frame_w = frame_w * kParams.viewport_width / kParams.canvas_width;
|
|
|
|
frame_h = frame_h * kParams.viewport_height / kParams.canvas_height;
|
|
|
|
|
|
|
|
// glScissor() takes window coordinates (0,0 at bottom left).
|
|
|
|
window_y = kParams.viewport_height - window_y - frame_h;
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glScissor(window_x, window_y, frame_w, frame_h);
|
|
|
|
DrawBackground();
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
2011-12-13 23:02:04 +01:00
|
|
|
static void HandleDisplay(void) {
|
2012-11-15 09:15:04 +01:00
|
|
|
const WebPDecBuffer* const pic = kParams.pic;
|
2013-08-09 23:40:31 +02:00
|
|
|
const WebPIterator* const curr = &kParams.curr_frame;
|
|
|
|
WebPIterator* const prev = &kParams.prev_frame;
|
2012-11-15 09:35:01 +01:00
|
|
|
GLfloat xoff, yoff;
|
2012-05-09 09:41:12 +02:00
|
|
|
if (pic == NULL) return;
|
2011-12-13 23:02:04 +01:00
|
|
|
glPushMatrix();
|
2016-09-29 07:30:03 +02:00
|
|
|
glPixelZoom((GLfloat)(+1. / kParams.canvas_width * kParams.viewport_width),
|
|
|
|
(GLfloat)(-1. / kParams.canvas_height * kParams.viewport_height));
|
2013-08-09 23:40:31 +02:00
|
|
|
xoff = (GLfloat)(2. * curr->x_offset / kParams.canvas_width);
|
|
|
|
yoff = (GLfloat)(2. * curr->y_offset / kParams.canvas_height);
|
2013-03-15 20:17:45 +01:00
|
|
|
glRasterPos2f(-1.f + xoff, 1.f - yoff);
|
2011-12-13 23:02:04 +01:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
2012-05-09 09:41:12 +02:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, pic->u.RGBA.stride / 4);
|
2013-03-23 20:45:11 +01:00
|
|
|
|
2016-11-25 15:31:54 +01:00
|
|
|
if (kParams.only_deltas) {
|
2018-07-20 12:54:30 +02:00
|
|
|
DrawBackground();
|
2018-07-23 19:50:33 +02:00
|
|
|
} else {
|
|
|
|
// The rectangle of the previous frame might be different than the current
|
|
|
|
// frame, so we may need to DrawBackgroundScissored for both.
|
2013-08-09 23:40:31 +02:00
|
|
|
if (prev->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND) {
|
|
|
|
// Clear the previous frame rectangle.
|
2018-07-23 19:50:33 +02:00
|
|
|
DrawBackgroundScissored(prev->x_offset, prev->y_offset, prev->width,
|
|
|
|
prev->height);
|
|
|
|
}
|
|
|
|
if (curr->blend_method == WEBP_MUX_NO_BLEND) {
|
2013-08-09 23:40:31 +02:00
|
|
|
// We simulate no-blending behavior by first clearing the current frame
|
2018-07-23 19:50:33 +02:00
|
|
|
// rectangle and then alpha-blending against it.
|
|
|
|
DrawBackgroundScissored(curr->x_offset, curr->y_offset, curr->width,
|
|
|
|
curr->height);
|
2013-08-09 23:40:31 +02:00
|
|
|
}
|
2012-11-15 09:15:04 +01:00
|
|
|
}
|
2013-08-09 23:40:31 +02:00
|
|
|
|
|
|
|
*prev = *curr;
|
2013-03-23 20:45:11 +01:00
|
|
|
|
2012-05-09 09:41:12 +02:00
|
|
|
glDrawPixels(pic->width, pic->height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
(GLvoid*)pic->u.RGBA.rgba);
|
|
|
|
if (kParams.print_info) {
|
2011-12-13 23:02:04 +01:00
|
|
|
char tmp[32];
|
|
|
|
|
2013-03-15 20:17:45 +01:00
|
|
|
glColor4f(0.90f, 0.0f, 0.90f, 1.0f);
|
2011-12-17 04:30:33 +01:00
|
|
|
glRasterPos2f(-0.95f, 0.90f);
|
2022-07-05 20:47:09 +02:00
|
|
|
PrintStringW(kParams.file_name);
|
2011-12-13 23:02:04 +01:00
|
|
|
|
2012-05-09 09:41:12 +02:00
|
|
|
snprintf(tmp, sizeof(tmp), "Dimension:%d x %d", pic->width, pic->height);
|
2013-03-15 20:17:45 +01:00
|
|
|
glColor4f(0.90f, 0.0f, 0.90f, 1.0f);
|
2011-12-17 04:30:33 +01:00
|
|
|
glRasterPos2f(-0.95f, 0.80f);
|
2011-12-13 23:02:04 +01:00
|
|
|
PrintString(tmp);
|
2013-08-09 23:40:31 +02:00
|
|
|
if (curr->x_offset != 0 || curr->y_offset != 0) {
|
2012-11-15 09:15:04 +01:00
|
|
|
snprintf(tmp, sizeof(tmp), " (offset:%d,%d)",
|
2013-08-09 23:40:31 +02:00
|
|
|
curr->x_offset, curr->y_offset);
|
2012-11-15 09:15:04 +01:00
|
|
|
glRasterPos2f(-0.95f, 0.70f);
|
|
|
|
PrintString(tmp);
|
|
|
|
}
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
2012-07-10 08:01:52 +02:00
|
|
|
glPopMatrix();
|
2017-11-26 03:21:44 +01:00
|
|
|
#if defined(__APPLE__) || defined(_WIN32)
|
|
|
|
glFlush();
|
|
|
|
#else
|
2017-05-09 18:02:25 +02:00
|
|
|
glutSwapBuffers();
|
2017-11-26 03:21:44 +01:00
|
|
|
#endif
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
|
|
|
|
2024-03-19 11:27:58 +01:00
|
|
|
static void StartDisplay(const char* filename) {
|
2019-05-28 11:56:52 +02:00
|
|
|
int width = kParams.canvas_width;
|
|
|
|
int height = kParams.canvas_height;
|
|
|
|
int screen_width, screen_height;
|
2024-03-19 11:27:58 +01:00
|
|
|
const char viewername[] = " - WebP viewer";
|
|
|
|
// max linux file len + viewername string
|
|
|
|
char title[4096 + sizeof(viewername)] = "";
|
2017-11-26 03:21:44 +01:00
|
|
|
// TODO(webp:365) GLUT_DOUBLE results in flickering / old frames to be
|
|
|
|
// partially displayed with animated webp + alpha.
|
|
|
|
#if defined(__APPLE__) || defined(_WIN32)
|
|
|
|
glutInitDisplayMode(GLUT_RGBA);
|
|
|
|
#else
|
2017-05-09 18:02:25 +02:00
|
|
|
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
|
2017-11-26 03:21:44 +01:00
|
|
|
#endif
|
2019-05-28 11:56:52 +02:00
|
|
|
screen_width = glutGet(GLUT_SCREEN_WIDTH);
|
|
|
|
screen_height = glutGet(GLUT_SCREEN_HEIGHT);
|
2019-06-05 21:43:23 +02:00
|
|
|
if (width > screen_width || height > screen_height) {
|
2019-05-28 11:56:52 +02:00
|
|
|
if (width > screen_width) {
|
|
|
|
height = (height * screen_width + width - 1) / width;
|
|
|
|
width = screen_width;
|
|
|
|
}
|
|
|
|
if (height > screen_height) {
|
|
|
|
width = (width * screen_height + height - 1) / height;
|
|
|
|
height = screen_height;
|
|
|
|
}
|
|
|
|
}
|
2024-03-19 11:27:58 +01:00
|
|
|
snprintf(title, sizeof(title), "%s%s", filename, viewername);
|
2012-11-15 09:15:04 +01:00
|
|
|
glutInitWindowSize(width, height);
|
2024-03-19 11:27:58 +01:00
|
|
|
glutCreateWindow(title);
|
2011-12-13 23:02:04 +01:00
|
|
|
glutDisplayFunc(HandleDisplay);
|
2016-09-29 07:30:03 +02:00
|
|
|
glutReshapeFunc(HandleReshape);
|
2011-12-13 23:02:04 +01:00
|
|
|
glutIdleFunc(NULL);
|
|
|
|
glutKeyboardFunc(HandleKey);
|
2012-06-20 20:18:35 +02:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_BLEND);
|
2018-07-20 12:54:30 +02:00
|
|
|
glClearColor(0, 0, 0, 0); // window will be cleared to black (no blend)
|
|
|
|
DrawBackground();
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Main
|
|
|
|
|
|
|
|
static void Help(void) {
|
2018-07-20 12:54:30 +02:00
|
|
|
printf(
|
|
|
|
"Usage: vwebp in_file [options]\n\n"
|
|
|
|
"Decodes the WebP image file and visualize it using OpenGL\n"
|
|
|
|
"Options are:\n"
|
|
|
|
" -version ..... print version number and exit\n"
|
|
|
|
" -noicc ....... don't use the icc profile if present\n"
|
|
|
|
" -nofancy ..... don't use the fancy YUV420 upscaler\n"
|
|
|
|
" -nofilter .... disable in-loop filtering\n"
|
|
|
|
" -dither <int> dithering strength (0..100), default=50\n"
|
|
|
|
" -noalphadither disable alpha plane dithering\n"
|
|
|
|
" -usebgcolor .. display background color\n"
|
|
|
|
" -mt .......... use multi-threading\n"
|
|
|
|
" -info ........ print info\n"
|
|
|
|
" -h ........... this help message\n"
|
|
|
|
"\n"
|
|
|
|
"Keyboard shortcuts:\n"
|
|
|
|
" 'c' ................ toggle use of color profile\n"
|
|
|
|
" 'b' ................ toggle background color display\n"
|
|
|
|
" 'i' ................ overlay file information\n"
|
|
|
|
" 'd' ................ disable blending & disposal (debug)\n"
|
|
|
|
" 'q' / 'Q' / ESC .... quit\n");
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
|
|
|
|
2019-07-26 09:46:40 +02:00
|
|
|
int main(int argc, char* argv[]) {
|
2024-04-02 04:34:17 +02:00
|
|
|
int c, file_name_argv_index = 1;
|
2013-09-12 09:32:28 +02:00
|
|
|
WebPDecoderConfig* const config = &kParams.config;
|
2013-08-15 09:21:15 +02:00
|
|
|
WebPIterator* const curr = &kParams.curr_frame;
|
2011-12-13 23:02:04 +01:00
|
|
|
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
INIT_WARGV(argc, argv);
|
|
|
|
|
2013-09-12 09:32:28 +02:00
|
|
|
if (!WebPInitDecoderConfig(config)) {
|
2011-12-13 23:02:04 +01:00
|
|
|
fprintf(stderr, "Library version mismatch!\n");
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(-1);
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
2013-11-26 22:59:02 +01:00
|
|
|
config->options.dithering_strength = 50;
|
2014-06-14 00:06:16 +02:00
|
|
|
config->options.alpha_dithering_strength = 100;
|
2013-03-08 04:31:27 +01:00
|
|
|
kParams.use_color_profile = 1;
|
2018-07-20 12:54:30 +02:00
|
|
|
// Background color hidden by default to see transparent areas.
|
|
|
|
kParams.draw_anim_background_color = 0;
|
2011-12-13 23:02:04 +01:00
|
|
|
|
|
|
|
for (c = 1; c < argc; ++c) {
|
2014-09-11 08:35:48 +02:00
|
|
|
int parse_error = 0;
|
2011-12-13 23:02:04 +01:00
|
|
|
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
|
|
|
Help();
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(0);
|
2013-03-08 04:31:27 +01:00
|
|
|
} else if (!strcmp(argv[c], "-noicc")) {
|
|
|
|
kParams.use_color_profile = 0;
|
2011-12-13 23:02:04 +01:00
|
|
|
} else if (!strcmp(argv[c], "-nofancy")) {
|
2013-09-12 09:32:28 +02:00
|
|
|
config->options.no_fancy_upsampling = 1;
|
2011-12-13 23:02:04 +01:00
|
|
|
} else if (!strcmp(argv[c], "-nofilter")) {
|
2013-09-12 09:32:28 +02:00
|
|
|
config->options.bypass_filtering = 1;
|
2014-06-14 00:06:16 +02:00
|
|
|
} else if (!strcmp(argv[c], "-noalphadither")) {
|
|
|
|
config->options.alpha_dithering_strength = 0;
|
2018-07-20 12:54:30 +02:00
|
|
|
} else if (!strcmp(argv[c], "-usebgcolor")) {
|
|
|
|
kParams.draw_anim_background_color = 1;
|
2013-11-26 22:59:02 +01:00
|
|
|
} else if (!strcmp(argv[c], "-dither") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config->options.dithering_strength =
|
|
|
|
ExUtilGetInt(argv[++c], 0, &parse_error);
|
2012-11-15 09:15:04 +01:00
|
|
|
} else if (!strcmp(argv[c], "-info")) {
|
|
|
|
kParams.print_info = 1;
|
2011-12-13 23:02:04 +01:00
|
|
|
} else if (!strcmp(argv[c], "-version")) {
|
2013-02-26 23:22:06 +01:00
|
|
|
const int dec_version = WebPGetDecoderVersion();
|
|
|
|
const int dmux_version = WebPGetDemuxVersion();
|
|
|
|
printf("WebP Decoder version: %d.%d.%d\nWebP Demux version: %d.%d.%d\n",
|
|
|
|
(dec_version >> 16) & 0xff, (dec_version >> 8) & 0xff,
|
|
|
|
dec_version & 0xff, (dmux_version >> 16) & 0xff,
|
|
|
|
(dmux_version >> 8) & 0xff, dmux_version & 0xff);
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(0);
|
2011-12-13 23:02:04 +01:00
|
|
|
} else if (!strcmp(argv[c], "-mt")) {
|
2013-09-12 09:32:28 +02:00
|
|
|
config->options.use_threads = 1;
|
2013-12-13 05:20:08 +01:00
|
|
|
} else if (!strcmp(argv[c], "--")) {
|
2024-04-02 04:34:17 +02:00
|
|
|
if (c < argc - 1) {
|
|
|
|
kParams.file_name = (const char*)GET_WARGV(argv, ++c);
|
|
|
|
file_name_argv_index = c;
|
|
|
|
}
|
2013-12-13 05:20:08 +01:00
|
|
|
break;
|
2011-12-13 23:02:04 +01:00
|
|
|
} else if (argv[c][0] == '-') {
|
|
|
|
printf("Unknown option '%s'\n", argv[c]);
|
|
|
|
Help();
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(-1);
|
2011-12-13 23:02:04 +01:00
|
|
|
} else {
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
kParams.file_name = (const char*)GET_WARGV(argv, c);
|
2024-04-02 04:34:17 +02:00
|
|
|
file_name_argv_index = c;
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
2014-09-11 08:35:48 +02:00
|
|
|
|
|
|
|
if (parse_error) {
|
|
|
|
Help();
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(-1);
|
2014-09-11 08:35:48 +02:00
|
|
|
}
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
|
|
|
|
2012-05-12 01:00:57 +02:00
|
|
|
if (kParams.file_name == NULL) {
|
|
|
|
printf("missing input file!!\n");
|
|
|
|
Help();
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(0);
|
2012-05-12 01:00:57 +02:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:36:29 +02:00
|
|
|
if (!ImgIoUtilReadFile(kParams.file_name,
|
|
|
|
&kParams.data.bytes, &kParams.data.size)) {
|
2012-05-12 01:00:57 +02:00
|
|
|
goto Error;
|
|
|
|
}
|
2012-05-09 09:41:12 +02:00
|
|
|
|
2013-06-10 14:46:22 +02:00
|
|
|
if (!WebPGetInfo(kParams.data.bytes, kParams.data.size, NULL, NULL)) {
|
|
|
|
fprintf(stderr, "Input file doesn't appear to be WebP format.\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
2012-09-27 08:44:59 +02:00
|
|
|
kParams.dmux = WebPDemux(&kParams.data);
|
|
|
|
if (kParams.dmux == NULL) {
|
2012-05-09 09:41:12 +02:00
|
|
|
fprintf(stderr, "Could not create demuxing object!\n");
|
|
|
|
goto Error;
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
2012-05-09 09:41:12 +02:00
|
|
|
|
2012-11-15 09:15:04 +01:00
|
|
|
kParams.canvas_width = WebPDemuxGetI(kParams.dmux, WEBP_FF_CANVAS_WIDTH);
|
|
|
|
kParams.canvas_height = WebPDemuxGetI(kParams.dmux, WEBP_FF_CANVAS_HEIGHT);
|
|
|
|
if (kParams.print_info) {
|
|
|
|
printf("Canvas: %d x %d\n", kParams.canvas_width, kParams.canvas_height);
|
|
|
|
}
|
2012-05-09 09:41:12 +02:00
|
|
|
|
2015-02-06 06:09:27 +01:00
|
|
|
ClearPreviousFrame();
|
2013-03-23 20:45:11 +01:00
|
|
|
|
2013-03-08 04:31:27 +01:00
|
|
|
memset(&kParams.iccp, 0, sizeof(kParams.iccp));
|
|
|
|
kParams.has_color_profile =
|
|
|
|
!!(WebPDemuxGetI(kParams.dmux, WEBP_FF_FORMAT_FLAGS) & ICCP_FLAG);
|
|
|
|
if (kParams.has_color_profile) {
|
|
|
|
#ifdef WEBP_HAVE_QCMS
|
|
|
|
if (!WebPDemuxGetChunk(kParams.dmux, "ICCP", 1, &kParams.iccp)) goto Error;
|
|
|
|
printf("VP8X: Found color profile\n");
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "Warning: color profile present, but qcms is unavailable!\n"
|
|
|
|
"Build libqcms from Mozilla or Chromium and define WEBP_HAVE_QCMS "
|
|
|
|
"before building.\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-08-09 23:40:31 +02:00
|
|
|
if (!WebPDemuxGetFrame(kParams.dmux, 1, curr)) goto Error;
|
2012-05-09 09:41:12 +02:00
|
|
|
|
2013-08-09 23:40:31 +02:00
|
|
|
kParams.has_animation = (curr->num_frames > 1);
|
2012-09-27 08:44:59 +02:00
|
|
|
kParams.loop_count = (int)WebPDemuxGetI(kParams.dmux, WEBP_FF_LOOP_COUNT);
|
2012-11-15 09:15:04 +01:00
|
|
|
kParams.bg_color = WebPDemuxGetI(kParams.dmux, WEBP_FF_BACKGROUND_COLOR);
|
2012-09-27 08:44:59 +02:00
|
|
|
printf("VP8X: Found %d images in file (loop count = %d)\n",
|
2013-08-09 23:40:31 +02:00
|
|
|
curr->num_frames, kParams.loop_count);
|
2011-12-13 23:02:04 +01:00
|
|
|
|
2012-05-09 09:41:12 +02:00
|
|
|
// Decode first frame
|
2012-11-15 09:15:04 +01:00
|
|
|
if (!Decode()) goto Error;
|
|
|
|
|
|
|
|
// Position iterator to last frame. Next call to HandleDisplay will wrap over.
|
|
|
|
// We take this into account by bumping up loop_count.
|
2023-11-10 13:57:07 +01:00
|
|
|
if (!WebPDemuxGetFrame(kParams.dmux, 0, curr)) goto Error;
|
2012-11-15 09:15:04 +01:00
|
|
|
if (kParams.loop_count) ++kParams.loop_count;
|
2011-12-13 23:02:04 +01:00
|
|
|
|
2015-12-03 10:36:21 +01:00
|
|
|
#if defined(__unix__) || defined(__CYGWIN__)
|
|
|
|
// Work around GLUT compositor bug.
|
|
|
|
// https://bugs.launchpad.net/ubuntu/+source/freeglut/+bug/369891
|
|
|
|
setenv("XLIB_SKIP_ARGB_VISUALS", "1", 1);
|
|
|
|
#endif
|
|
|
|
|
2012-05-09 09:41:12 +02:00
|
|
|
// Start display (and timer)
|
2011-12-13 23:02:04 +01:00
|
|
|
glutInit(&argc, argv);
|
2012-05-25 23:53:46 +02:00
|
|
|
#ifdef FREEGLUT
|
|
|
|
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
|
|
|
|
#endif
|
2024-04-02 04:34:17 +02:00
|
|
|
StartDisplay(argv[file_name_argv_index]);
|
2012-11-15 09:15:04 +01:00
|
|
|
|
2012-05-09 09:41:12 +02:00
|
|
|
if (kParams.has_animation) glutTimerFunc(0, decode_callback, 0);
|
|
|
|
glutMainLoop();
|
2011-12-13 23:02:04 +01:00
|
|
|
|
|
|
|
// Should only be reached when using FREEGLUT:
|
2012-05-09 09:41:12 +02:00
|
|
|
ClearParams();
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(0);
|
2012-05-09 09:41:12 +02:00
|
|
|
|
|
|
|
Error:
|
|
|
|
ClearParams();
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
FREE_WARGV_AND_RETURN(-1);
|
2011-12-13 23:02:04 +01:00
|
|
|
}
|
|
|
|
|
2013-09-12 13:03:51 +02:00
|
|
|
#else // !WEBP_HAVE_GL
|
|
|
|
|
2019-07-26 09:46:40 +02:00
|
|
|
int main(int argc, const char* argv[]) {
|
2013-09-12 13:03:51 +02:00
|
|
|
fprintf(stderr, "OpenGL support not enabled in %s.\n", argv[0]);
|
|
|
|
(void)argc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-12-13 23:02:04 +01:00
|
|
|
//------------------------------------------------------------------------------
|