Skip to content

Commit 26be371

Browse files
committed
Initial commit
0 parents  commit 26be371

15 files changed

+664
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.moc
2+
*.o
3+
Makefile
4+
moc_*.cpp

common-config.pri

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
PROJECT_NAME = qtraw
2+
PROJECT_VERSION = 1.0
3+
4+
TOP_SRC_DIR = $$PWD
5+
TOP_BUILD_DIR = $${TOP_SRC_DIR}/$(BUILD_DIR)
6+
7+
INSTALL_PREFIX = /usr
8+
9+
isEmpty(PREFIX) {
10+
message("====")
11+
message("==== NOTE: To override the installation path run: `qmake PREFIX=/custom/path'")
12+
message("==== (current installation path is `$${INSTALL_PREFIX}')")
13+
} else {
14+
INSTALL_PREFIX = $${PREFIX}
15+
message("====")
16+
message("==== install prefix set to `$${INSTALL_PREFIX}'")
17+
}
18+
19+
20+
INSTALL_LIBDIR = $${INSTALL_PREFIX}/lib
21+
22+
# default library directory can be overriden by defining LIBDIR when
23+
# running qmake
24+
isEmpty(LIBDIR) {
25+
message("====")
26+
message("==== NOTE: To override the library installation path run: `qmake LIBDIR=/custom/path'")
27+
message("==== (current installation path is `$${INSTALL_LIBDIR}')")
28+
} else {
29+
INSTALL_LIBDIR = $${LIBDIR}
30+
message("====")
31+
message("==== library install path set to `$${INSTALL_LIBDIR}'")
32+
}

qtraw.pro

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include(common-config.pri)
2+
3+
TEMPLATE = subdirs
4+
SUBDIRS = \
5+
src \
6+
tests
7+
8+
DISTNAME = $${PROJECT_NAME}-$${PROJECT_VERSION}
9+
dist.commands = "git archive --format=tar --prefix=$${DISTNAME}/ HEAD | bzip2 -9 > $${DISTNAME}.tar.bz2"
10+
QMAKE_EXTRA_TARGETS += dist

src/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
imageformats/

src/datastream.cpp

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (C) 2012 Alberto Mardegan <info@mardy.it>
3+
*
4+
* This file is part of QtRaw.
5+
*
6+
* QtRaw is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* QtRaw is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with QtRaw. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "datastream.h"
21+
22+
#include <QIODevice>
23+
#include <QTextStream>
24+
25+
Datastream::Datastream(QIODevice *device):
26+
m_device(device)
27+
{
28+
}
29+
30+
Datastream::~Datastream()
31+
{
32+
}
33+
34+
int Datastream::valid()
35+
{
36+
return m_device->isReadable();
37+
}
38+
39+
int Datastream::read(void *ptr, size_t size, size_t nmemb)
40+
{
41+
return int(m_device->read((char *)ptr, size * nmemb));
42+
}
43+
44+
int Datastream::seek(INT64 offset, int whence)
45+
{
46+
qint64 pos;
47+
switch (whence) {
48+
case SEEK_SET:
49+
pos = offset;
50+
break;
51+
case SEEK_CUR:
52+
pos = m_device->pos() + offset;
53+
break;
54+
case SEEK_END:
55+
pos = m_device->size();
56+
break;
57+
default:
58+
return -1;
59+
}
60+
61+
if (pos < 0) pos = 0;
62+
return m_device->seek(pos) ? 0 : -1;
63+
}
64+
65+
INT64 Datastream::tell()
66+
{
67+
return m_device->pos();
68+
}
69+
70+
int Datastream::get_char()
71+
{
72+
char c;
73+
return m_device->getChar(&c) ? c : -1;
74+
}
75+
76+
char *Datastream::gets(char *s, int n)
77+
{
78+
return m_device->readLine(s, n) >= 0 ? s : NULL;
79+
}
80+
81+
int Datastream::scanf_one(const char *fmt, void *val)
82+
{
83+
QTextStream stream(m_device);
84+
/* This is only used for %d or %f */
85+
if (qstrcmp(fmt, "%d") == 0) {
86+
int d;
87+
stream >> d;
88+
*(static_cast<int*>(val)) = d;
89+
} else if (qstrcmp(fmt, "%f") == 0) {
90+
float f;
91+
stream >> f;
92+
*(static_cast<float*>(val)) = f;
93+
} else {
94+
return 0;
95+
}
96+
return (stream.status() == QTextStream::Ok) ? 1 : EOF;
97+
}
98+
99+
int Datastream::eof()
100+
{
101+
return m_device->atEnd();
102+
}
103+
104+
void *Datastream::make_jas_stream()
105+
{
106+
return NULL;
107+
}

