| OLD | NEW |
| 1 // Copyright 2014 Google Inc. All Rights Reserved. | 1 // Copyright 2014 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 // Near-lossless image preprocessing adjusts pixel values to help | 10 // Near-lossless image preprocessing adjusts pixel values to help |
| 11 // compressibility with a guarantee of maximum deviation between original and | 11 // compressibility with a guarantee of maximum deviation between original and |
| 12 // resulting pixel values. | 12 // resulting pixel values. |
| 13 // | 13 // |
| 14 // Author: Jyrki Alakuijala (jyrki@google.com) | 14 // Author: Jyrki Alakuijala (jyrki@google.com) |
| 15 // Converted to C by Aleksander Kramarz (akramarz@google.com) | 15 // Converted to C by Aleksander Kramarz (akramarz@google.com) |
| 16 | 16 |
| 17 #include <assert.h> | 17 #include <assert.h> |
| 18 #include <stdlib.h> | 18 #include <stdlib.h> |
| 19 | 19 |
| 20 #include "../dsp/lossless.h" | 20 #include "../dsp/lossless_common.h" |
| 21 #include "../utils/utils.h" | 21 #include "../utils/utils.h" |
| 22 #include "./vp8enci.h" | 22 #include "./vp8i_enc.h" |
| 23 | 23 |
| 24 #define MIN_DIM_FOR_NEAR_LOSSLESS 64 | 24 #define MIN_DIM_FOR_NEAR_LOSSLESS 64 |
| 25 #define MAX_LIMIT_BITS 5 | 25 #define MAX_LIMIT_BITS 5 |
| 26 | 26 |
| 27 // Quantizes the value up or down to a multiple of 1<<bits (or to 255), | 27 // Quantizes the value up or down to a multiple of 1<<bits (or to 255), |
| 28 // choosing the closer one, resolving ties using bankers' rounding. | 28 // choosing the closer one, resolving ties using bankers' rounding. |
| 29 static int FindClosestDiscretized(int a, int bits) { | 29 static int FindClosestDiscretized(int a, int bits) { |
| 30 const int mask = (1 << bits) - 1; | 30 const int mask = (1 << bits) - 1; |
| 31 const int biased = a + (mask >> 1) + ((a >> bits) & 1); | 31 const int biased = a + (mask >> 1) + ((a >> bits) & 1); |
| 32 assert(bits > 0); | 32 assert(bits > 0); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 WebPSafeFree(copy_buffer); | 113 WebPSafeFree(copy_buffer); |
| 114 return 1; | 114 return 1; |
| 115 } | 115 } |
| 116 | 116 |
| 117 for (i = limit_bits; i != 0; --i) { | 117 for (i = limit_bits; i != 0; --i) { |
| 118 NearLossless(xsize, ysize, argb, i, copy_buffer); | 118 NearLossless(xsize, ysize, argb, i, copy_buffer); |
| 119 } | 119 } |
| 120 WebPSafeFree(copy_buffer); | 120 WebPSafeFree(copy_buffer); |
| 121 return 1; | 121 return 1; |
| 122 } | 122 } |
| OLD | NEW |