1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
* libopenraw - thumbcpp
*
* Copyright (C) 2006, 2009 Hubert Figuiere
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdio.h>
#include <iostream>
#include <libopenraw/libopenraw.h>
#include <libopenraw/debug.h>
#include <libopenraw++/thumbnail.h>
#include <libopenraw++/rawfile.h>
#include <boost/scoped_ptr.hpp>
using OpenRaw::Thumbnail;
using boost::scoped_ptr;
int
main(int argc, char** argv)
{
::or_error err = OR_ERROR_NONE;
if (argc < 2) {
std::cerr << "missing parameter" << std::endl;
return 1;
}
OpenRaw::init();
or_debug_set_level(DEBUG2);
FILE * f;
{
scoped_ptr<OpenRaw::RawFile> raw_file(OpenRaw::RawFile::newRawFile(argv[1]));
if(!raw_file)
{
std::cout << "Unable to open raw file.\n";
return 1;
}
std::vector<uint32_t> list = raw_file->listThumbnailSizes();
for(std::vector<uint32_t>::iterator i = list.begin();
i != list.end(); ++i)
{
std::cout << "found " << *i << " pixels\n";
}
}
{
scoped_ptr<Thumbnail> thumb(Thumbnail::getAndExtractThumbnail(argv[1],
160, err));
if (thumb != NULL) {
size_t s;
std::cerr << "thumb data size =" << thumb->size() << std::endl;
std::cerr << "thumb data type =" << thumb->dataType() << std::endl;
f = fopen("thumb.jpg", "wb");
s = fwrite(thumb->data(), 1, thumb->size(), f);
if(s != thumb->size()) {
std::cerr << "short write of " << s << " bytes\n";
}
fclose(f);
}
else {
std::cerr << "error = " << err << std::endl;
}
}
{
scoped_ptr<Thumbnail> thumb(Thumbnail::getAndExtractThumbnail(argv[1],
640, err));
if (thumb != NULL) {
size_t s;
std::cerr << "thumb data size =" << thumb->size() << std::endl;
std::cerr << "thumb data type =" << thumb->dataType() << std::endl;
f = fopen("thumbl.jpg", "wb");
s = fwrite(thumb->data(), 1, thumb->size(), f);
if(s != thumb->size()) {
std::cerr << "short write of " << s << " bytes\n";
}
fclose(f);
}
else {
std::cerr << "error = " << err << std::endl;
}
}
{
scoped_ptr<Thumbnail> thumb(Thumbnail::getAndExtractThumbnail(argv[1],
2048, err));
if (thumb != NULL) {
size_t s;
std::cerr << "preview data size =" << thumb->size() << std::endl;
std::cerr << "preview data type =" << thumb->dataType() << std::endl;
f = fopen("preview.jpg", "wb");
s = fwrite(thumb->data(), 1, thumb->size(), f);
if(s != thumb->size()) {
std::cerr << "short write of " << s << " bytes\n";
}
fclose(f);
}
else {
std::cerr << "error = " << err << std::endl;
}
}
return 0;
}
|