| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 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 | 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 | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // WebP encoder: main entry point | 10 // WebP encoder: main entry point |
| 11 // | 11 // |
| 12 // Author: Skal (pascal.massimino@gmail.com) | 12 // Author: Skal (pascal.massimino@gmail.com) |
| 13 | 13 |
| 14 #include <assert.h> | 14 #include <assert.h> |
| 15 #include <stdlib.h> | 15 #include <stdlib.h> |
| 16 #include <string.h> | 16 #include <string.h> |
| 17 #include <math.h> | 17 #include <math.h> |
| 18 | 18 |
| 19 #include "./cost.h" | 19 #include "./cost_enc.h" |
| 20 #include "./vp8enci.h" | 20 #include "./vp8i_enc.h" |
| 21 #include "./vp8li.h" | 21 #include "./vp8li_enc.h" |
| 22 #include "../utils/utils.h" | 22 #include "../utils/utils.h" |
| 23 | 23 |
| 24 // #define PRINT_MEMORY_INFO | 24 // #define PRINT_MEMORY_INFO |
| 25 | 25 |
| 26 #ifdef PRINT_MEMORY_INFO | 26 #ifdef PRINT_MEMORY_INFO |
| 27 #include <stdio.h> | 27 #include <stdio.h> |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 //------------------------------------------------------------------------------ | 30 //------------------------------------------------------------------------------ |
| 31 | 31 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Mapping from config->method_ to coding tools used. | 70 // Mapping from config->method_ to coding tools used. |
| 71 //-------------------+---+---+---+---+---+---+---+ | 71 //-------------------+---+---+---+---+---+---+---+ |
| 72 // Method | 0 | 1 | 2 | 3 |(4)| 5 | 6 | | 72 // Method | 0 | 1 | 2 | 3 |(4)| 5 | 6 | |
| 73 //-------------------+---+---+---+---+---+---+---+ | 73 //-------------------+---+---+---+---+---+---+---+ |
| 74 // fast probe | x | | | x | | | | | 74 // fast probe | x | | | x | | | | |
| 75 //-------------------+---+---+---+---+---+---+---+ | 75 //-------------------+---+---+---+---+---+---+---+ |
| 76 // dynamic proba | ~ | x | x | x | x | x | x | | 76 // dynamic proba | ~ | x | x | x | x | x | x | |
| 77 //-------------------+---+---+---+---+---+---+---+ | 77 //-------------------+---+---+---+---+---+---+---+ |
| 78 // fast mode analysis| | | | | x | x | x | | 78 // fast mode analysis|[x]|[x]| | | x | x | x | |
| 79 //-------------------+---+---+---+---+---+---+---+ | 79 //-------------------+---+---+---+---+---+---+---+ |
| 80 // basic rd-opt | | | | x | x | x | x | | 80 // basic rd-opt | | | | x | x | x | x | |
| 81 //-------------------+---+---+---+---+---+---+---+ | 81 //-------------------+---+---+---+---+---+---+---+ |
| 82 // disto-refine i4/16| x | x | x | | | | | | 82 // disto-refine i4/16| x | x | x | | | | | |
| 83 //-------------------+---+---+---+---+---+---+---+ | 83 //-------------------+---+---+---+---+---+---+---+ |
| 84 // disto-refine uv | | x | x | | | | | | 84 // disto-refine uv | | x | x | | | | | |
| 85 //-------------------+---+---+---+---+---+---+---+ | 85 //-------------------+---+---+---+---+---+---+---+ |
| 86 // rd-opt i4/16 | | | ~ | x | x | x | x | | 86 // rd-opt i4/16 | | | ~ | x | x | x | x | |
| 87 //-------------------+---+---+---+---+---+---+---+ | 87 //-------------------+---+---+---+---+---+---+---+ |
| 88 // token buffer (opt)| | | | x | x | x | x | | 88 // token buffer (opt)| | | | x | x | x | x | |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 WebPEncodingSetError(pic, VP8_ENC_ERROR_USER_ABORT); | 308 WebPEncodingSetError(pic, VP8_ENC_ERROR_USER_ABORT); |
| 309 return 0; | 309 return 0; |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 return 1; // ok | 312 return 1; // ok |
| 313 } | 313 } |
| 314 //------------------------------------------------------------------------------ | 314 //------------------------------------------------------------------------------ |
| 315 | 315 |
| 316 int WebPEncode(const WebPConfig* config, WebPPicture* pic) { | 316 int WebPEncode(const WebPConfig* config, WebPPicture* pic) { |
| 317 int ok = 0; | 317 int ok = 0; |
| 318 if (pic == NULL) return 0; |
| 318 | 319 |
| 319 if (pic == NULL) | |
| 320 return 0; | |
| 321 WebPEncodingSetError(pic, VP8_ENC_OK); // all ok so far | 320 WebPEncodingSetError(pic, VP8_ENC_OK); // all ok so far |
| 322 if (config == NULL) // bad params | 321 if (config == NULL) { // bad params |
| 323 return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER); | 322 return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER); |
| 324 if (!WebPValidateConfig(config)) | 323 } |
| 324 if (!WebPValidateConfig(config)) { |
| 325 return WebPEncodingSetError(pic, VP8_ENC_ERROR_INVALID_CONFIGURATION); | 325 return WebPEncodingSetError(pic, VP8_ENC_ERROR_INVALID_CONFIGURATION); |
| 326 if (pic->width <= 0 || pic->height <= 0) | 326 } |
| 327 if (pic->width <= 0 || pic->height <= 0) { |
| 327 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); | 328 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); |
| 328 if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) | 329 } |
| 330 if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) { |
| 329 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); | 331 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); |
| 332 } |
| 330 | 333 |
| 331 if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); | 334 if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); |
| 332 | 335 |
| 333 if (!config->lossless) { | 336 if (!config->lossless) { |
| 334 VP8Encoder* enc = NULL; | 337 VP8Encoder* enc = NULL; |
| 335 | 338 |
| 336 if (!config->exact) { | 339 if (!config->exact) { |
| 337 WebPCleanupTransparentArea(pic); | 340 WebPCleanupTransparentArea(pic); |
| 338 } | 341 } |
| 339 | 342 |
| 340 if (pic->use_argb || pic->y == NULL || pic->u == NULL || pic->v == NULL) { | 343 if (pic->use_argb || pic->y == NULL || pic->u == NULL || pic->v == NULL) { |
| 341 // Make sure we have YUVA samples. | 344 // Make sure we have YUVA samples. |
| 342 if (config->preprocessing & 4) { | 345 if (config->use_sharp_yuv || (config->preprocessing & 4)) { |
| 343 if (!WebPPictureSmartARGBToYUVA(pic)) { | 346 if (!WebPPictureSharpARGBToYUVA(pic)) { |
| 344 return 0; | 347 return 0; |
| 345 } | 348 } |
| 346 } else { | 349 } else { |
| 347 float dithering = 0.f; | 350 float dithering = 0.f; |
| 348 if (config->preprocessing & 2) { | 351 if (config->preprocessing & 2) { |
| 349 const float x = config->quality / 100.f; | 352 const float x = config->quality / 100.f; |
| 350 const float x2 = x * x; | 353 const float x2 = x * x; |
| 351 // slowly decreasing from max dithering at low quality (q->0) | 354 // slowly decreasing from max dithering at low quality (q->0) |
| 352 // to 0.5 dithering amplitude at high quality (q->100) | 355 // to 0.5 dithering amplitude at high quality (q->100) |
| 353 dithering = 1.0f + (0.5f - 1.0f) * x2 * x2; | 356 dithering = 1.0f + (0.5f - 1.0f) * x2 * x2; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 389 |
| 387 if (!config->exact) { | 390 if (!config->exact) { |
| 388 WebPCleanupTransparentAreaLossless(pic); | 391 WebPCleanupTransparentAreaLossless(pic); |
| 389 } | 392 } |
| 390 | 393 |
| 391 ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem. | 394 ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem. |
| 392 } | 395 } |
| 393 | 396 |
| 394 return ok; | 397 return ok; |
| 395 } | 398 } |
| OLD | NEW |