diff --git a/src/utils/alpha.c b/src/utils/alpha.c index 65b30de2..70a1f339 100644 --- a/src/utils/alpha.c +++ b/src/utils/alpha.c @@ -69,13 +69,13 @@ typedef struct { } static size_t GetLongestMatch(const uint8_t* const data, - const uint8_t* const ref, size_t max_len) { + const uint8_t* const ref, size_t max_len) { size_t n; for (n = 0; n < max_len && (data[n] == ref[n]); ++n) { /* do nothing */ } return n; } -static int EncodeZlibTCoder(uint8_t* data, int width, int height, +static int EncodeZlibTCoder(const uint8_t* data, int width, int height, uint8_t** output, size_t* output_size) { int ok = 0; const size_t data_size = width * height; @@ -129,9 +129,9 @@ static int EncodeZlibTCoder(uint8_t* data, int width, int height, + TCoderSymbolCost(coderd, dist); // We're gaining an extra len-best.len coded message over the last // known best. Compute how this would have cost if coded all literal. - // (TODO: we shoud fully re-evaluate at position best.len and not + // (TODO: we should fully re-evaluate at position best.len and not // assume all is going be coded as literals. But it's at least an - // upper-bound (worst-case coding). Deferred evaluation usd below + // upper-bound (worst-case coding). Deferred evaluation used below // partially addresses this. double lit_cost = 0; size_t i; @@ -238,7 +238,7 @@ int EncodeAlpha(const uint8_t* data, int width, int height, int stride, uint8_t* quant_alpha = NULL; uint8_t* out = NULL; size_t compressed_size = 0; - size_t data_size = height * width; + const size_t data_size = height * width; float mse = 0.0; int ok = 0; int h; @@ -267,7 +267,7 @@ int EncodeAlpha(const uint8_t* data, int width, int height, int stride, // Extract the alpha data (WidthXHeight) from raw_data (StrideXHeight). for (h = 0; h < height; ++h) { - memcpy(quant_alpha + h * width, data + h * stride, width * sizeof(*data)); + memcpy(quant_alpha + h * width, data + h * stride, width); } if (quality < 100) { // No Quantization required for 'quality = 100'. @@ -422,8 +422,7 @@ int DecodeAlpha(const uint8_t* data, size_t data_size, // Construct raw_data (HeightXStride) from the alpha data (HeightXWidth). int h; for (h = 0; h < height; ++h) { - memcpy(output + h * stride, decoded_data + h * width, - width * sizeof(*data)); + memcpy(output + h * stride, decoded_data + h * width, width); } } free(decoded_data); diff --git a/src/utils/alpha.h b/src/utils/alpha.h index e0df9cc2..f6416ec8 100644 --- a/src/utils/alpha.h +++ b/src/utils/alpha.h @@ -20,37 +20,37 @@ extern "C" { #endif -// Encodes the given Alpha data 'data' of size 'stride'x'height' via specified +// Encodes the given alpha data 'data' of size 'stride'x'height' via specified // compression method 'method'. The pre-processing (Quantization) is // performed if 'quality' is less than 100. For such cases, the encoding is -// lossy. Valid ranges for 'quality' is [0, 100] and 'method' is [0, 2]: +// lossy. Valid ranges for 'quality' is [0, 100] and 'method' is [0, 1]: // 'method = 0' - No compression; -// 'method = 1' - zlib; -// 'output' corresponds to the buffer containing compressed Alpha data. +// 'method = 1' - Backward reference counts encoded with arithmetic encoder; +// 'output' corresponds to the buffer containing compressed alpha data. // This buffer is allocated by this method and caller should call // free(*output) when done. -// 'output_size' corresponds to size of this compressed Alpha buffer. +// 'output_size' corresponds to size of this compressed alpha buffer. // -// Returns 1 on successfully encoding the Alpha and +// Returns 1 on successfully encoding the alpha and // 0 if either: // data, output or output_size is NULL, or // inappropriate width, height or stride, or // invalid quality or method, or -// Memory allocation for the compressed data fails. +// memory allocation for the compressed data fails. int EncodeAlpha(const uint8_t* data, int width, int height, int stride, int quality, int method, uint8_t** output, size_t* output_size); // Decodes the compressed data 'data' of size 'data_size' into the 'output'. -// The 'output' buffer should be pre-alloacated and must be of the same +// The 'output' buffer should be pre-allocated and must be of the same // dimension 'height'x'stride', as that of the image. // -// Returns 1 on successfully decoding the compressed Alpha and +// Returns 1 on successfully decoding the compressed alpha and // 0 if either: // data or output is NULL, or -// Error in bit-stream header (invalid compression mode or qbits), or -// Error returned by approppriate compression method. +// error in bit-stream header (invalid compression mode or qbits), or +// error returned by appropriate compression method. int DecodeAlpha(const uint8_t* data, size_t data_size, int width, int height, int stride, uint8_t* output); diff --git a/src/utils/quant_levels.c b/src/utils/quant_levels.c index 89257d7b..de13a2f5 100644 --- a/src/utils/quant_levels.c +++ b/src/utils/quant_levels.c @@ -120,7 +120,7 @@ int QuantizeLevels(uint8_t* data, int width, int height, // Remap the alpha plane to quantized values. { // double->int rounding operation can be costly, so we do it - // once for all before remaping. We also perform the data[] -> slot + // once for all before remapping. We also perform the data[] -> slot // mapping, while at it (avoid one indirection in the final loop). uint8_t map[NUM_SYMBOLS]; int s; diff --git a/src/utils/tcoder.c b/src/utils/tcoder.c index 45fcc8a3..b8d8acae 100644 --- a/src/utils/tcoder.c +++ b/src/utils/tcoder.c @@ -75,7 +75,7 @@ // Here, if the symbol 'A' becomes more frequent afterward, we'll just swap it // with 'C' (cf ExchangeSymbol()) without reorganizing the tree. // -// Using this simple maintainance, we obverved a typical 10-20% reduction +// Using this simple maintenance, we observed a typical 10-20% reduction // in the number of calls to VP8PutBit(), leading to 3-5% speed gain. // @@ -369,7 +369,8 @@ void TCoderEncode(TCoder* const c, int s, VP8BitWriter* const bw) { break; } else if (!HasOnlyRightChild(c, parent)) { const int left_proba = node->probaL_; - const int is_right = (pos >> (length - 1 - i)) & 1; // extract bits #i + const int is_right = + (pos >> (length - 1 - i)) & 1; // extract bits #i VP8PutBit(bw, is_right, left_proba); parent = (parent << 1) | is_right; } else { diff --git a/src/utils/tcoder.h b/src/utils/tcoder.h index 158cb2eb..a34b1493 100644 --- a/src/utils/tcoder.h +++ b/src/utils/tcoder.h @@ -65,7 +65,7 @@ TCoder* TCoderNew(int max_symbol); // Re-initialize an existing object, make it ready for a new encoding or // decoding cycle. void TCoderInit(TCoder* const c); -// destroys the tree-ocder object and frees memory. +// destroys the tree-coder object and frees memory. void TCoderDelete(TCoder* const c); // Code next symbol 's'. If the bit-writer 'bw' is NULL, the function will