src/datastream.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2012 Alberto Mardegan <info@mardy.it>
3+
*
4+
* This file is part of QtRaw.
5+
*
6+
* QtRaw is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* QtRaw is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with QtRaw. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef DATASTREAM_H
21+
#define DATASTREAM_H
22+
23+
#include <QImageIOHandler>
24+
25+
#include <libraw_datastream.h>
26+
27+
class QIODevice;
28+
29+
class Datastream: public LibRaw_abstract_datastream
30+
{
31+
public:
32+
Datastream(QIODevice *device);
33+
~Datastream();
34+
35+
// reimplemented virtual methods:
36+
virtual int valid();
37+
virtual int read(void *ptr, size_t size, size_t nmemb);
38+
virtual int seek(INT64 offset, int whence);
39+
virtual INT64 tell();
40+
virtual int get_char();
41+
virtual char *gets(char *s, int n);
42+
virtual int scanf_one(const char *fmt, void *val);
43+
virtual int eof();
44+
virtual void *make_jas_stream();
45+
46+
private:
47+
QIODevice *m_device;
48+
};
49+
50+
#endif // DATASTREAM_H

src/main.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2012 Alberto Mardegan <info@mardy.it>
3+
*
4+
* This file is part of QtRaw.
5+
*
6+
* QtRaw is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* QtRaw is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with QtRaw. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <QByteArray>
21+
#include <QImageIOHandler>
22+
#include <QIODevice>
23+
#include <QStringList>
24+
25+
#include "raw-io-handler.h"
26+
27+
class RawPlugin: public QImageIOPlugin
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
QStringList keys() const;
33+
Capabilities capabilities(QIODevice *device,
34+
const QByteArray &format) const;
35+
QImageIOHandler *create(QIODevice *device,
36+
const QByteArray &format = QByteArray()) const;
37+
};
38+
39+
QStringList RawPlugin::keys() const
40+
{
41+
return QStringList() <<
42+
QLatin1String("crw") << QLatin1String("cr2") <<
43+
QLatin1String("arw") <<
44+
QLatin1String("nef") <<
45+
QLatin1String("raf") <<
46+
QLatin1String("dng");
47+
}
48+
49+
QImageIOPlugin::Capabilities
50+
RawPlugin::capabilities(QIODevice *device, const QByteArray &format) const
51+
{
52+
if (keys().contains(format) ||
53+
format == "tif" ||
54+
format == "tiff")
55+
return Capabilities(CanRead);
56+
if (!format.isEmpty())
57+
return 0;
58+
59+
Capabilities cap;
60+
if (device->isReadable())
61+
cap |= CanRead;
62+
return Capabilities(CanRead);
63+
}
64+
65+
QImageIOHandler *RawPlugin::create(QIODevice *device,
66+
const QByteArray &format) const
67+
{
68+
RawIOHandler *handler = new RawIOHandler();
69+
handler->setDevice(device);
70+
handler->setFormat(format);
71+
return handler;
72+
}
73+
74+
Q_EXPORT_PLUGIN2(qtraw, RawPlugin)
75+
76+
#include "main.moc"

0 commit comments

Comments
 (0)