James Zern | ad1e163 | 2012-01-06 14:49:06 -0800 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 2 | // |
James Zern | d640614 | 2013-06-06 23:05:58 -0700 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license |
| 4 | // that can be found in the COPYING file in the root of the source |
| 5 | // tree. An additional intellectual property rights grant can be found |
| 6 | // in the file PATENTS. All contributing project authors may |
| 7 | // be found in the AUTHORS file in the root of the source tree. |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 8 | // ----------------------------------------------------------------------------- |
| 9 | // |
| 10 | // simple command line calling the WebPEncode function. |
| 11 | // Encodes a raw .YUV into WebP bitstream |
| 12 | // |
| 13 | // Author: Skal (pascal.massimino@gmail.com) |
| 14 | |
| 15 | #include <stdio.h> |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 16 | #include <stdlib.h> |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 17 | #include <string.h> |
| 18 | |
James Zern | 31f9dc6 | 2011-06-06 17:56:50 -0700 | [diff] [blame] | 19 | #ifdef HAVE_CONFIG_H |
James Zern | 32b3137 | 2014-06-10 17:53:44 -0700 | [diff] [blame] | 20 | #include "webp/config.h" |
James Zern | 31f9dc6 | 2011-06-06 17:56:50 -0700 | [diff] [blame] | 21 | #endif |
| 22 | |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 23 | #include "webp/encode.h" |
skal | 1bd287a | 2012-12-11 11:02:39 +0100 | [diff] [blame] | 24 | |
James Zern | 63aba3a | 2012-12-03 18:20:00 -0800 | [diff] [blame] | 25 | #include "./metadata.h" |
James Zern | 00b29e2 | 2012-05-15 13:48:11 -0700 | [diff] [blame] | 26 | #include "./stopwatch.h" |
skal | 1bd287a | 2012-12-11 11:02:39 +0100 | [diff] [blame] | 27 | |
| 28 | #include "./jpegdec.h" |
| 29 | #include "./pngdec.h" |
James Zern | 1c1c564 | 2012-12-06 14:04:36 -0800 | [diff] [blame] | 30 | #include "./tiffdec.h" |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 31 | #include "./webpdec.h" |
James Zern | a452a55 | 2013-01-22 18:28:52 -0800 | [diff] [blame] | 32 | #include "./wicdec.h" |
skal | 1bd287a | 2012-12-11 11:02:39 +0100 | [diff] [blame] | 33 | |
James Zern | b4d0ef8 | 2011-07-15 14:53:03 -0700 | [diff] [blame] | 34 | #ifndef WEBP_DLL |
James Zern | 605a712 | 2013-11-25 14:43:12 -0800 | [diff] [blame] | 35 | #ifdef __cplusplus |
James Zern | 04e84cf | 2011-11-04 15:20:08 -0700 | [diff] [blame] | 36 | extern "C" { |
James Zern | b4d0ef8 | 2011-07-15 14:53:03 -0700 | [diff] [blame] | 37 | #endif |
Pascal Massimino | cfbf88a | 2011-04-22 12:14:45 -0700 | [diff] [blame] | 38 | |
James Zern | 04e84cf | 2011-11-04 15:20:08 -0700 | [diff] [blame] | 39 | extern void* VP8GetCPUInfo; // opaque forward declaration. |
| 40 | |
James Zern | 605a712 | 2013-11-25 14:43:12 -0800 | [diff] [blame] | 41 | #ifdef __cplusplus |
James Zern | 04e84cf | 2011-11-04 15:20:08 -0700 | [diff] [blame] | 42 | } // extern "C" |
| 43 | #endif |
| 44 | #endif // WEBP_DLL |
| 45 | |
James Zern | c7e86ab | 2011-08-25 14:22:32 -0700 | [diff] [blame] | 46 | //------------------------------------------------------------------------------ |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 47 | |
| 48 | static int verbose = 0; |
| 49 | |
| 50 | static int ReadYUV(FILE* in_file, WebPPicture* const pic) { |
Pascal Massimino | dd10817 | 2012-07-18 21:58:53 +0000 | [diff] [blame] | 51 | const int use_argb = pic->use_argb; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 52 | const int uv_width = (pic->width + 1) / 2; |
| 53 | const int uv_height = (pic->height + 1) / 2; |
| 54 | int y; |
| 55 | int ok = 0; |
| 56 | |
Pascal Massimino | dd10817 | 2012-07-18 21:58:53 +0000 | [diff] [blame] | 57 | pic->use_argb = 0; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 58 | if (!WebPPictureAlloc(pic)) return ok; |
| 59 | |
| 60 | for (y = 0; y < pic->height; ++y) { |
| 61 | if (fread(pic->y + y * pic->y_stride, pic->width, 1, in_file) != 1) { |
| 62 | goto End; |
| 63 | } |
| 64 | } |
| 65 | for (y = 0; y < uv_height; ++y) { |
| 66 | if (fread(pic->u + y * pic->uv_stride, uv_width, 1, in_file) != 1) |
| 67 | goto End; |
| 68 | } |
| 69 | for (y = 0; y < uv_height; ++y) { |
| 70 | if (fread(pic->v + y * pic->uv_stride, uv_width, 1, in_file) != 1) |
| 71 | goto End; |
| 72 | } |
| 73 | ok = 1; |
Pascal Massimino | dd10817 | 2012-07-18 21:58:53 +0000 | [diff] [blame] | 74 | if (use_argb) ok = WebPPictureYUVAToARGB(pic); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 75 | |
| 76 | End: |
| 77 | return ok; |
| 78 | } |
| 79 | |
James Zern | 31f9dc6 | 2011-06-06 17:56:50 -0700 | [diff] [blame] | 80 | #ifdef HAVE_WINCODEC_H |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 81 | |
Pascal Massimino | 2ab4b72 | 2011-04-25 16:58:04 -0700 | [diff] [blame] | 82 | static int ReadPicture(const char* const filename, WebPPicture* const pic, |
James Zern | 63aba3a | 2012-12-03 18:20:00 -0800 | [diff] [blame] | 83 | int keep_alpha, Metadata* const metadata) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 84 | int ok; |
| 85 | if (pic->width != 0 && pic->height != 0) { |
| 86 | // If image size is specified, infer it as YUV format. |
| 87 | FILE* in_file = fopen(filename, "rb"); |
| 88 | if (in_file == NULL) { |
| 89 | fprintf(stderr, "Error! Cannot open input file '%s'\n", filename); |
| 90 | return 0; |
| 91 | } |
| 92 | ok = ReadYUV(in_file, pic); |
| 93 | fclose(in_file); |
| 94 | } else { |
| 95 | // If no size specified, try to decode it using WIC. |
James Zern | e83ff7d | 2013-01-24 15:37:49 -0800 | [diff] [blame] | 96 | ok = ReadPictureWithWIC(filename, pic, keep_alpha, metadata); |
James Zern | 7d039fc | 2014-05-24 18:30:33 -0700 | [diff] [blame] | 97 | if (!ok) { |
| 98 | ok = ReadWebP(filename, pic, keep_alpha, metadata); |
| 99 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 100 | } |
| 101 | if (!ok) { |
| 102 | fprintf(stderr, "Error! Could not process file %s\n", filename); |
| 103 | } |
| 104 | return ok; |
| 105 | } |
| 106 | |
James Zern | 31f9dc6 | 2011-06-06 17:56:50 -0700 | [diff] [blame] | 107 | #else // !HAVE_WINCODEC_H |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 108 | |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 109 | typedef enum { |
James Zern | d8921dd | 2012-07-02 11:24:23 -0700 | [diff] [blame] | 110 | PNG_ = 0, |
| 111 | JPEG_, |
James Zern | 6f76d24 | 2012-07-01 17:55:21 -0700 | [diff] [blame] | 112 | TIFF_, // 'TIFF' clashes with libtiff |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 113 | WEBP_, |
James Zern | a0b2736 | 2012-01-27 17:39:47 -0800 | [diff] [blame] | 114 | UNSUPPORTED |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 115 | } InputFileFormat; |
| 116 | |
| 117 | static InputFileFormat GetImageType(FILE* in_file) { |
| 118 | InputFileFormat format = UNSUPPORTED; |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 119 | uint32_t magic1, magic2; |
| 120 | uint8_t buf[12]; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 121 | |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 122 | if ((fread(&buf[0], 12, 1, in_file) != 1) || |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 123 | (fseek(in_file, 0, SEEK_SET) != 0)) { |
| 124 | return format; |
| 125 | } |
| 126 | |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 127 | magic1 = ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; |
| 128 | magic2 = ((uint32_t)buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11]; |
| 129 | if (magic1 == 0x89504E47U) { |
James Zern | d8921dd | 2012-07-02 11:24:23 -0700 | [diff] [blame] | 130 | format = PNG_; |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 131 | } else if (magic1 >= 0xFFD8FF00U && magic1 <= 0xFFD8FFFFU) { |
James Zern | d8921dd | 2012-07-02 11:24:23 -0700 | [diff] [blame] | 132 | format = JPEG_; |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 133 | } else if (magic1 == 0x49492A00 || magic1 == 0x4D4D002A) { |
James Zern | 6f76d24 | 2012-07-01 17:55:21 -0700 | [diff] [blame] | 134 | format = TIFF_; |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 135 | } else if (magic1 == 0x52494646 && magic2 == 0x57454250) { |
| 136 | format = WEBP_; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 137 | } |
| 138 | return format; |
| 139 | } |
| 140 | |
Pascal Massimino | 2ab4b72 | 2011-04-25 16:58:04 -0700 | [diff] [blame] | 141 | static int ReadPicture(const char* const filename, WebPPicture* const pic, |
James Zern | 63aba3a | 2012-12-03 18:20:00 -0800 | [diff] [blame] | 142 | int keep_alpha, Metadata* const metadata) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 143 | int ok = 0; |
| 144 | FILE* in_file = fopen(filename, "rb"); |
| 145 | if (in_file == NULL) { |
| 146 | fprintf(stderr, "Error! Cannot open input file '%s'\n", filename); |
| 147 | return ok; |
| 148 | } |
| 149 | |
| 150 | if (pic->width == 0 || pic->height == 0) { |
| 151 | // If no size specified, try to decode it as PNG/JPEG (as appropriate). |
| 152 | const InputFileFormat format = GetImageType(in_file); |
James Zern | d8921dd | 2012-07-02 11:24:23 -0700 | [diff] [blame] | 153 | if (format == PNG_) { |
James Zern | dba64d9 | 2012-12-04 19:00:30 -0800 | [diff] [blame] | 154 | ok = ReadPNG(in_file, pic, keep_alpha, metadata); |
James Zern | d8921dd | 2012-07-02 11:24:23 -0700 | [diff] [blame] | 155 | } else if (format == JPEG_) { |
James Zern | 2c72496 | 2012-12-16 19:13:56 -0800 | [diff] [blame] | 156 | ok = ReadJPEG(in_file, pic, metadata); |
James Zern | 6f76d24 | 2012-07-01 17:55:21 -0700 | [diff] [blame] | 157 | } else if (format == TIFF_) { |
James Zern | 2914ecf | 2012-12-15 19:41:03 -0800 | [diff] [blame] | 158 | ok = ReadTIFF(filename, pic, keep_alpha, metadata); |
James Zern | ddeb6ac | 2014-04-22 19:30:27 -0700 | [diff] [blame] | 159 | } else if (format == WEBP_) { |
| 160 | ok = ReadWebP(filename, pic, keep_alpha, metadata); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 161 | } |
| 162 | } else { |
| 163 | // If image size is specified, infer it as YUV format. |
| 164 | ok = ReadYUV(in_file, pic); |
| 165 | } |
| 166 | if (!ok) { |
| 167 | fprintf(stderr, "Error! Could not process file %s\n", filename); |
| 168 | } |
| 169 | |
| 170 | fclose(in_file); |
| 171 | return ok; |
| 172 | } |
| 173 | |
James Zern | 31f9dc6 | 2011-06-06 17:56:50 -0700 | [diff] [blame] | 174 | #endif // !HAVE_WINCODEC_H |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 175 | |
| 176 | static void AllocExtraInfo(WebPPicture* const pic) { |
| 177 | const int mb_w = (pic->width + 15) / 16; |
| 178 | const int mb_h = (pic->height + 15) / 16; |
| 179 | pic->extra_info = (uint8_t*)malloc(mb_w * mb_h * sizeof(*pic->extra_info)); |
| 180 | } |
| 181 | |
| 182 | static void PrintByteCount(const int bytes[4], int total_size, |
| 183 | int* const totals) { |
| 184 | int s; |
| 185 | int total = 0; |
| 186 | for (s = 0; s < 4; ++s) { |
| 187 | fprintf(stderr, "| %7d ", bytes[s]); |
| 188 | total += bytes[s]; |
| 189 | if (totals) totals[s] += bytes[s]; |
| 190 | } |
James Zern | 04e84cf | 2011-11-04 15:20:08 -0700 | [diff] [blame] | 191 | fprintf(stderr, "| %7d (%.1f%%)\n", total, 100.f * total / total_size); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void PrintPercents(const int counts[4], int total) { |
| 195 | int s; |
| 196 | for (s = 0; s < 4; ++s) { |
| 197 | fprintf(stderr, "| %2d%%", 100 * counts[s] / total); |
| 198 | } |
James Zern | 04e84cf | 2011-11-04 15:20:08 -0700 | [diff] [blame] | 199 | fprintf(stderr, "| %7d\n", total); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static void PrintValues(const int values[4]) { |
| 203 | int s; |
| 204 | for (s = 0; s < 4; ++s) { |
| 205 | fprintf(stderr, "| %7d ", values[s]); |
| 206 | } |
James Zern | 04e84cf | 2011-11-04 15:20:08 -0700 | [diff] [blame] | 207 | fprintf(stderr, "|\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Pascal Massimino | 7d853d7 | 2012-07-24 16:15:36 -0700 | [diff] [blame] | 210 | static void PrintFullLosslessInfo(const WebPAuxStats* const stats, |
| 211 | const char* const description) { |
| 212 | fprintf(stderr, "Lossless-%s compressed size: %d bytes\n", |
| 213 | description, stats->lossless_size); |
| 214 | if (stats->lossless_features) { |
| 215 | fprintf(stderr, " * Lossless features used:"); |
| 216 | if (stats->lossless_features & 1) fprintf(stderr, " PREDICTION"); |
| 217 | if (stats->lossless_features & 2) fprintf(stderr, " CROSS-COLOR-TRANSFORM"); |
| 218 | if (stats->lossless_features & 4) fprintf(stderr, " SUBTRACT-GREEN"); |
| 219 | if (stats->lossless_features & 8) fprintf(stderr, " PALETTE"); |
| 220 | fprintf(stderr, "\n"); |
| 221 | } |
| 222 | fprintf(stderr, " * Precision Bits: histogram=%d transform=%d cache=%d\n", |
| 223 | stats->histogram_bits, stats->transform_bits, stats->cache_bits); |
| 224 | if (stats->palette_size > 0) { |
| 225 | fprintf(stderr, " * Palette size: %d\n", stats->palette_size); |
| 226 | } |
| 227 | } |
| 228 | |
Vikas Arora | c4ccab6 | 2012-05-09 11:27:46 +0530 | [diff] [blame] | 229 | static void PrintExtraInfoLossless(const WebPPicture* const pic, |
| 230 | int short_output, |
| 231 | const char* const file_name) { |
| 232 | const WebPAuxStats* const stats = pic->stats; |
| 233 | if (short_output) { |
| 234 | fprintf(stderr, "%7d %2.2f\n", stats->coded_size, stats->PSNR[3]); |
| 235 | } else { |
| 236 | fprintf(stderr, "File: %s\n", file_name); |
| 237 | fprintf(stderr, "Dimension: %d x %d\n", pic->width, pic->height); |
| 238 | fprintf(stderr, "Output: %d bytes\n", stats->coded_size); |
Pascal Massimino | 7d853d7 | 2012-07-24 16:15:36 -0700 | [diff] [blame] | 239 | PrintFullLosslessInfo(stats, "ARGB"); |
Vikas Arora | c4ccab6 | 2012-05-09 11:27:46 +0530 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | static void PrintExtraInfoLossy(const WebPPicture* const pic, int short_output, |
skal | 9bfbdd1 | 2013-03-12 00:37:42 +0100 | [diff] [blame] | 244 | int full_details, |
Vikas Arora | c4ccab6 | 2012-05-09 11:27:46 +0530 | [diff] [blame] | 245 | const char* const file_name) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 246 | const WebPAuxStats* const stats = pic->stats; |
| 247 | if (short_output) { |
| 248 | fprintf(stderr, "%7d %2.2f\n", stats->coded_size, stats->PSNR[3]); |
James Zern | 04e84cf | 2011-11-04 15:20:08 -0700 | [diff] [blame] | 249 | } else { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 250 | const int num_i4 = stats->block_count[0]; |
| 251 | const int num_i16 = stats->block_count[1]; |
| 252 | const int num_skip = stats->block_count[2]; |
| 253 | const int total = num_i4 + num_i16; |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 254 | fprintf(stderr, "File: %s\n", file_name); |
| 255 | fprintf(stderr, "Dimension: %d x %d%s\n", |
James Zern | c71ff9e | 2012-06-07 17:32:29 -0700 | [diff] [blame] | 256 | pic->width, pic->height, |
| 257 | stats->alpha_data_size ? " (with alpha)" : ""); |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 258 | fprintf(stderr, "Output: " |
| 259 | "%d bytes Y-U-V-All-PSNR %2.2f %2.2f %2.2f %2.2f dB\n", |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 260 | stats->coded_size, |
| 261 | stats->PSNR[0], stats->PSNR[1], stats->PSNR[2], stats->PSNR[3]); |
| 262 | if (total > 0) { |
| 263 | int totals[4] = { 0, 0, 0, 0 }; |
| 264 | fprintf(stderr, "block count: intra4: %d\n" |
| 265 | " intra16: %d (-> %.2f%%)\n", |
| 266 | num_i4, num_i16, 100.f * num_i16 / total); |
| 267 | fprintf(stderr, " skipped block: %d (%.2f%%)\n", |
| 268 | num_skip, 100.f * num_skip / total); |
| 269 | fprintf(stderr, "bytes used: header: %6d (%.1f%%)\n" |
| 270 | " mode-partition: %6d (%.1f%%)\n", |
| 271 | stats->header_bytes[0], |
| 272 | 100.f * stats->header_bytes[0] / stats->coded_size, |
| 273 | stats->header_bytes[1], |
| 274 | 100.f * stats->header_bytes[1] / stats->coded_size); |
Pascal Massimino | 7d853d7 | 2012-07-24 16:15:36 -0700 | [diff] [blame] | 275 | if (stats->alpha_data_size > 0) { |
| 276 | fprintf(stderr, " transparency: %6d (%.1f dB)\n", |
| 277 | stats->alpha_data_size, stats->PSNR[4]); |
Pascal Massimino | 2ab4b72 | 2011-04-25 16:58:04 -0700 | [diff] [blame] | 278 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 279 | fprintf(stderr, " Residuals bytes " |
| 280 | "|segment 1|segment 2|segment 3" |
| 281 | "|segment 4| total\n"); |
skal | 9bfbdd1 | 2013-03-12 00:37:42 +0100 | [diff] [blame] | 282 | if (full_details) { |
| 283 | fprintf(stderr, " intra4-coeffs: "); |
| 284 | PrintByteCount(stats->residual_bytes[0], stats->coded_size, totals); |
| 285 | fprintf(stderr, " intra16-coeffs: "); |
| 286 | PrintByteCount(stats->residual_bytes[1], stats->coded_size, totals); |
| 287 | fprintf(stderr, " chroma coeffs: "); |
| 288 | PrintByteCount(stats->residual_bytes[2], stats->coded_size, totals); |
| 289 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 290 | fprintf(stderr, " macroblocks: "); |
| 291 | PrintPercents(stats->segment_size, total); |
| 292 | fprintf(stderr, " quantizer: "); |
| 293 | PrintValues(stats->segment_quant); |
| 294 | fprintf(stderr, " filter level: "); |
| 295 | PrintValues(stats->segment_level); |
skal | 9bfbdd1 | 2013-03-12 00:37:42 +0100 | [diff] [blame] | 296 | if (full_details) { |
| 297 | fprintf(stderr, "------------------+---------"); |
| 298 | fprintf(stderr, "+---------+---------+---------+-----------------\n"); |
| 299 | fprintf(stderr, " segments total: "); |
| 300 | PrintByteCount(totals, stats->coded_size, NULL); |
| 301 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 302 | } |
Pascal Massimino | 7d853d7 | 2012-07-24 16:15:36 -0700 | [diff] [blame] | 303 | if (stats->lossless_size > 0) { |
| 304 | PrintFullLosslessInfo(stats, "alpha"); |
| 305 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 306 | } |
skal | fff2a11 | 2013-12-23 12:03:00 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static void PrintMapInfo(const WebPPicture* const pic) { |
Pascal Massimino | 7d853d7 | 2012-07-24 16:15:36 -0700 | [diff] [blame] | 310 | if (pic->extra_info != NULL) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 311 | const int mb_w = (pic->width + 15) / 16; |
| 312 | const int mb_h = (pic->height + 15) / 16; |
| 313 | const int type = pic->extra_info_type; |
| 314 | int x, y; |
| 315 | for (y = 0; y < mb_h; ++y) { |
| 316 | for (x = 0; x < mb_w; ++x) { |
| 317 | const int c = pic->extra_info[x + y * mb_w]; |
| 318 | if (type == 1) { // intra4/intra16 |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 319 | fprintf(stderr, "%c", "+."[c]); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 320 | } else if (type == 2) { // segments |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 321 | fprintf(stderr, "%c", ".-*X"[c]); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 322 | } else if (type == 3) { // quantizers |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 323 | fprintf(stderr, "%.2d ", c); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 324 | } else if (type == 6 || type == 7) { |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 325 | fprintf(stderr, "%3d ", c); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 326 | } else { |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 327 | fprintf(stderr, "0x%.2x ", c); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 328 | } |
| 329 | } |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 330 | fprintf(stderr, "\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
James Zern | c7e86ab | 2011-08-25 14:22:32 -0700 | [diff] [blame] | 335 | //------------------------------------------------------------------------------ |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 336 | |
| 337 | static int MyWriter(const uint8_t* data, size_t data_size, |
| 338 | const WebPPicture* const pic) { |
| 339 | FILE* const out = (FILE*)pic->custom_ptr; |
| 340 | return data_size ? (fwrite(data, data_size, 1, out) == 1) : 1; |
| 341 | } |
| 342 | |
| 343 | // Dumps a picture as a PGM file using the IMC4 layout. |
| 344 | static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) { |
| 345 | int y; |
| 346 | const int uv_width = (picture->width + 1) / 2; |
| 347 | const int uv_height = (picture->height + 1) / 2; |
| 348 | const int stride = (picture->width + 1) & ~1; |
Pascal Massimino | 437999f | 2012-06-04 15:50:05 -0700 | [diff] [blame] | 349 | const int alpha_height = |
| 350 | WebPPictureHasTransparency(picture) ? picture->height : 0; |
Pascal Massimino | 5142a0b | 2011-07-07 16:08:15 -0700 | [diff] [blame] | 351 | const int height = picture->height + uv_height + alpha_height; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 352 | FILE* const f = fopen(PGM_name, "wb"); |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 353 | if (f == NULL) return 0; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 354 | fprintf(f, "P5\n%d %d\n255\n", stride, height); |
| 355 | for (y = 0; y < picture->height; ++y) { |
| 356 | if (fwrite(picture->y + y * picture->y_stride, picture->width, 1, f) != 1) |
| 357 | return 0; |
| 358 | if (picture->width & 1) fputc(0, f); // pad |
| 359 | } |
| 360 | for (y = 0; y < uv_height; ++y) { |
| 361 | if (fwrite(picture->u + y * picture->uv_stride, uv_width, 1, f) != 1) |
| 362 | return 0; |
| 363 | if (fwrite(picture->v + y * picture->uv_stride, uv_width, 1, f) != 1) |
| 364 | return 0; |
| 365 | } |
Pascal Massimino | 5142a0b | 2011-07-07 16:08:15 -0700 | [diff] [blame] | 366 | for (y = 0; y < alpha_height; ++y) { |
| 367 | if (fwrite(picture->a + y * picture->a_stride, picture->width, 1, f) != 1) |
| 368 | return 0; |
| 369 | if (picture->width & 1) fputc(0, f); // pad |
| 370 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 371 | fclose(f); |
| 372 | return 1; |
| 373 | } |
| 374 | |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 375 | // ----------------------------------------------------------------------------- |
| 376 | // Metadata writing. |
| 377 | |
| 378 | enum { |
| 379 | METADATA_EXIF = (1 << 0), |
James Zern | d8dc72a | 2013-03-13 14:04:20 -0700 | [diff] [blame] | 380 | METADATA_ICC = (1 << 1), |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 381 | METADATA_XMP = (1 << 2), |
James Zern | d8dc72a | 2013-03-13 14:04:20 -0700 | [diff] [blame] | 382 | METADATA_ALL = METADATA_EXIF | METADATA_ICC | METADATA_XMP |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 383 | }; |
| 384 | |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 385 | static const int kChunkHeaderSize = 8; |
| 386 | static const int kTagSize = 4; |
| 387 | |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 388 | static void PrintMetadataInfo(const Metadata* const metadata, |
| 389 | int metadata_written) { |
| 390 | if (metadata == NULL || metadata_written == 0) return; |
| 391 | |
| 392 | fprintf(stderr, "Metadata:\n"); |
James Zern | 7dd288f | 2013-03-15 16:42:58 -0700 | [diff] [blame] | 393 | if (metadata_written & METADATA_ICC) { |
James Zern | 14d42af | 2013-03-20 16:59:35 -0700 | [diff] [blame] | 394 | fprintf(stderr, " * ICC profile: %6d bytes\n", (int)metadata->iccp.size); |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 395 | } |
| 396 | if (metadata_written & METADATA_EXIF) { |
James Zern | 14d42af | 2013-03-20 16:59:35 -0700 | [diff] [blame] | 397 | fprintf(stderr, " * EXIF data: %6d bytes\n", (int)metadata->exif.size); |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 398 | } |
| 399 | if (metadata_written & METADATA_XMP) { |
James Zern | 14d42af | 2013-03-20 16:59:35 -0700 | [diff] [blame] | 400 | fprintf(stderr, " * XMP data: %6d bytes\n", (int)metadata->xmp.size); |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 404 | // Outputs, in little endian, 'num' bytes from 'val' to 'out'. |
| 405 | static int WriteLE(FILE* const out, uint32_t val, int num) { |
| 406 | uint8_t buf[4]; |
| 407 | int i; |
| 408 | for (i = 0; i < num; ++i) { |
| 409 | buf[i] = (uint8_t)(val & 0xff); |
| 410 | val >>= 8; |
| 411 | } |
| 412 | return (fwrite(buf, num, 1, out) == 1); |
| 413 | } |
| 414 | |
| 415 | static int WriteLE24(FILE* const out, uint32_t val) { |
| 416 | return WriteLE(out, val, 3); |
| 417 | } |
| 418 | |
| 419 | static int WriteLE32(FILE* const out, uint32_t val) { |
| 420 | return WriteLE(out, val, 4); |
| 421 | } |
| 422 | |
| 423 | static int WriteMetadataChunk(FILE* const out, const char fourcc[4], |
| 424 | const MetadataPayload* const payload) { |
| 425 | const uint8_t zero = 0; |
| 426 | const size_t need_padding = payload->size & 1; |
| 427 | int ok = (fwrite(fourcc, kTagSize, 1, out) == 1); |
| 428 | ok = ok && WriteLE32(out, (uint32_t)payload->size); |
| 429 | ok = ok && (fwrite(payload->bytes, payload->size, 1, out) == 1); |
| 430 | return ok && (fwrite(&zero, need_padding, need_padding, out) == need_padding); |
| 431 | } |
| 432 | |
| 433 | // Sets 'flag' in 'vp8x_flags' and updates 'metadata_size' with the size of the |
| 434 | // chunk if there is metadata and 'keep' is true. |
| 435 | static int UpdateFlagsAndSize(const MetadataPayload* const payload, |
| 436 | int keep, int flag, |
| 437 | uint32_t* vp8x_flags, uint64_t* metadata_size) { |
| 438 | if (keep && payload->bytes != NULL && payload->size > 0) { |
| 439 | *vp8x_flags |= flag; |
| 440 | *metadata_size += kChunkHeaderSize + payload->size + (payload->size & 1); |
| 441 | return 1; |
| 442 | } |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | // Writes a WebP file using the image contained in 'memory_writer' and the |
| 447 | // metadata from 'metadata'. Metadata is controlled by 'keep_metadata' and the |
| 448 | // availability in 'metadata'. Returns true on success. |
| 449 | // For details see doc/webp-container-spec.txt#extended-file-format. |
| 450 | static int WriteWebPWithMetadata(FILE* const out, |
| 451 | const WebPPicture* const picture, |
| 452 | const WebPMemoryWriter* const memory_writer, |
| 453 | const Metadata* const metadata, |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 454 | int keep_metadata, |
| 455 | int* const metadata_written) { |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 456 | const char kVP8XHeader[] = "VP8X\x0a\x00\x00\x00"; |
| 457 | const int kAlphaFlag = 0x10; |
| 458 | const int kEXIFFlag = 0x08; |
| 459 | const int kICCPFlag = 0x20; |
| 460 | const int kXMPFlag = 0x04; |
| 461 | const size_t kRiffHeaderSize = 12; |
| 462 | const size_t kMaxChunkPayload = ~0 - kChunkHeaderSize - 1; |
| 463 | const size_t kMinSize = kRiffHeaderSize + kChunkHeaderSize; |
| 464 | uint32_t flags = 0; |
| 465 | uint64_t metadata_size = 0; |
| 466 | const int write_exif = UpdateFlagsAndSize(&metadata->exif, |
| 467 | !!(keep_metadata & METADATA_EXIF), |
| 468 | kEXIFFlag, &flags, &metadata_size); |
| 469 | const int write_iccp = UpdateFlagsAndSize(&metadata->iccp, |
James Zern | d8dc72a | 2013-03-13 14:04:20 -0700 | [diff] [blame] | 470 | !!(keep_metadata & METADATA_ICC), |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 471 | kICCPFlag, &flags, &metadata_size); |
| 472 | const int write_xmp = UpdateFlagsAndSize(&metadata->xmp, |
| 473 | !!(keep_metadata & METADATA_XMP), |
| 474 | kXMPFlag, &flags, &metadata_size); |
| 475 | uint8_t* webp = memory_writer->mem; |
| 476 | size_t webp_size = memory_writer->size; |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 477 | |
| 478 | *metadata_written = 0; |
| 479 | |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 480 | if (webp_size < kMinSize) return 0; |
| 481 | if (webp_size - kChunkHeaderSize + metadata_size > kMaxChunkPayload) { |
| 482 | fprintf(stderr, "Error! Addition of metadata would exceed " |
| 483 | "container size limit.\n"); |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | if (metadata_size > 0) { |
| 488 | const int kVP8XChunkSize = 18; |
| 489 | const int has_vp8x = !memcmp(webp + kRiffHeaderSize, "VP8X", kTagSize); |
| 490 | const uint32_t riff_size = (uint32_t)(webp_size - kChunkHeaderSize + |
| 491 | (has_vp8x ? 0 : kVP8XChunkSize) + |
| 492 | metadata_size); |
| 493 | // RIFF |
| 494 | int ok = (fwrite(webp, kTagSize, 1, out) == 1); |
| 495 | // RIFF size (file header size is not recorded) |
| 496 | ok = ok && WriteLE32(out, riff_size); |
| 497 | webp += kChunkHeaderSize; |
| 498 | webp_size -= kChunkHeaderSize; |
| 499 | // WEBP |
| 500 | ok = ok && (fwrite(webp, kTagSize, 1, out) == 1); |
| 501 | webp += kTagSize; |
| 502 | webp_size -= kTagSize; |
| 503 | if (has_vp8x) { // update the existing VP8X flags |
| 504 | webp[kChunkHeaderSize] |= (uint8_t)(flags & 0xff); |
| 505 | ok = ok && (fwrite(webp, kVP8XChunkSize, 1, out) == 1); |
James Zern | b5b2e3c | 2013-12-19 10:17:08 -0800 | [diff] [blame] | 506 | webp += kVP8XChunkSize; |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 507 | webp_size -= kVP8XChunkSize; |
| 508 | } else { |
| 509 | const int is_lossless = !memcmp(webp, "VP8L", kTagSize); |
Urvang Joshi | 8ba1bf6 | 2013-07-19 11:55:09 -0700 | [diff] [blame] | 510 | if (is_lossless) { |
| 511 | // Presence of alpha is stored in the 29th bit of VP8L data. |
| 512 | if (webp[kChunkHeaderSize + 3] & (1 << 5)) flags |= kAlphaFlag; |
| 513 | } |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 514 | ok = ok && (fwrite(kVP8XHeader, kChunkHeaderSize, 1, out) == 1); |
| 515 | ok = ok && WriteLE32(out, flags); |
| 516 | ok = ok && WriteLE24(out, picture->width - 1); |
| 517 | ok = ok && WriteLE24(out, picture->height - 1); |
| 518 | } |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 519 | if (write_iccp) { |
| 520 | ok = ok && WriteMetadataChunk(out, "ICCP", &metadata->iccp); |
James Zern | 7dd288f | 2013-03-15 16:42:58 -0700 | [diff] [blame] | 521 | *metadata_written |= METADATA_ICC; |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 522 | } |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 523 | // Image |
| 524 | ok = ok && (fwrite(webp, webp_size, 1, out) == 1); |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 525 | if (write_exif) { |
| 526 | ok = ok && WriteMetadataChunk(out, "EXIF", &metadata->exif); |
| 527 | *metadata_written |= METADATA_EXIF; |
| 528 | } |
| 529 | if (write_xmp) { |
| 530 | ok = ok && WriteMetadataChunk(out, "XMP ", &metadata->xmp); |
| 531 | *metadata_written |= METADATA_XMP; |
| 532 | } |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 533 | return ok; |
| 534 | } else { |
| 535 | // No metadata, just write the original image file. |
| 536 | return (fwrite(webp, webp_size, 1, out) == 1); |
| 537 | } |
| 538 | } |
| 539 | |
James Zern | c7e86ab | 2011-08-25 14:22:32 -0700 | [diff] [blame] | 540 | //------------------------------------------------------------------------------ |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 541 | |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 542 | static int ProgressReport(int percent, const WebPPicture* const picture) { |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 543 | fprintf(stderr, "[%s]: %3d %% \r", |
| 544 | (char*)picture->user_data, percent); |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 545 | return 1; // all ok |
| 546 | } |
| 547 | |
| 548 | //------------------------------------------------------------------------------ |
| 549 | |
Pascal Massimino | f8db5d5 | 2011-03-25 15:04:11 -0700 | [diff] [blame] | 550 | static void HelpShort(void) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 551 | printf("Usage:\n\n"); |
| 552 | printf(" cwebp [options] -q quality input.png -o output.webp\n\n"); |
| 553 | printf("where quality is between 0 (poor) to 100 (very good).\n"); |
| 554 | printf("Typical value is around 80.\n\n"); |
| 555 | printf("Try -longhelp for an exhaustive list of advanced options.\n"); |
| 556 | } |
| 557 | |
Pascal Massimino | f8db5d5 | 2011-03-25 15:04:11 -0700 | [diff] [blame] | 558 | static void HelpLong(void) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 559 | printf("Usage:\n"); |
| 560 | printf(" cwebp [-preset <...>] [options] in_file [-o out_file]\n\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 561 | printf("If input size (-s) for an image is not specified, it is\n" |
| 562 | "assumed to be a PNG, JPEG, TIFF or WebP file.\n"); |
James Zern | 31f9dc6 | 2011-06-06 17:56:50 -0700 | [diff] [blame] | 563 | #ifdef HAVE_WINCODEC_H |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 564 | printf("Windows builds can take as input any of the files handled by WIC.\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 565 | #endif |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 566 | printf("\nOptions:\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 567 | printf(" -h / -help ............ short help\n"); |
| 568 | printf(" -H / -longhelp ........ long help\n"); |
| 569 | printf(" -q <float> ............. quality factor (0:small..100:big)\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 570 | printf(" -alpha_q <int> ......... transparency-compression quality " |
| 571 | "(0..100)\n"); |
| 572 | printf(" -preset <string> ....... preset setting, one of:\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 573 | printf(" default, photo, picture,\n"); |
| 574 | printf(" drawing, icon, text\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 575 | printf(" -preset must come first, as it overwrites other parameters\n"); |
| 576 | printf(" -z <int> ............... activates lossless preset with given\n" |
skal | 65b99f1 | 2014-03-11 23:25:35 +0100 | [diff] [blame] | 577 | " level in [0:fast, ..., 9:slowest]\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 578 | printf("\n"); |
| 579 | printf(" -m <int> ............... compression method (0=fast, 6=slowest)\n"); |
| 580 | printf(" -segments <int> ........ number of segments to use (1..4)\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 581 | printf(" -size <int> ............ target size (in bytes)\n"); |
| 582 | printf(" -psnr <float> .......... target PSNR (in dB. typically: 42)\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 583 | printf("\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 584 | printf(" -s <int> <int> ......... input size (width x height) for YUV\n"); |
| 585 | printf(" -sns <int> ............. spatial noise shaping (0:off, 100:max)\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 586 | printf(" -f <int> ............... filter strength (0=off..100)\n"); |
| 587 | printf(" -sharpness <int> ....... " |
| 588 | "filter sharpness (0:most .. 7:least sharp)\n"); |
Pascal Massimino | 92668da | 2013-02-15 01:08:52 -0800 | [diff] [blame] | 589 | printf(" -strong ................ use strong filter instead " |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 590 | "of simple (default)\n"); |
| 591 | printf(" -nostrong .............. use simple filter instead of strong\n"); |
Pascal Massimino | 900286e | 2011-08-23 15:58:22 -0700 | [diff] [blame] | 592 | printf(" -partition_limit <int> . limit quality to fit the 512k limit on\n"); |
| 593 | printf(" " |
| 594 | "the first partition (0=no degradation ... 100=full)\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 595 | printf(" -pass <int> ............ analysis pass number (1..10)\n"); |
| 596 | printf(" -crop <x> <y> <w> <h> .. crop picture with the given rectangle\n"); |
Pascal Massimino | 6d0e66c | 2011-05-02 17:19:00 -0700 | [diff] [blame] | 597 | printf(" -resize <w> <h> ........ resize picture (after any cropping)\n"); |
skal | f817930 | 2013-03-01 01:21:34 +0100 | [diff] [blame] | 598 | printf(" -mt .................... use multi-threading if available\n"); |
skal | 9bfbdd1 | 2013-03-12 00:37:42 +0100 | [diff] [blame] | 599 | printf(" -low_memory ............ reduce memory usage (slower encoding)\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 600 | printf(" -map <int> ............. print map of extra info\n"); |
| 601 | printf(" -print_psnr ............ prints averaged PSNR distortion\n"); |
| 602 | printf(" -print_ssim ............ prints averaged SSIM distortion\n"); |
| 603 | printf(" -print_lsim ............ prints local-similarity distortion\n"); |
| 604 | printf(" -d <file.pgm> .......... dump the compressed output (PGM file)\n"); |
| 605 | printf(" -alpha_method <int> .... transparency-compression method (0..1)\n"); |
| 606 | printf(" -alpha_filter <string> . predictive filtering for alpha plane,\n"); |
| 607 | printf(" one of: none, fast (default) or best\n"); |
| 608 | printf(" -alpha_cleanup ......... clean RGB values in transparent area\n"); |
| 609 | printf(" -blend_alpha <hex> ..... blend colors against background color\n" |
Pascal Massimino | e7d9548 | 2013-04-02 19:14:14 -0700 | [diff] [blame] | 610 | " expressed as RGB values written in\n" |
| 611 | " hexadecimal, e.g. 0xc0e0d0 for red=0xc0\n" |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 612 | " green=0xe0 and blue=0xd0\n"); |
| 613 | printf(" -noalpha ............... discard any transparency information\n"); |
| 614 | printf(" -lossless .............. encode image losslessly\n"); |
| 615 | printf(" -hint <string> ......... specify image characteristics hint,\n"); |
| 616 | printf(" one of: photo, picture or graph\n"); |
Pascal Massimino | 6d0e66c | 2011-05-02 17:19:00 -0700 | [diff] [blame] | 617 | |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 618 | printf("\n"); |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 619 | printf(" -metadata <string> ..... comma separated list of metadata to\n"); |
| 620 | printf(" "); |
| 621 | printf("copy from the input to the output if present.\n"); |
| 622 | printf(" " |
James Zern | d8dc72a | 2013-03-13 14:04:20 -0700 | [diff] [blame] | 623 | "Valid values: all, none (default), exif, icc, xmp\n"); |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 624 | |
| 625 | printf("\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 626 | printf(" -short ................. condense printed message\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 627 | printf(" -quiet ................. don't print anything\n"); |
| 628 | printf(" -version ............... print version number and exit\n"); |
James Zern | b4d0ef8 | 2011-07-15 14:53:03 -0700 | [diff] [blame] | 629 | #ifndef WEBP_DLL |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 630 | printf(" -noasm ................. disable all assembly optimizations\n"); |
James Zern | b4d0ef8 | 2011-07-15 14:53:03 -0700 | [diff] [blame] | 631 | #endif |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 632 | printf(" -v ..................... verbose, e.g. print encoding/decoding " |
| 633 | "times\n"); |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 634 | printf(" -progress .............. report encoding progress\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 635 | printf("\n"); |
| 636 | printf("Experimental Options:\n"); |
skal | 0a8b886 | 2014-06-18 16:45:34 +0200 | [diff] [blame] | 637 | printf(" -jpeg_like ............. roughly match expected JPEG size\n"); |
| 638 | printf(" -af .................... auto-adjust filter strength\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 639 | printf(" -pre <int> ............. pre-processing filter\n"); |
| 640 | printf("\n"); |
| 641 | } |
| 642 | |
James Zern | c7e86ab | 2011-08-25 14:22:32 -0700 | [diff] [blame] | 643 | //------------------------------------------------------------------------------ |
Pascal Massimino | ca7a2fd | 2011-06-02 06:55:03 -0700 | [diff] [blame] | 644 | // Error messages |
| 645 | |
skal | 0b747b1 | 2014-07-21 15:44:43 +0200 | [diff] [blame] | 646 | static const char* const kErrorMessages[VP8_ENC_ERROR_LAST] = { |
Pascal Massimino | ca7a2fd | 2011-06-02 06:55:03 -0700 | [diff] [blame] | 647 | "OK", |
| 648 | "OUT_OF_MEMORY: Out of memory allocating objects", |
| 649 | "BITSTREAM_OUT_OF_MEMORY: Out of memory re-allocating byte buffer", |
| 650 | "NULL_PARAMETER: NULL parameter passed to function", |
| 651 | "INVALID_CONFIGURATION: configuration is invalid", |
Pascal Massimino | 900286e | 2011-08-23 15:58:22 -0700 | [diff] [blame] | 652 | "BAD_DIMENSION: Bad picture dimension. Maximum width and height " |
| 653 | "allowed is 16383 pixels.", |
| 654 | "PARTITION0_OVERFLOW: Partition #0 is too big to fit 512k.\n" |
| 655 | "To reduce the size of this partition, try using less segments " |
| 656 | "with the -segments option, and eventually reduce the number of " |
| 657 | "header bits using -partition_limit. More details are available " |
| 658 | "in the manual (`man cwebp`)", |
| 659 | "PARTITION_OVERFLOW: Partition is too big to fit 16M", |
Pascal Massimino | d71fbdc | 2011-12-01 03:34:22 -0800 | [diff] [blame] | 660 | "BAD_WRITE: Picture writer returned an I/O error", |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 661 | "FILE_TOO_BIG: File would be too big to fit in 4G", |
| 662 | "USER_ABORT: encoding abort requested by user" |
Pascal Massimino | ca7a2fd | 2011-06-02 06:55:03 -0700 | [diff] [blame] | 663 | }; |
| 664 | |
James Zern | c7e86ab | 2011-08-25 14:22:32 -0700 | [diff] [blame] | 665 | //------------------------------------------------------------------------------ |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 666 | |
| 667 | int main(int argc, const char *argv[]) { |
Pascal Massimino | 4abe04a | 2012-05-09 00:32:20 -0700 | [diff] [blame] | 668 | int return_value = -1; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 669 | const char *in_file = NULL, *out_file = NULL, *dump_file = NULL; |
| 670 | FILE *out = NULL; |
| 671 | int c; |
| 672 | int short_output = 0; |
| 673 | int quiet = 0; |
Vikas Arora | a0ec9aa | 2011-12-01 15:11:34 +0530 | [diff] [blame] | 674 | int keep_alpha = 1; |
Pascal Massimino | e7d9548 | 2013-04-02 19:14:14 -0700 | [diff] [blame] | 675 | int blend_alpha = 0; |
| 676 | uint32_t background_color = 0xffffffu; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 677 | int crop = 0, crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0; |
Pascal Massimino | 6d0e66c | 2011-05-02 17:19:00 -0700 | [diff] [blame] | 678 | int resize_w = 0, resize_h = 0; |
skal | 65b99f1 | 2014-03-11 23:25:35 +0100 | [diff] [blame] | 679 | int lossless_preset = 6; |
| 680 | int use_lossless_preset = -1; // -1=unset, 0=don't use, 1=use it |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 681 | int show_progress = 0; |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 682 | int keep_metadata = 0; |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 683 | int metadata_written = 0; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 684 | WebPPicture picture; |
Pascal Massimino | f86e6ab | 2012-10-18 08:26:40 -0700 | [diff] [blame] | 685 | int print_distortion = -1; // -1=off, 0=PSNR, 1=SSIM, 2=LSIM |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 686 | WebPPicture original_picture; // when PSNR or SSIM is requested |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 687 | WebPConfig config; |
| 688 | WebPAuxStats stats; |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 689 | WebPMemoryWriter memory_writer; |
James Zern | 63aba3a | 2012-12-03 18:20:00 -0800 | [diff] [blame] | 690 | Metadata metadata; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 691 | Stopwatch stop_watch; |
Pascal Massimino | 6d0e66c | 2011-05-02 17:19:00 -0700 | [diff] [blame] | 692 | |
James Zern | 63aba3a | 2012-12-03 18:20:00 -0800 | [diff] [blame] | 693 | MetadataInit(&metadata); |
James Zern | 88d382a | 2013-02-01 19:17:26 -0800 | [diff] [blame] | 694 | WebPMemoryWriterInit(&memory_writer); |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 695 | if (!WebPPictureInit(&picture) || |
| 696 | !WebPPictureInit(&original_picture) || |
| 697 | !WebPConfigInit(&config)) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 698 | fprintf(stderr, "Error! Version mismatch!\n"); |
James Zern | 256afef | 2012-07-27 18:56:55 -0700 | [diff] [blame] | 699 | return -1; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | if (argc == 1) { |
| 703 | HelpShort(); |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | for (c = 1; c < argc; ++c) { |
| 708 | if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { |
| 709 | HelpShort(); |
| 710 | return 0; |
| 711 | } else if (!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) { |
| 712 | HelpLong(); |
| 713 | return 0; |
| 714 | } else if (!strcmp(argv[c], "-o") && c < argc - 1) { |
| 715 | out_file = argv[++c]; |
| 716 | } else if (!strcmp(argv[c], "-d") && c < argc - 1) { |
| 717 | dump_file = argv[++c]; |
| 718 | config.show_compressed = 1; |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 719 | } else if (!strcmp(argv[c], "-print_psnr")) { |
| 720 | config.show_compressed = 1; |
Pascal Massimino | f86e6ab | 2012-10-18 08:26:40 -0700 | [diff] [blame] | 721 | print_distortion = 0; |
| 722 | } else if (!strcmp(argv[c], "-print_ssim")) { |
| 723 | config.show_compressed = 1; |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 724 | print_distortion = 1; |
Pascal Massimino | f86e6ab | 2012-10-18 08:26:40 -0700 | [diff] [blame] | 725 | } else if (!strcmp(argv[c], "-print_lsim")) { |
| 726 | config.show_compressed = 1; |
| 727 | print_distortion = 2; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 728 | } else if (!strcmp(argv[c], "-short")) { |
skal | fff2a11 | 2013-12-23 12:03:00 +0100 | [diff] [blame] | 729 | ++short_output; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 730 | } else if (!strcmp(argv[c], "-s") && c < argc - 2) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 731 | picture.width = strtol(argv[++c], NULL, 0); |
| 732 | picture.height = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 733 | } else if (!strcmp(argv[c], "-m") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 734 | config.method = strtol(argv[++c], NULL, 0); |
skal | 65b99f1 | 2014-03-11 23:25:35 +0100 | [diff] [blame] | 735 | use_lossless_preset = 0; // disable -z option |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 736 | } else if (!strcmp(argv[c], "-q") && c < argc - 1) { |
Mikolaj Zalewski | 2aa6b80 | 2011-06-28 16:02:56 +0200 | [diff] [blame] | 737 | config.quality = (float)strtod(argv[++c], NULL); |
skal | 65b99f1 | 2014-03-11 23:25:35 +0100 | [diff] [blame] | 738 | use_lossless_preset = 0; // disable -z option |
| 739 | } else if (!strcmp(argv[c], "-z") && c < argc - 1) { |
| 740 | lossless_preset = strtol(argv[++c], NULL, 0); |
| 741 | if (use_lossless_preset != 0) use_lossless_preset = 1; |
Vikas Arora | a0ec9aa | 2011-12-01 15:11:34 +0530 | [diff] [blame] | 742 | } else if (!strcmp(argv[c], "-alpha_q") && c < argc - 1) { |
| 743 | config.alpha_quality = strtol(argv[++c], NULL, 0); |
| 744 | } else if (!strcmp(argv[c], "-alpha_method") && c < argc - 1) { |
| 745 | config.alpha_compression = strtol(argv[++c], NULL, 0); |
Pascal Massimino | 2e3e8b2 | 2012-01-17 08:18:22 +0000 | [diff] [blame] | 746 | } else if (!strcmp(argv[c], "-alpha_cleanup")) { |
| 747 | keep_alpha = keep_alpha ? 2 : 0; |
Pascal Massimino | e7d9548 | 2013-04-02 19:14:14 -0700 | [diff] [blame] | 748 | } else if (!strcmp(argv[c], "-blend_alpha") && c < argc - 1) { |
| 749 | blend_alpha = 1; |
| 750 | background_color = strtol(argv[++c], NULL, 16); // <- parses '0x' prefix |
| 751 | background_color = background_color & 0x00ffffffu; |
Vikas Arora | 252028a | 2012-01-05 13:04:30 +0530 | [diff] [blame] | 752 | } else if (!strcmp(argv[c], "-alpha_filter") && c < argc - 1) { |
Pascal Massimino | 8ca2076 | 2012-01-08 19:27:21 -0800 | [diff] [blame] | 753 | ++c; |
| 754 | if (!strcmp(argv[c], "none")) { |
| 755 | config.alpha_filtering = 0; |
| 756 | } else if (!strcmp(argv[c], "fast")) { |
| 757 | config.alpha_filtering = 1; |
| 758 | } else if (!strcmp(argv[c], "best")) { |
| 759 | config.alpha_filtering = 2; |
| 760 | } else { |
| 761 | fprintf(stderr, "Error! Unrecognized alpha filter: %s\n", argv[c]); |
| 762 | goto Error; |
| 763 | } |
Vikas Arora | a0ec9aa | 2011-12-01 15:11:34 +0530 | [diff] [blame] | 764 | } else if (!strcmp(argv[c], "-noalpha")) { |
| 765 | keep_alpha = 0; |
Pascal Massimino | 72920ca | 2012-04-24 10:59:08 +0000 | [diff] [blame] | 766 | } else if (!strcmp(argv[c], "-lossless")) { |
| 767 | config.lossless = 1; |
Vikas Arora | d373076 | 2012-06-22 12:14:48 +0530 | [diff] [blame] | 768 | } else if (!strcmp(argv[c], "-hint") && c < argc - 1) { |
| 769 | ++c; |
| 770 | if (!strcmp(argv[c], "photo")) { |
| 771 | config.image_hint = WEBP_HINT_PHOTO; |
| 772 | } else if (!strcmp(argv[c], "picture")) { |
| 773 | config.image_hint = WEBP_HINT_PICTURE; |
Vikas Arora | dd1c387 | 2012-07-31 23:07:52 -0700 | [diff] [blame] | 774 | } else if (!strcmp(argv[c], "graph")) { |
| 775 | config.image_hint = WEBP_HINT_GRAPH; |
Vikas Arora | d373076 | 2012-06-22 12:14:48 +0530 | [diff] [blame] | 776 | } else { |
| 777 | fprintf(stderr, "Error! Unrecognized image hint: %s\n", argv[c]); |
| 778 | goto Error; |
| 779 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 780 | } else if (!strcmp(argv[c], "-size") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 781 | config.target_size = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 782 | } else if (!strcmp(argv[c], "-psnr") && c < argc - 1) { |
Mikolaj Zalewski | 2aa6b80 | 2011-06-28 16:02:56 +0200 | [diff] [blame] | 783 | config.target_PSNR = (float)strtod(argv[++c], NULL); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 784 | } else if (!strcmp(argv[c], "-sns") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 785 | config.sns_strength = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 786 | } else if (!strcmp(argv[c], "-f") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 787 | config.filter_strength = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 788 | } else if (!strcmp(argv[c], "-af")) { |
| 789 | config.autofilter = 1; |
skal | e895059 | 2013-02-05 19:40:18 +0100 | [diff] [blame] | 790 | } else if (!strcmp(argv[c], "-jpeg_like")) { |
| 791 | config.emulate_jpeg_size = 1; |
skal | f817930 | 2013-03-01 01:21:34 +0100 | [diff] [blame] | 792 | } else if (!strcmp(argv[c], "-mt")) { |
| 793 | ++config.thread_level; // increase thread level |
skal | 9bfbdd1 | 2013-03-12 00:37:42 +0100 | [diff] [blame] | 794 | } else if (!strcmp(argv[c], "-low_memory")) { |
| 795 | config.low_memory = 1; |
Pascal Massimino | 842c009 | 2011-05-05 18:10:08 -0700 | [diff] [blame] | 796 | } else if (!strcmp(argv[c], "-strong")) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 797 | config.filter_type = 1; |
Pascal Massimino | 92668da | 2013-02-15 01:08:52 -0800 | [diff] [blame] | 798 | } else if (!strcmp(argv[c], "-nostrong")) { |
| 799 | config.filter_type = 0; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 800 | } else if (!strcmp(argv[c], "-sharpness") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 801 | config.filter_sharpness = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 802 | } else if (!strcmp(argv[c], "-pass") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 803 | config.pass = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 804 | } else if (!strcmp(argv[c], "-pre") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 805 | config.preprocessing = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 806 | } else if (!strcmp(argv[c], "-segments") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 807 | config.segments = strtol(argv[++c], NULL, 0); |
Pascal Massimino | 900286e | 2011-08-23 15:58:22 -0700 | [diff] [blame] | 808 | } else if (!strcmp(argv[c], "-partition_limit") && c < argc - 1) { |
| 809 | config.partition_limit = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 810 | } else if (!strcmp(argv[c], "-map") && c < argc - 1) { |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 811 | picture.extra_info_type = strtol(argv[++c], NULL, 0); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 812 | } else if (!strcmp(argv[c], "-crop") && c < argc - 4) { |
| 813 | crop = 1; |
Pascal Massimino | 4b0b0d6 | 2011-03-26 09:27:45 -0700 | [diff] [blame] | 814 | crop_x = strtol(argv[++c], NULL, 0); |
| 815 | crop_y = strtol(argv[++c], NULL, 0); |
| 816 | crop_w = strtol(argv[++c], NULL, 0); |
| 817 | crop_h = strtol(argv[++c], NULL, 0); |
Pascal Massimino | 6d0e66c | 2011-05-02 17:19:00 -0700 | [diff] [blame] | 818 | } else if (!strcmp(argv[c], "-resize") && c < argc - 2) { |
| 819 | resize_w = strtol(argv[++c], NULL, 0); |
| 820 | resize_h = strtol(argv[++c], NULL, 0); |
James Zern | b4d0ef8 | 2011-07-15 14:53:03 -0700 | [diff] [blame] | 821 | #ifndef WEBP_DLL |
Pascal Massimino | cfbf88a | 2011-04-22 12:14:45 -0700 | [diff] [blame] | 822 | } else if (!strcmp(argv[c], "-noasm")) { |
Pascal Massimino | e06ac08 | 2011-09-02 21:30:08 +0000 | [diff] [blame] | 823 | VP8GetCPUInfo = NULL; |
James Zern | b4d0ef8 | 2011-07-15 14:53:03 -0700 | [diff] [blame] | 824 | #endif |
Pascal Massimino | 650ffa3 | 2011-03-24 16:17:10 -0700 | [diff] [blame] | 825 | } else if (!strcmp(argv[c], "-version")) { |
| 826 | const int version = WebPGetEncoderVersion(); |
| 827 | printf("%d.%d.%d\n", |
| 828 | (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff); |
| 829 | return 0; |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 830 | } else if (!strcmp(argv[c], "-progress")) { |
| 831 | show_progress = 1; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 832 | } else if (!strcmp(argv[c], "-quiet")) { |
| 833 | quiet = 1; |
| 834 | } else if (!strcmp(argv[c], "-preset") && c < argc - 1) { |
| 835 | WebPPreset preset; |
| 836 | ++c; |
| 837 | if (!strcmp(argv[c], "default")) { |
| 838 | preset = WEBP_PRESET_DEFAULT; |
| 839 | } else if (!strcmp(argv[c], "photo")) { |
| 840 | preset = WEBP_PRESET_PHOTO; |
| 841 | } else if (!strcmp(argv[c], "picture")) { |
| 842 | preset = WEBP_PRESET_PICTURE; |
| 843 | } else if (!strcmp(argv[c], "drawing")) { |
| 844 | preset = WEBP_PRESET_DRAWING; |
| 845 | } else if (!strcmp(argv[c], "icon")) { |
| 846 | preset = WEBP_PRESET_ICON; |
| 847 | } else if (!strcmp(argv[c], "text")) { |
| 848 | preset = WEBP_PRESET_TEXT; |
| 849 | } else { |
| 850 | fprintf(stderr, "Error! Unrecognized preset: %s\n", argv[c]); |
| 851 | goto Error; |
| 852 | } |
| 853 | if (!WebPConfigPreset(&config, preset, config.quality)) { |
Pascal Massimino | 6d978a6 | 2011-03-17 14:49:19 -0700 | [diff] [blame] | 854 | fprintf(stderr, "Error! Could initialize configuration with preset.\n"); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 855 | goto Error; |
| 856 | } |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 857 | } else if (!strcmp(argv[c], "-metadata") && c < argc - 1) { |
| 858 | static const struct { |
| 859 | const char* option; |
| 860 | int flag; |
| 861 | } kTokens[] = { |
| 862 | { "all", METADATA_ALL }, |
| 863 | { "none", 0 }, |
| 864 | { "exif", METADATA_EXIF }, |
James Zern | d8dc72a | 2013-03-13 14:04:20 -0700 | [diff] [blame] | 865 | { "icc", METADATA_ICC }, |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 866 | { "xmp", METADATA_XMP }, |
| 867 | }; |
| 868 | const size_t kNumTokens = sizeof(kTokens) / sizeof(kTokens[0]); |
| 869 | const char* start = argv[++c]; |
| 870 | const char* const end = start + strlen(start); |
| 871 | |
| 872 | while (start < end) { |
| 873 | size_t i; |
| 874 | const char* token = strchr(start, ','); |
| 875 | if (token == NULL) token = end; |
| 876 | |
| 877 | for (i = 0; i < kNumTokens; ++i) { |
| 878 | if ((size_t)(token - start) == strlen(kTokens[i].option) && |
| 879 | !strncmp(start, kTokens[i].option, strlen(kTokens[i].option))) { |
| 880 | if (kTokens[i].flag != 0) { |
| 881 | keep_metadata |= kTokens[i].flag; |
| 882 | } else { |
| 883 | keep_metadata = 0; |
| 884 | } |
| 885 | break; |
| 886 | } |
| 887 | } |
| 888 | if (i == kNumTokens) { |
| 889 | fprintf(stderr, "Error! Unknown metadata type '%.*s'\n", |
| 890 | (int)(token - start), start); |
| 891 | HelpLong(); |
| 892 | return -1; |
| 893 | } |
| 894 | start = token + 1; |
| 895 | } |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 896 | #ifdef HAVE_WINCODEC_H |
James Zern | d8dc72a | 2013-03-13 14:04:20 -0700 | [diff] [blame] | 897 | if (keep_metadata != 0 && keep_metadata != METADATA_ICC) { |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 898 | // TODO(jzern): remove when -metadata is supported on all platforms. |
James Zern | e83ff7d | 2013-01-24 15:37:49 -0800 | [diff] [blame] | 899 | fprintf(stderr, "Warning: only ICC profile extraction is currently" |
| 900 | " supported on this platform!\n"); |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 901 | } |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 902 | #endif |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 903 | } else if (!strcmp(argv[c], "-v")) { |
| 904 | verbose = 1; |
James Zern | 98af68f | 2013-12-12 20:20:08 -0800 | [diff] [blame] | 905 | } else if (!strcmp(argv[c], "--")) { |
| 906 | if (c < argc - 1) in_file = argv[++c]; |
| 907 | break; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 908 | } else if (argv[c][0] == '-') { |
| 909 | fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]); |
| 910 | HelpLong(); |
| 911 | return -1; |
| 912 | } else { |
| 913 | in_file = argv[c]; |
| 914 | } |
| 915 | } |
Pascal Massimino | 4abe04a | 2012-05-09 00:32:20 -0700 | [diff] [blame] | 916 | if (in_file == NULL) { |
| 917 | fprintf(stderr, "No input file specified!\n"); |
| 918 | HelpShort(); |
| 919 | goto Error; |
| 920 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 921 | |
skal | 65b99f1 | 2014-03-11 23:25:35 +0100 | [diff] [blame] | 922 | if (use_lossless_preset == 1) { |
| 923 | if (!WebPConfigLosslessPreset(&config, lossless_preset)) { |
| 924 | fprintf(stderr, "Invalid lossless preset (-z %d)\n", lossless_preset); |
| 925 | goto Error; |
| 926 | } |
| 927 | } |
| 928 | |
Vikas Arora | b7fb0ed | 2012-06-20 09:02:25 +0530 | [diff] [blame] | 929 | // Check for unsupported command line options for lossless mode and log |
| 930 | // warning for such options. |
Pascal Massimino | 0275159 | 2012-06-20 09:20:34 +0000 | [diff] [blame] | 931 | if (!quiet && config.lossless == 1) { |
Vikas Arora | b7fb0ed | 2012-06-20 09:02:25 +0530 | [diff] [blame] | 932 | if (config.target_size > 0 || config.target_PSNR > 0) { |
| 933 | fprintf(stderr, "Encoding for specified size or PSNR is not supported" |
| 934 | " for lossless encoding. Ignoring such option(s)!\n"); |
| 935 | } |
| 936 | if (config.partition_limit > 0) { |
| 937 | fprintf(stderr, "Partition limit option is not required for lossless" |
| 938 | " encoding. Ignoring this option!\n"); |
| 939 | } |
Vikas Arora | b7fb0ed | 2012-06-20 09:02:25 +0530 | [diff] [blame] | 940 | } |
| 941 | |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 942 | if (!WebPValidateConfig(&config)) { |
| 943 | fprintf(stderr, "Error! Invalid configuration.\n"); |
| 944 | goto Error; |
| 945 | } |
| 946 | |
Pascal Massimino | 0744e84 | 2011-02-25 12:03:27 -0800 | [diff] [blame] | 947 | // Read the input |
Pascal Massimino | 38369c0 | 2011-05-04 22:59:51 -0700 | [diff] [blame] | 948 | if (verbose) { |
skal | d51f45f | 2013-09-12 09:32:28 +0200 | [diff] [blame] | 949 | StopwatchReset(&stop_watch); |
Pascal Massimino | 38369c0 | 2011-05-04 22:59:51 -0700 | [diff] [blame] | 950 | } |
James Zern | 7eaee9f | 2013-01-11 12:25:36 -0800 | [diff] [blame] | 951 | if (!ReadPicture(in_file, &picture, keep_alpha, |
| 952 | (keep_metadata == 0) ? NULL : &metadata)) { |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 953 | fprintf(stderr, "Error! Cannot read input picture file '%s'\n", in_file); |
Pascal Massimino | 6d978a6 | 2011-03-17 14:49:19 -0700 | [diff] [blame] | 954 | goto Error; |
| 955 | } |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 956 | picture.progress_hook = (show_progress && !quiet) ? ProgressReport : NULL; |
Pascal Massimino | e7d9548 | 2013-04-02 19:14:14 -0700 | [diff] [blame] | 957 | |
| 958 | if (blend_alpha) { |
| 959 | WebPBlendAlpha(&picture, background_color); |
| 960 | } |
| 961 | |
James Zern | 7c732e5 | 2013-02-01 20:04:20 -0800 | [diff] [blame] | 962 | if (keep_alpha == 2) { |
| 963 | WebPCleanupTransparentArea(&picture); |
| 964 | } |
Pascal Massimino | 30971c9 | 2011-12-01 02:24:50 -0800 | [diff] [blame] | 965 | |
Pascal Massimino | 0744e84 | 2011-02-25 12:03:27 -0800 | [diff] [blame] | 966 | if (verbose) { |
Pascal Massimino | 126c035 | 2013-01-25 00:44:16 -0800 | [diff] [blame] | 967 | const double read_time = StopwatchReadAndReset(&stop_watch); |
| 968 | fprintf(stderr, "Time to read input: %.3fs\n", read_time); |
Pascal Massimino | 0744e84 | 2011-02-25 12:03:27 -0800 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | // Open the output |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 972 | if (out_file != NULL) { |
| 973 | const int use_stdout = !strcmp(out_file, "-"); |
| 974 | out = use_stdout ? stdout : fopen(out_file, "wb"); |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 975 | if (out == NULL) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 976 | fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file); |
| 977 | goto Error; |
| 978 | } else { |
| 979 | if (!short_output && !quiet) { |
| 980 | fprintf(stderr, "Saving file '%s'\n", out_file); |
| 981 | } |
| 982 | } |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 983 | if (keep_metadata == 0) { |
| 984 | picture.writer = MyWriter; |
| 985 | picture.custom_ptr = (void*)out; |
| 986 | } else { |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 987 | picture.writer = WebPMemoryWrite; |
| 988 | picture.custom_ptr = (void*)&memory_writer; |
| 989 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 990 | } else { |
| 991 | out = NULL; |
| 992 | if (!quiet && !short_output) { |
| 993 | fprintf(stderr, "No output file specified (no -o flag). Encoding will\n"); |
| 994 | fprintf(stderr, "be performed, but its results discarded.\n\n"); |
| 995 | } |
| 996 | } |
Pascal Massimino | 7d853d7 | 2012-07-24 16:15:36 -0700 | [diff] [blame] | 997 | if (!quiet) { |
| 998 | picture.stats = &stats; |
James Zern | 475d87d | 2012-07-27 19:53:16 -0700 | [diff] [blame] | 999 | picture.user_data = (void*)in_file; |
Pascal Massimino | 7d853d7 | 2012-07-24 16:15:36 -0700 | [diff] [blame] | 1000 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1001 | |
Vikas Arora | e09e9ff | 2014-07-28 16:04:54 -0700 | [diff] [blame] | 1002 | // Crop & resize. |
Pascal Massimino | 38369c0 | 2011-05-04 22:59:51 -0700 | [diff] [blame] | 1003 | if (verbose) { |
skal | d51f45f | 2013-09-12 09:32:28 +0200 | [diff] [blame] | 1004 | StopwatchReset(&stop_watch); |
Pascal Massimino | 38369c0 | 2011-05-04 22:59:51 -0700 | [diff] [blame] | 1005 | } |
Pascal Massimino | 31b68fe | 2012-06-21 00:30:43 -0700 | [diff] [blame] | 1006 | if (crop != 0) { |
| 1007 | // We use self-cropping using a view. |
| 1008 | if (!WebPPictureView(&picture, crop_x, crop_y, crop_w, crop_h, &picture)) { |
| 1009 | fprintf(stderr, "Error! Cannot crop picture\n"); |
| 1010 | goto Error; |
| 1011 | } |
Pascal Massimino | 6d978a6 | 2011-03-17 14:49:19 -0700 | [diff] [blame] | 1012 | } |
Pascal Massimino | 6d0e66c | 2011-05-02 17:19:00 -0700 | [diff] [blame] | 1013 | if ((resize_w | resize_h) > 0) { |
| 1014 | if (!WebPPictureRescale(&picture, resize_w, resize_h)) { |
| 1015 | fprintf(stderr, "Error! Cannot resize picture\n"); |
| 1016 | goto Error; |
| 1017 | } |
| 1018 | } |
Vikas Arora | e09e9ff | 2014-07-28 16:04:54 -0700 | [diff] [blame] | 1019 | if (verbose && (crop != 0 || (resize_w | resize_h) > 0)) { |
| 1020 | const double preproc_time = StopwatchReadAndReset(&stop_watch); |
| 1021 | fprintf(stderr, "Time to crop/resize picture: %.3fs\n", preproc_time); |
| 1022 | } |
| 1023 | |
Pascal Massimino | 6d0e66c | 2011-05-02 17:19:00 -0700 | [diff] [blame] | 1024 | if (picture.extra_info_type > 0) { |
| 1025 | AllocExtraInfo(&picture); |
| 1026 | } |
Pascal Massimino | f86e6ab | 2012-10-18 08:26:40 -0700 | [diff] [blame] | 1027 | if (print_distortion >= 0) { // Save original picture for later comparison |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 1028 | WebPPictureCopy(&picture, &original_picture); |
| 1029 | } |
Vikas Arora | e09e9ff | 2014-07-28 16:04:54 -0700 | [diff] [blame] | 1030 | |
| 1031 | // Compress. |
| 1032 | if (verbose) { |
| 1033 | StopwatchReset(&stop_watch); |
| 1034 | } |
Pascal Massimino | 6d978a6 | 2011-03-17 14:49:19 -0700 | [diff] [blame] | 1035 | if (!WebPEncode(&config, &picture)) { |
| 1036 | fprintf(stderr, "Error! Cannot encode picture as WebP\n"); |
Pascal Massimino | ca7a2fd | 2011-06-02 06:55:03 -0700 | [diff] [blame] | 1037 | fprintf(stderr, "Error code: %d (%s)\n", |
| 1038 | picture.error_code, kErrorMessages[picture.error_code]); |
Pascal Massimino | 6d978a6 | 2011-03-17 14:49:19 -0700 | [diff] [blame] | 1039 | goto Error; |
| 1040 | } |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1041 | if (verbose) { |
Pascal Massimino | 126c035 | 2013-01-25 00:44:16 -0800 | [diff] [blame] | 1042 | const double encode_time = StopwatchReadAndReset(&stop_watch); |
| 1043 | fprintf(stderr, "Time to encode picture: %.3fs\n", encode_time); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1044 | } |
Pascal Massimino | 0744e84 | 2011-02-25 12:03:27 -0800 | [diff] [blame] | 1045 | |
| 1046 | // Write info |
Pascal Massimino | 38369c0 | 2011-05-04 22:59:51 -0700 | [diff] [blame] | 1047 | if (dump_file) { |
Pascal Massimino | dd10817 | 2012-07-18 21:58:53 +0000 | [diff] [blame] | 1048 | if (picture.use_argb) { |
Pascal Massimino | 437999f | 2012-06-04 15:50:05 -0700 | [diff] [blame] | 1049 | fprintf(stderr, "Warning: can't dump file (-d option) in lossless mode."); |
| 1050 | } else if (!DumpPicture(&picture, dump_file)) { |
| 1051 | fprintf(stderr, "Warning, couldn't dump picture %s\n", dump_file); |
| 1052 | } |
Pascal Massimino | 38369c0 | 2011-05-04 22:59:51 -0700 | [diff] [blame] | 1053 | } |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 1054 | |
James Zern | 7049043 | 2013-12-09 20:15:54 -0800 | [diff] [blame] | 1055 | if (keep_metadata != 0) { |
| 1056 | if (out != NULL) { |
| 1057 | if (!WriteWebPWithMetadata(out, &picture, &memory_writer, |
| 1058 | &metadata, keep_metadata, &metadata_written)) { |
| 1059 | fprintf(stderr, "Error writing WebP file with metadata!\n"); |
| 1060 | goto Error; |
| 1061 | } |
| 1062 | } else { // output is disabled, just display the metadata stats. |
| 1063 | const struct { |
| 1064 | const MetadataPayload* const payload; |
| 1065 | int flag; |
| 1066 | } *iter, info[] = { |
| 1067 | { &metadata.exif, METADATA_EXIF }, |
| 1068 | { &metadata.iccp, METADATA_ICC }, |
| 1069 | { &metadata.xmp, METADATA_XMP }, |
| 1070 | { NULL, 0 } |
| 1071 | }; |
| 1072 | uint32_t unused1 = 0; |
| 1073 | uint64_t unused2 = 0; |
| 1074 | |
| 1075 | for (iter = info; iter->payload != NULL; ++iter) { |
| 1076 | if (UpdateFlagsAndSize(iter->payload, !!(keep_metadata & iter->flag), |
| 1077 | 0, &unused1, &unused2)) { |
| 1078 | metadata_written |= iter->flag; |
| 1079 | } |
| 1080 | } |
James Zern | 76ec5fa | 2013-01-14 18:32:44 -0800 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | |
Pascal Massimino | 38369c0 | 2011-05-04 22:59:51 -0700 | [diff] [blame] | 1084 | if (!quiet) { |
skal | fff2a11 | 2013-12-23 12:03:00 +0100 | [diff] [blame] | 1085 | if (!short_output || print_distortion < 0) { |
| 1086 | if (config.lossless) { |
| 1087 | PrintExtraInfoLossless(&picture, short_output, in_file); |
| 1088 | } else { |
| 1089 | PrintExtraInfoLossy(&picture, short_output, config.low_memory, in_file); |
| 1090 | } |
| 1091 | } |
| 1092 | if (!short_output && picture.extra_info_type > 0) { |
| 1093 | PrintMapInfo(&picture); |
| 1094 | } |
| 1095 | if (print_distortion >= 0) { // print distortion |
| 1096 | static const char* distortion_names[] = { "PSNR", "SSIM", "LSIM" }; |
| 1097 | float values[5]; |
| 1098 | // Comparison is performed in YUVA colorspace. |
| 1099 | if (original_picture.use_argb && |
| 1100 | !WebPPictureARGBToYUVA(&original_picture, WEBP_YUV420A)) { |
| 1101 | fprintf(stderr, "Error while converting original picture to YUVA.\n"); |
| 1102 | goto Error; |
| 1103 | } |
| 1104 | if (picture.use_argb && |
| 1105 | !WebPPictureARGBToYUVA(&picture, WEBP_YUV420A)) { |
| 1106 | fprintf(stderr, "Error while converting compressed picture to YUVA.\n"); |
| 1107 | goto Error; |
| 1108 | } |
| 1109 | if (!WebPPictureDistortion(&picture, &original_picture, |
| 1110 | print_distortion, values)) { |
| 1111 | fprintf(stderr, "Error while computing the distortion.\n"); |
| 1112 | goto Error; |
| 1113 | } |
| 1114 | if (!short_output) { |
| 1115 | fprintf(stderr, "%s: Y:%.2f U:%.2f V:%.2f A:%.2f Total:%.2f\n", |
| 1116 | distortion_names[print_distortion], |
| 1117 | values[0], values[1], values[2], values[3], values[4]); |
| 1118 | } else { |
| 1119 | fprintf(stderr, "%7d %.4f\n", picture.stats->coded_size, values[4]); |
| 1120 | } |
Vikas Arora | c4ccab6 | 2012-05-09 11:27:46 +0530 | [diff] [blame] | 1121 | } |
James Zern | 0bc4268 | 2013-03-13 14:41:38 -0700 | [diff] [blame] | 1122 | if (!short_output) { |
| 1123 | PrintMetadataInfo(&metadata, metadata_written); |
| 1124 | } |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 1125 | } |
Pascal Massimino | 4abe04a | 2012-05-09 00:32:20 -0700 | [diff] [blame] | 1126 | return_value = 0; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1127 | |
| 1128 | Error: |
skal | af93bdd | 2014-03-27 23:27:32 +0100 | [diff] [blame] | 1129 | WebPMemoryWriterClear(&memory_writer); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1130 | free(picture.extra_info); |
James Zern | 63aba3a | 2012-12-03 18:20:00 -0800 | [diff] [blame] | 1131 | MetadataFree(&metadata); |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1132 | WebPPictureFree(&picture); |
Pascal Massimino | d61479f | 2012-01-20 07:20:56 -0800 | [diff] [blame] | 1133 | WebPPictureFree(&original_picture); |
skal | e12f874 | 2014-03-12 19:48:00 +0100 | [diff] [blame] | 1134 | if (out != NULL && out != stdout) { |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1135 | fclose(out); |
| 1136 | } |
| 1137 | |
Pascal Massimino | 4abe04a | 2012-05-09 00:32:20 -0700 | [diff] [blame] | 1138 | return return_value; |
Pascal Massimino | f61d14a | 2011-02-18 23:33:46 -0800 | [diff] [blame] | 1139 | } |
| 1140 | |
James Zern | c7e86ab | 2011-08-25 14:22:32 -0700 | [diff] [blame] | 1141 | //------------------------------------------------------------------------------ |