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 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); | 321 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); |
322 if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) | 322 if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) |
323 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); | 323 return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); |
324 | 324 |
325 if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); | 325 if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); |
326 | 326 |
327 if (!config->lossless) { | 327 if (!config->lossless) { |
328 VP8Encoder* enc = NULL; | 328 VP8Encoder* enc = NULL; |
329 if (pic->y == NULL || pic->u == NULL || pic->v == NULL) { | 329 if (pic->y == NULL || pic->u == NULL || pic->v == NULL) { |
330 // Make sure we have YUVA samples. | 330 // Make sure we have YUVA samples. |
331 float dithering = 0.f; | 331 if (config->preprocessing & 4) { |
332 if (config->preprocessing & 2) { | 332 #if WEBP_ENCODER_ABI_VERSION > 0x0204 |
333 const float x = config->quality / 100.f; | 333 if (!WebPPictureSmartARGBToYUVA(pic)) { |
334 const float x2 = x * x; | 334 return 0; |
335 // slowly decreasing from max dithering at low quality (q->0) | 335 } |
336 // to 0.5 dithering amplitude at high quality (q->100) | 336 #endif |
337 dithering = 1.0f + (0.5f - 1.0f) * x2 * x2; | 337 } else { |
338 } | 338 float dithering = 0.f; |
339 if (!WebPPictureARGBToYUVADithered(pic, WEBP_YUV420, dithering)) { | 339 if (config->preprocessing & 2) { |
340 return 0; | 340 const float x = config->quality / 100.f; |
| 341 const float x2 = x * x; |
| 342 // slowly decreasing from max dithering at low quality (q->0) |
| 343 // to 0.5 dithering amplitude at high quality (q->100) |
| 344 dithering = 1.0f + (0.5f - 1.0f) * x2 * x2; |
| 345 } |
| 346 if (!WebPPictureARGBToYUVADithered(pic, WEBP_YUV420, dithering)) { |
| 347 return 0; |
| 348 } |
341 } | 349 } |
342 } | 350 } |
343 | 351 |
344 enc = InitVP8Encoder(config, pic); | 352 enc = InitVP8Encoder(config, pic); |
345 if (enc == NULL) return 0; // pic->error is already set. | 353 if (enc == NULL) return 0; // pic->error is already set. |
346 // Note: each of the tasks below account for 20% in the progress report. | 354 // Note: each of the tasks below account for 20% in the progress report. |
347 ok = VP8EncAnalyze(enc); | 355 ok = VP8EncAnalyze(enc); |
348 | 356 |
349 // Analysis is done, proceed to actual coding. | 357 // Analysis is done, proceed to actual coding. |
350 ok = ok && VP8EncStartAlpha(enc); // possibly done in parallel | 358 ok = ok && VP8EncStartAlpha(enc); // possibly done in parallel |
(...skipping 14 matching lines...) Expand all Loading... |
365 // Make sure we have ARGB samples. | 373 // Make sure we have ARGB samples. |
366 if (pic->argb == NULL && !WebPPictureYUVAToARGB(pic)) { | 374 if (pic->argb == NULL && !WebPPictureYUVAToARGB(pic)) { |
367 return 0; | 375 return 0; |
368 } | 376 } |
369 | 377 |
370 ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem. | 378 ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem. |
371 } | 379 } |
372 | 380 |
373 return ok; | 381 return ok; |
374 } | 382 } |
OLD | NEW |