2 * This file is part of RawTherapee.
4 * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
6 * RawTherapee 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.
11 * RawTherapee 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.
16 * You should have received a copy of the GNU General Public License
17 * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
19 #include <thumbimageupdater.h>
22 ThumbImageUpdater thumbImageUpdater
;
24 ThumbImageUpdater::ThumbImageUpdater ()
25 : tostop(false), stopped(true), qMutex(NULL
), startMutex(NULL
) {
29 void ThumbImageUpdater::add (Thumbnail
* t
, const rtengine::procparams::ProcParams
& params
, int height
, bool* priority
, ThumbImageUpdateListener
* l
) {
32 qMutex
= new Glib::Mutex ();
34 startMutex
= new Glib::Mutex ();
37 // look up if an older version is in the queue
38 std::list
<Job
>::iterator i
;
39 for (i
=jqueue
.begin(); i
!=jqueue
.end(); i
++)
40 if (i
->thumbnail
==t
&& i
->listener
==l
) {
43 i
->priority
= priority
;
46 // not found, create and append new job
47 if (i
==jqueue
.end ()) {
53 j
.priority
= priority
;
59 void ThumbImageUpdater::process () {
62 #undef THREAD_PRIORITY_NORMAL
64 thread
= Glib::Thread::create(sigc::mem_fun(*this, &ThumbImageUpdater::process_
), (unsigned long int)0, true, true, Glib::THREAD_PRIORITY_NORMAL
);
68 void ThumbImageUpdater::process_ () {
73 #define threadNum 4 // IF LCMS GETS THREAD SAFETY WE CAN ENABLE MORE THREADS
74 Glib::Thread
**threadPool
= new Glib::Thread
* [threadNum
];
76 while (!tostop
&& !jqueue
.empty ()) {
80 for (; threads
<threadNum
&& !jqueue
.empty (); threads
++) {
81 // find first entry having update priority, if any
82 std::list
<Job
>::iterator i
;
83 for (i
=jqueue
.begin (); i
!=jqueue
.end(); i
++)
91 threadPool
[threads
] = Glib::Thread::create(sigc::bind(sigc::mem_fun(*this, &ThumbImageUpdater::processJob
), current
), 0, true, true, Glib::THREAD_PRIORITY_NORMAL
);
93 threadPool
[threads
] = NULL
;
97 for (int j
=0; j
<threads
; j
++)
99 threadPool
[j
]->join ();
104 void ThumbImageUpdater::processJob (Job current
) {
106 if (current
.listener
) {
108 rtengine::IImage8
* img
= current
.thumbnail
->processThumbImage (current
.pparams
, current
.height
, scale
);
110 current
.listener
->updateImage (img
, scale
, current
.pparams
.crop
);
115 void ThumbImageUpdater::stop () {
123 Glib::Thread::self()->yield();
129 void ThumbImageUpdater::removeJobs () {
135 while (!jqueue
.empty())
140 void ThumbImageUpdater::removeJobs (ThumbImageUpdateListener
* listener
) {
149 std::list
<Job
>::iterator i
;
150 for (i
=jqueue
.begin(); i
!=jqueue
.end(); i
++)
151 if (i
->listener
== listener
) {
160 void ThumbImageUpdater::terminate () {