cosmetics after e1947a9

indent / spelling / line length & a couple missing consts

Change-Id: Id282cb7bc6881d4738a3d9fa912b5b22a007c4d2
This commit is contained in:
James Zern 2011-11-30 17:01:53 -08:00
parent e1947a9299
commit 67228734dc
5 changed files with 23 additions and 23 deletions

View File

@ -75,7 +75,7 @@ static size_t GetLongestMatch(const uint8_t* const data,
return n; 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) { uint8_t** output, size_t* output_size) {
int ok = 0; int ok = 0;
const size_t data_size = width * height; const size_t data_size = width * height;
@ -129,9 +129,9 @@ static int EncodeZlibTCoder(uint8_t* data, int width, int height,
+ TCoderSymbolCost(coderd, dist); + TCoderSymbolCost(coderd, dist);
// We're gaining an extra len-best.len coded message over the last // 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. // 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 // 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. // partially addresses this.
double lit_cost = 0; double lit_cost = 0;
size_t i; 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* quant_alpha = NULL;
uint8_t* out = NULL; uint8_t* out = NULL;
size_t compressed_size = 0; size_t compressed_size = 0;
size_t data_size = height * width; const size_t data_size = height * width;
float mse = 0.0; float mse = 0.0;
int ok = 0; int ok = 0;
int h; 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). // Extract the alpha data (WidthXHeight) from raw_data (StrideXHeight).
for (h = 0; h < height; ++h) { 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'. 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). // Construct raw_data (HeightXStride) from the alpha data (HeightXWidth).
int h; int h;
for (h = 0; h < height; ++h) { for (h = 0; h < height; ++h) {
memcpy(output + h * stride, decoded_data + h * width, memcpy(output + h * stride, decoded_data + h * width, width);
width * sizeof(*data));
} }
} }
free(decoded_data); free(decoded_data);

View File

@ -20,37 +20,37 @@
extern "C" { extern "C" {
#endif #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 // compression method 'method'. The pre-processing (Quantization) is
// performed if 'quality' is less than 100. For such cases, the encoding 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 = 0' - No compression;
// 'method = 1' - zlib; // 'method = 1' - Backward reference counts encoded with arithmetic encoder;
// 'output' corresponds to the buffer containing compressed Alpha data. // 'output' corresponds to the buffer containing compressed alpha data.
// This buffer is allocated by this method and caller should call // This buffer is allocated by this method and caller should call
// free(*output) when done. // 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: // 0 if either:
// data, output or output_size is NULL, or // data, output or output_size is NULL, or
// inappropriate width, height or stride, or // inappropriate width, height or stride, or
// invalid quality or method, 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 EncodeAlpha(const uint8_t* data, int width, int height, int stride,
int quality, int method, int quality, int method,
uint8_t** output, size_t* output_size); uint8_t** output, size_t* output_size);
// Decodes the compressed data 'data' of size 'data_size' into the 'output'. // 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. // 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: // 0 if either:
// data or output is NULL, or // data or output is NULL, or
// Error in bit-stream header (invalid compression mode or qbits), or // error in bit-stream header (invalid compression mode or qbits), or
// Error returned by approppriate compression method. // error returned by appropriate compression method.
int DecodeAlpha(const uint8_t* data, size_t data_size, int DecodeAlpha(const uint8_t* data, size_t data_size,
int width, int height, int stride, uint8_t* output); int width, int height, int stride, uint8_t* output);

View File

@ -120,7 +120,7 @@ int QuantizeLevels(uint8_t* data, int width, int height,
// Remap the alpha plane to quantized values. // Remap the alpha plane to quantized values.
{ {
// double->int rounding operation can be costly, so we do it // 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). // mapping, while at it (avoid one indirection in the final loop).
uint8_t map[NUM_SYMBOLS]; uint8_t map[NUM_SYMBOLS];
int s; int s;

View File

@ -75,7 +75,7 @@
// Here, if the symbol 'A' becomes more frequent afterward, we'll just swap it // Here, if the symbol 'A' becomes more frequent afterward, we'll just swap it
// with 'C' (cf ExchangeSymbol()) without reorganizing the tree. // 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. // 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; break;
} else if (!HasOnlyRightChild(c, parent)) { } else if (!HasOnlyRightChild(c, parent)) {
const int left_proba = node->probaL_; 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); VP8PutBit(bw, is_right, left_proba);
parent = (parent << 1) | is_right; parent = (parent << 1) | is_right;
} else { } else {

View File

@ -65,7 +65,7 @@ TCoder* TCoderNew(int max_symbol);
// Re-initialize an existing object, make it ready for a new encoding or // Re-initialize an existing object, make it ready for a new encoding or
// decoding cycle. // decoding cycle.
void TCoderInit(TCoder* const c); 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); void TCoderDelete(TCoder* const c);
// Code next symbol 's'. If the bit-writer 'bw' is NULL, the function will // Code next symbol 's'. If the bit-writer 'bw' is NULL, the function will