[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd/pnm_src cvdimage.cxx
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd/pnm_src cvdimage.cxx |
Date: |
Wed, 24 Feb 2010 17:48:45 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 10/02/24 17:48:45
Modified files:
pnm_src : cvdimage.cxx
Log message:
Fix a compile error for newer compilers.
Fix an aliasing error.
Put in some comments.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/cvdimage.cxx?cvsroot=libcvd&r1=1.3&r2=1.4
Patches:
Index: cvdimage.cxx
===================================================================
RCS file: /cvsroot/libcvd/libcvd/pnm_src/cvdimage.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- cvdimage.cxx 18 Feb 2010 13:30:10 -0000 1.3
+++ cvdimage.cxx 24 Feb 2010 17:48:45 -0000 1.4
@@ -28,6 +28,7 @@
#include "cvd/image_io.h"
#include "cvd/config.h"
#include <iostream>
+#include <sstream>
#include <iomanip>
#include <setjmp.h>
#include <algorithm>
@@ -324,16 +325,13 @@
// create a Huffman tree, encode the data and return the new code
vector<PackType> huff_compress(const Image<byte>& im, const array<int,256>& h)
{
-// cvd_timer t;
-
-// cout << "Hist: " << t.reset() * 1000 << endl;
-
+ //Create a Huffman compression tree
vector<Huff*> terminals;
Huff* table = create_tree(h, terminals);
-// cout << "Tree : " << t.reset() * 1000 << endl;
+ //Create the symbols for the tree and store them
+ //rather inefficiently in an array, one bit per entry.
vector<vector<byte> > symbols(256);
-
for(unsigned int i=0; i < terminals.size(); i++)
{
vector<byte> bits;
@@ -358,9 +356,13 @@
symbols[symbol] = bits;
}
-// cout << "Symbols : " << t.reset() * 1000 << endl;
- //Longest symbol is 48 bits?
+ //Convert the symbols in to a bit packed form.
+ //The symbols are packed in to chunks of PackType (uint16_t)
+ //For each of the 256 symbols, store the symbol 16 different times with
+ //starting offset by 16 different shifts.
+
+ //This allows the symbols to be efficiently stuffed in to the stream
later.
array<array<array<PackType, 20>, PackBits>, 256> fast_symbols;
array<array<int, PackBits>, 256> fast_symbols_num_chunks;
@@ -390,6 +392,7 @@
}
+ //Now pack the symbols into the array
vector<PackType> r2;
r2.reserve(im.size().area()/(2*PackBits));
int bit=0;
@@ -411,14 +414,13 @@
}
-// cout << "Fast Packing : " << t.reset() * 1000 << endl;
-
return r2;
}
// given an encoded data stream and a histogram of the encoded symbols, create
// a Huffman tree, decode the data and store it in the image ret.
+// No particular effort has been paid to efficiency.
template<class P> void huff_decompress(const vector<P>& b, const
array<int,256>& h, Image<byte>& ret)
{
vector<Huff*> terminals;
@@ -581,7 +583,9 @@
size_t pos = tmp.find("pred=");
if (pos!=tmp.npos) {
istringstream sstr(tmp.substr(pos+5));
- sstr >> (int&)pred_mode;
+ int pmode=-1;
+ sstr >> pmode;
+ pred_mode = (cvd_predictors) pmode;
}
//cout << "type: '" << type << "'" << endl;