~ubuntu-branches/ubuntu/vivid/rawstudio/vivid

« back to all changes in this revision

Viewing changes to plugins/load-rawspeed/rawspeed/DngDecoderSlices.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2011-07-28 17:36:32 UTC
  • mfrom: (2.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110728173632-5czluz9ye3c83zc5
Tags: 2.0-1
* [3750b2cf] Merge commit 'upstream/2.0'
* [63637468] Removing Patch, not necessary anymore.
* [2fb580dc] Add new build-dependencies.
* [c57d953b] Run dh_autoreconf due to patches in configure.in
* [13febe39] Add patch to remove the libssl requirement.
* [5ae773fe] Replace libjpeg62-dev by libjpeg8-dev :)
* [1969d755] Don't build static libraries.
* [7cfe0a2e] Add a patch to fix the plugin directory path.
  As plugins are shared libraries, they need to go into /usr/lib,
  not into /usr/share.
  Thanks to Andrew McMillan
* [c1d0d9dd] Don't install .la files for all plugins and libraries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "StdAfx.h"
 
2
#include "DngDecoderSlices.h"
 
3
/*
 
4
    RawSpeed - RAW file decoder.
 
5
 
 
6
    Copyright (C) 2009 Klaus Post
 
7
 
 
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.
 
12
 
 
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.
 
17
 
 
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
 
21
 
 
22
    http://www.klauspost.com
 
23
*/
 
24
 
 
25
namespace RawSpeed {
 
26
 
 
27
void *DecodeThread(void *_this) {
 
28
  DngDecoderThread* me = (DngDecoderThread*)_this;
 
29
  DngDecoderSlices* parent = me->parent;
 
30
  try {
 
31
    parent->decodeSlice(me);
 
32
  } catch (...) {
 
33
    parent->setError("DNGDEcodeThread: Caught exception.");
 
34
  }
 
35
  pthread_exit(NULL);
 
36
  return NULL;
 
37
}
 
38
 
 
39
 
 
40
DngDecoderSlices::DngDecoderSlices(FileMap* file, RawImage img) :
 
41
    mFile(file), mRaw(img) {
 
42
  mFixLjpeg = false;
 
43
}
 
44
 
 
45
DngDecoderSlices::~DngDecoderSlices(void) {
 
46
}
 
47
 
 
48
void DngDecoderSlices::addSlice(DngSliceElement slice) {
 
49
  slices.push(slice);
 
50
}
 
51
 
 
52
void DngDecoderSlices::startDecoding() {
 
53
  // Create threads
 
54
 
 
55
  nThreads = getThreadCount();
 
56
  int slicesPerThread = ((int)slices.size() + nThreads - 1) / nThreads;
 
57
//  decodedSlices = 0;
 
58
  pthread_attr_t attr;
 
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);
 
63
 
 
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());
 
69
        slices.pop();
 
70
      }
 
71
    }
 
72
    t->parent = this;
 
73
    pthread_create(&t->threadid, &attr, DecodeThread, t);
 
74
    threads.push_back(t);
 
75
  }
 
76
  pthread_attr_destroy(&attr);
 
77
 
 
78
  void *status;
 
79
  for (uint32 i = 0; i < nThreads; i++) {
 
80
    pthread_join(threads[i]->threadid, &status);
 
81
    delete(threads[i]);
 
82
  }
 
83
  pthread_mutex_destroy(&errMutex);
 
84
 
 
85
}
 
86
 
 
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;
 
93
    t->slices.pop();
 
94
    try {
 
95
      l.startDecoder(e.byteOffset, e.byteCount, e.offX, e.offY);
 
96
    } catch (RawDecoderException err) {
 
97
      setError(err.what());
 
98
    } catch (IOException err) {
 
99
      setError("DngDecoderSlices::decodeSlice: IO error occurred.");
 
100
    }
 
101
  }
 
102
}
 
103
 
 
104
int DngDecoderSlices::size() {
 
105
  return (int)slices.size();
 
106
}
 
107
 
 
108
void DngDecoderSlices::setError( const char* err )
 
109
{
 
110
  pthread_mutex_lock(&errMutex);
 
111
  errors.push_back(_strdup(err));
 
112
  pthread_mutex_unlock(&errMutex);
 
113
}
 
114
 
 
115
} // namespace RawSpeed