libopenraw
ljpegtest.cpp
1 /*
2  * Copyright (C) 2007-2016 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 "rawdata.hpp"
27 #include "io/file.hpp"
28 #include "rawcontainer.hpp"
29 #include "jfifcontainer.hpp"
30 #include "ljpegdecompressor.hpp"
31 #include "ljpegdecompressor_priv.hpp"
32 
33 
34 using OpenRaw::IO::File;
35 
36 std::string g_testfile;
37 
38 using namespace OpenRaw::Internals;
39 
40 int test_main(int argc, char *argv[])
41 {
42  if (argc == 1) {
43  // no argument, lets run like we are in "check"
44  const char * srcdir = getenv("srcdir");
45 
46  BOOST_ASSERT(srcdir != NULL);
47  g_testfile = std::string(srcdir);
48  g_testfile += "/ljpegtest1.jpg";
49  }
50  else {
51  g_testfile = argv[1];
52  }
53 
54  File::Ptr s(new File(g_testfile.c_str()));
55  RawContainer *container = new JfifContainer(s, 0);
56 
57  LJpegDecompressor decompressor(s.get(), container);
58 
59  OpenRaw::RawDataPtr decompData = decompressor.decompress();
60 
61  boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false> crc_ccitt2;
62  const uint8_t * data = static_cast<uint8_t *>(decompData->data());
63  size_t data_len = decompData->size();
64  crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 );
65 
66  BOOST_CHECK(crc_ccitt2() == 0x20cc);
67 
68  delete container;
69 
70  return 0;
71 }
72 
virtual RawDataPtr decompress() override