libopenraw
ljpegtest.cpp
1 /*
2  * Copyright (C) 2007, 2009 Hubert Figuiere
3  *
4  * This library is free software: you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation, either version 3 of
7  * the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 
21 #include <string>
22 
23 #include <boost/test/minimal.hpp>
24 #include <boost/crc.hpp> // for boost::crc_basic, boost::crc_optimal
25 
26 #include <libopenraw++/rawdata.h>
27 
28 #include "io/file.h"
29 #include "rawcontainer.h"
30 #include "jfifcontainer.h"
31 #include "ljpegdecompressor.h"
32 #include "ljpegdecompressor_priv.h"
33 
34 using OpenRaw::RawData;
35 using OpenRaw::IO::File;
36 
37 std::string g_testfile;
38 
39 using namespace OpenRaw::Internals;
40 
41 int test_main(int argc, char *argv[])
42 {
43  if (argc == 1) {
44  // no argument, lets run like we are in "check"
45  const char * srcdir = getenv("srcdir");
46 
47  BOOST_ASSERT(srcdir != NULL);
48  g_testfile = std::string(srcdir);
49  g_testfile += "/ljpegtest1.jpg";
50  }
51  else {
52  g_testfile = argv[1];
53  }
54 
55 
56  RawData *decompData;
57  File *s = new File(g_testfile.c_str());
58  RawContainer *container = new JFIFContainer(s, 0);
59 
60  LJpegDecompressor decompressor(s, container);
61 
62  decompData = decompressor.decompress();
63 
64  boost::crc_optimal<8, 0x1021, 0xFFFF, 0, false, false> crc_ccitt2;
65  const uint8_t * data = static_cast<uint8_t *>(decompData->data());
66  size_t data_len = decompData->size();
67  crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 );
68  BOOST_CHECK(crc_ccitt2() == 0x49);
69 
70  delete decompData;
71  delete container;
72  delete s;
73 
74  return 0;
75 }
76