2
#include "DngDecoderSlices.h"
4
RawSpeed - RAW file decoder.
6
Copyright (C) 2009 Klaus Post
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Lesser General Public
10
License as published by the Free Software Foundation; either
11
version 2 of the License, or (at your option) any later version.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
http://www.klauspost.com
27
void *DecodeThread(void *_this) {
28
DngDecoderThread* me = (DngDecoderThread*)_this;
29
DngDecoderSlices* parent = me->parent;
31
parent->decodeSlice(me);
33
parent->setError("DNGDEcodeThread: Caught exception.");
40
DngDecoderSlices::DngDecoderSlices(FileMap* file, RawImage img) :
41
mFile(file), mRaw(img) {
45
DngDecoderSlices::~DngDecoderSlices(void) {
48
void DngDecoderSlices::addSlice(DngSliceElement slice) {
52
void DngDecoderSlices::startDecoding() {
55
nThreads = getThreadCount();
56
int slicesPerThread = ((int)slices.size() + nThreads - 1) / nThreads;
59
/* Initialize and set thread detached attribute */
60
pthread_attr_init(&attr);
61
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
62
pthread_mutex_init(&errMutex, NULL);
64
for (uint32 i = 0; i < nThreads; i++) {
65
DngDecoderThread* t = new DngDecoderThread();
66
for (int j = 0; j < slicesPerThread ; j++) {
67
if (!slices.empty()) {
68
t->slices.push(slices.front());
73
pthread_create(&t->threadid, &attr, DecodeThread, t);
76
pthread_attr_destroy(&attr);
79
for (uint32 i = 0; i < nThreads; i++) {
80
pthread_join(threads[i]->threadid, &status);
83
pthread_mutex_destroy(&errMutex);
87
void DngDecoderSlices::decodeSlice(DngDecoderThread* t) {
88
while (!t->slices.empty()) {
89
LJpegPlain l(mFile, mRaw);
90
l.mDNGCompatible = mFixLjpeg;
91
DngSliceElement e = t->slices.front();
92
l.mUseBigtable = e.mUseBigtable;
95
l.startDecoder(e.byteOffset, e.byteCount, e.offX, e.offY);
96
} catch (RawDecoderException err) {
98
} catch (IOException err) {
99
setError("DngDecoderSlices::decodeSlice: IO error occurred.");
104
int DngDecoderSlices::size() {
105
return (int)slices.size();
108
void DngDecoderSlices::setError( const char* err )
110
pthread_mutex_lock(&errMutex);
111
errors.push_back(_strdup(err));
112
pthread_mutex_unlock(&errMutex);
115
} // namespace RawSpeed