added a special thread for making thumbnails (thumb.h thumb.cpp)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@700 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -17,10 +17,10 @@ app.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
|
||||
app.o: ../notify/notifythread.h ../core/basethread.h synchro.h
|
||||
app.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
|
||||
app.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h users.h
|
||||
app.o: groups.h group.h loadavg.h sessionmanager.h sessioncontainer.h
|
||||
app.o: basethread.h ../functions/functions.h ../functions/functionbase.h
|
||||
app.o: ../core/request.h ../core/system.h ../core/synchro.h
|
||||
app.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
app.o: groups.h group.h loadavg.h thumb.h basethread.h sessionmanager.h
|
||||
app.o: sessioncontainer.h ../functions/functions.h
|
||||
app.o: ../functions/functionbase.h ../core/request.h ../core/system.h
|
||||
app.o: ../core/synchro.h ../functions/functionparser.h ../functions/adduser.h
|
||||
app.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
|
||||
app.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
|
||||
app.o: ../functions/createthread.h ../functions/default.h
|
||||
@@ -59,7 +59,7 @@ config.o: ../templates/htmltextstream.h ../notify/notifythread.h
|
||||
config.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
|
||||
config.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
|
||||
config.o: mounts.h mount.h mountparser.h users.h groups.h group.h loadavg.h
|
||||
config.o: sessionmanager.h sessioncontainer.h basethread.h
|
||||
config.o: thumb.h basethread.h sessionmanager.h sessioncontainer.h
|
||||
config.o: ../functions/functions.h ../functions/functionbase.h
|
||||
config.o: ../core/request.h ../core/system.h ../core/synchro.h
|
||||
config.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
@@ -157,12 +157,13 @@ mounts.o: ../templates/htmltextstream.h ../notify/notifythread.h
|
||||
mounts.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
|
||||
mounts.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
|
||||
mounts.o: mountparser.h plugin.h pluginmsg.h system.h users.h groups.h
|
||||
mounts.o: group.h loadavg.h sessionmanager.h sessioncontainer.h basethread.h
|
||||
mounts.o: ../functions/functions.h ../functions/functionbase.h
|
||||
mounts.o: ../core/request.h ../core/system.h ../core/synchro.h
|
||||
mounts.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
mounts.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
|
||||
mounts.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
|
||||
mounts.o: group.h loadavg.h thumb.h basethread.h sessionmanager.h
|
||||
mounts.o: sessioncontainer.h ../functions/functions.h
|
||||
mounts.o: ../functions/functionbase.h ../core/request.h ../core/system.h
|
||||
mounts.o: ../core/synchro.h ../functions/functionparser.h
|
||||
mounts.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
|
||||
mounts.o: ../functions/privchanger.h ../functions/chown.h
|
||||
mounts.o: ../functions/ckeditor.h ../functions/cp.h
|
||||
mounts.o: ../functions/createthread.h ../functions/default.h
|
||||
mounts.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
|
||||
mounts.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
|
||||
@@ -194,7 +195,7 @@ plugin.o: ../templates/htmltextstream.h ../notify/notifythread.h
|
||||
plugin.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
|
||||
plugin.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
|
||||
plugin.o: mounts.h mount.h mountparser.h users.h groups.h group.h loadavg.h
|
||||
plugin.o: sessionmanager.h sessioncontainer.h basethread.h
|
||||
plugin.o: thumb.h basethread.h sessionmanager.h sessioncontainer.h
|
||||
plugin.o: ../functions/functions.h ../functions/functionbase.h
|
||||
plugin.o: ../core/request.h ../core/system.h ../core/synchro.h
|
||||
plugin.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
@@ -231,8 +232,8 @@ plugindata.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
|
||||
plugindata.o: ../notify/notifythread.h ../core/basethread.h synchro.h
|
||||
plugindata.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
|
||||
plugindata.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h
|
||||
plugindata.o: users.h groups.h group.h loadavg.h sessionmanager.h
|
||||
plugindata.o: sessioncontainer.h basethread.h ../functions/functions.h
|
||||
plugindata.o: users.h groups.h group.h loadavg.h thumb.h basethread.h
|
||||
plugindata.o: sessionmanager.h sessioncontainer.h ../functions/functions.h
|
||||
plugindata.o: ../functions/functionbase.h ../core/request.h ../core/system.h
|
||||
plugindata.o: ../core/synchro.h ../functions/functionparser.h
|
||||
plugindata.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
|
||||
@@ -277,7 +278,7 @@ request.o: ../templates/htmltextstream.h ../notify/notifythread.h
|
||||
request.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
|
||||
request.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
|
||||
request.o: mounts.h mount.h mountparser.h users.h groups.h group.h loadavg.h
|
||||
request.o: sessionmanager.h sessioncontainer.h basethread.h
|
||||
request.o: thumb.h basethread.h sessionmanager.h sessioncontainer.h
|
||||
request.o: ../functions/functions.h ../functions/functionbase.h
|
||||
request.o: ../core/request.h ../core/system.h ../core/synchro.h
|
||||
request.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
@@ -324,7 +325,7 @@ sessionmanager.o: ../templates/htmltextstream.h ../notify/notifythread.h
|
||||
sessionmanager.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
|
||||
sessionmanager.o: ../core/config.h ../core/users.h ugcontainer.h mounts.h
|
||||
sessionmanager.o: mount.h mountparser.h users.h groups.h group.h loadavg.h
|
||||
sessionmanager.o: sessionparser.h plugin.h pluginmsg.h
|
||||
sessionmanager.o: thumb.h sessionparser.h plugin.h pluginmsg.h
|
||||
sessionmanager.o: ../functions/functions.h ../functions/functionbase.h
|
||||
sessionmanager.o: ../core/request.h ../core/system.h ../core/synchro.h
|
||||
sessionmanager.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
@@ -370,10 +371,16 @@ system.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
|
||||
system.o: ../notify/notifythread.h ../core/basethread.h synchro.h
|
||||
system.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
|
||||
system.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h
|
||||
system.o: users.h groups.h group.h loadavg.h ../templates/templates.h
|
||||
system.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
|
||||
system.o: ../core/httpsimpleparser.h ../core/log.h
|
||||
system.o: ../templates/indexpatterns.h ../core/request.h ../core/system.h
|
||||
system.o: ../core/sessionmanager.h
|
||||
system.o: users.h groups.h group.h loadavg.h thumb.h basethread.h
|
||||
system.o: ../templates/templates.h ../templates/patterncacher.h
|
||||
system.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
system.o: ../core/log.h ../templates/indexpatterns.h ../core/request.h
|
||||
system.o: ../core/system.h ../core/sessionmanager.h
|
||||
textstream.o: textstream.h misc.h item.h
|
||||
thumb.o: thumb.h basethread.h textstream.h ../db/db.h ../db/dbbase.h
|
||||
thumb.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
|
||||
thumb.o: item.h ../core/error.h log.h ../db/dbitemquery.h ../core/item.h
|
||||
thumb.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
|
||||
thumb.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
thumb.o: ../../ezc/src/utf8.h
|
||||
users.o: users.h
|
||||
|
@@ -1 +1 @@
|
||||
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o confparser.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o item.o lastcontainer.o loadavg.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o synchro.o system.o textstream.o users.o
|
||||
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o confparser.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o item.o lastcontainer.o loadavg.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o synchro.o system.o textstream.o thumb.o users.o
|
||||
|
13
core/app.cpp
13
core/app.cpp
@@ -7,7 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "wand/MagickWand.h"
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
@@ -147,7 +146,6 @@ bool App::Init()
|
||||
session_manager.LoadSessions();
|
||||
|
||||
CreateStaticTree();
|
||||
MagickWandGenesis();
|
||||
|
||||
plugin.Call(WINIX_PLUGIN_INIT);
|
||||
|
||||
@@ -155,12 +153,6 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
void App::Uninit()
|
||||
{
|
||||
MagickWandTerminus();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void App::Close()
|
||||
{
|
||||
@@ -984,6 +976,7 @@ void App::WaitForThreads()
|
||||
|
||||
system.notify.WaitForThread();
|
||||
session_manager.WaitForGC();
|
||||
system.thumb.WaitForThread();
|
||||
}
|
||||
|
||||
|
||||
@@ -1019,6 +1012,7 @@ sigset_t set;
|
||||
Ezc::WideToUTF8(app->config.base_url, app->url_to_fetch_on_exit);
|
||||
app->system.notify.PrepareToStopThread();
|
||||
app->session_manager.PrepareToStopGC();
|
||||
app->system.thumb.WakeUpThread();
|
||||
app->Unlock();
|
||||
|
||||
// this thread will hang on this method
|
||||
@@ -1051,6 +1045,9 @@ sigset_t set;
|
||||
|
||||
// gc for sessions
|
||||
session_manager.StartGC();
|
||||
|
||||
// thumbnails
|
||||
system.thumb.StartThread();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -49,7 +49,6 @@ public:
|
||||
bool InitFCGI();
|
||||
bool DropPrivileges();
|
||||
bool Init();
|
||||
void Uninit();
|
||||
void Start();
|
||||
void Close();
|
||||
void LogUserGroups();
|
||||
|
@@ -17,6 +17,7 @@ BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
||||
synchro = 0;
|
||||
thread_id = 0;
|
||||
work_mode = 0;
|
||||
wake_up_was_called = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +92,8 @@ bool BaseThread::BaseSignalReceived()
|
||||
{
|
||||
bool make_do = false;
|
||||
|
||||
wake_up_was_called = false;
|
||||
|
||||
try
|
||||
{
|
||||
make_do = SignalReceived(); // your short-time virtual method (objects are locked)
|
||||
@@ -119,13 +122,18 @@ void BaseThread::BaseDo()
|
||||
// use it with Lock and Unlock
|
||||
bool BaseThread::WaitForSignal()
|
||||
{
|
||||
if( synchro->was_stop_signal || wake_up_was_called )
|
||||
return true;
|
||||
|
||||
return pthread_cond_wait(&thread_signal, &synchro->mutex) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// you should use this method with: synchro->Lock() and Unlock()
|
||||
void BaseThread::WakeUpThread()
|
||||
{
|
||||
// you should use it with: synchro->Lock() and Unlock()
|
||||
wake_up_was_called = true;
|
||||
pthread_cond_signal(&thread_signal);
|
||||
}
|
||||
|
||||
@@ -168,14 +176,14 @@ bool make_do;
|
||||
{
|
||||
make_do = false;
|
||||
|
||||
if( !synchro->was_stop_signal && WaitForSignal() ) // automatically unlock, wait and lock again when signal comes
|
||||
if( WaitForSignal() ) // automatically unlock, wait and lock again when signal comes
|
||||
if( !synchro->was_stop_signal )
|
||||
make_do = BaseSignalReceived(); // your short-time virtual method will be called (objects locked)
|
||||
make_do = BaseSignalReceived(); // your short-time virtual method will be called (objects locked)
|
||||
|
||||
Unlock(); // unlocking from WaitForSignal()
|
||||
Unlock(); // unlocking from WaitForSignal()
|
||||
|
||||
if( make_do )
|
||||
BaseDo(); // your long-time virtual method will be called (objects *not* locked)
|
||||
BaseDo(); // your long-time virtual method will be called (objects *not* locked)
|
||||
}
|
||||
}
|
||||
while( !IsExitSignal() );
|
||||
|
@@ -63,6 +63,10 @@ public:
|
||||
// it's called only if Init() returned true
|
||||
virtual void Uninit() {}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// signal came (work mode = 0 - default)
|
||||
// signal comes when an other thread calls WakeUpThread() method
|
||||
// check specific job and return true to call Do() next
|
||||
@@ -81,12 +85,15 @@ public:
|
||||
virtual void Work() {}
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
Synchro * synchro;
|
||||
pthread_t thread_id; // thread id - set by StartThread()
|
||||
pthread_cond_t thread_signal;
|
||||
int work_mode;
|
||||
bool wake_up_was_called;
|
||||
|
||||
void SignalLoop();
|
||||
static void * StartRoutine(void *);
|
||||
|
@@ -113,9 +113,11 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
upload_dir = Text(L"upload_dir");
|
||||
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
|
||||
upload_files_chmod = Int(L"upload_files_chmod", 0640);
|
||||
create_thumb = Bool(L"create_thumb", false); // !! will be true
|
||||
create_thumb = Bool(L"create_thumb", true);
|
||||
thumb_mode = Int(L"thumb_mode", 2);
|
||||
thumb_cx = Size(L"thumb_cx", 150);
|
||||
thumb_cy = Size(L"thumb_cy", 150);
|
||||
convert_cmd = Text(L"convert_cmd", L"/usr/local/bin/convert");
|
||||
|
||||
templates_dir = Text(L"templates_dir");
|
||||
templates_dir_default = Text(L"templates_dir_default");
|
||||
|
@@ -198,9 +198,21 @@ public:
|
||||
int upload_files_chmod;
|
||||
|
||||
// create a thumbnail from an image
|
||||
// default: false (!!will be true)
|
||||
// default: true
|
||||
bool create_thumb;
|
||||
|
||||
// the mode of creating a thumbnail
|
||||
// width means thumb_cx, height means thumb_cy
|
||||
// 1: Width given, height automagically selected to preserve aspect ratio.
|
||||
// 2: Height given, width automagically selected to preserve aspect ratio.
|
||||
// 3: Maximum values of height and width given, aspect ratio preserved.
|
||||
// 4: Minimum values of width and height given, aspect ratio preserved.
|
||||
// 5: Width and height emphatically given, original aspect ratio ignored.
|
||||
// 6: Change as per widthxheight (3) but only if an image dimension exceeds a specified dimension.
|
||||
// 7: Change dimensions only if both image dimensions are less than specified dimensions.
|
||||
// default: 2
|
||||
int thumb_mode;
|
||||
|
||||
// width of thumbnails
|
||||
// default: 150
|
||||
size_t thumb_cx;
|
||||
@@ -209,6 +221,10 @@ public:
|
||||
// default: 150
|
||||
size_t thumb_cy;
|
||||
|
||||
// the convert program
|
||||
// default: /usr/local/bin/convert
|
||||
std::wstring convert_cmd;
|
||||
|
||||
// locale: en, pl
|
||||
// default: en
|
||||
std::wstring locale_str;
|
||||
|
@@ -58,6 +58,8 @@ void Item::Clear()
|
||||
file_fs = -1;
|
||||
file_type = WINIX_ITEM_FILETYPE_NONE;
|
||||
|
||||
has_thumb = false;
|
||||
|
||||
html_template.clear();
|
||||
|
||||
SetDateToNow();
|
||||
|
18
core/item.h
18
core/item.h
@@ -69,28 +69,12 @@ Type type;
|
||||
long default_item;
|
||||
|
||||
|
||||
|
||||
|
||||
// external static file authorized by winix
|
||||
/*
|
||||
enum Auth
|
||||
{
|
||||
auth_none = 0, // there is not an external file
|
||||
auth_image = 1, // png, gif, jpg - only types available to render by a web browser
|
||||
auth_document = 2, // pdf doc xls txt
|
||||
auth_other = 3 // other file
|
||||
};
|
||||
|
||||
|
||||
Auth auth;
|
||||
std::wstring auth_path; // path to a file (if auth!=auth_none)
|
||||
*/
|
||||
|
||||
// static file (if exists)
|
||||
std::wstring file_path; // relative file path
|
||||
int file_fs; // file system type where the file was saved
|
||||
int file_type; // file type (none, image, doc, etc)
|
||||
|
||||
bool has_thumb;
|
||||
|
||||
|
||||
std::wstring html_template;
|
||||
|
@@ -903,3 +903,4 @@ tm Time(time_t par)
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@@ -67,6 +67,10 @@ void System::Init()
|
||||
notify.SetUsers(&users);
|
||||
notify.SetDirs(&dirs);
|
||||
notify.Init();
|
||||
|
||||
thumb.SetSynchro(synchro);
|
||||
thumb.SetConvertCmd(config->convert_cmd);
|
||||
thumb.SetDb(db);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "rebus.h"
|
||||
#include "loadavg.h"
|
||||
#include "synchro.h"
|
||||
#include "thumb.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
|
||||
@@ -52,6 +53,9 @@ public:
|
||||
// notifications (by emails)
|
||||
Notify notify;
|
||||
|
||||
// thumbnails (special thread)
|
||||
Thumb thumb;
|
||||
|
||||
// the time when the winix starts
|
||||
time_t system_start;
|
||||
|
||||
|
228
core/thumb.cpp
Executable file
228
core/thumb.cpp
Executable file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "thumb.h"
|
||||
#include "utf8.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
||||
void Thumb::SetConvertCmd(const std::wstring & cmd)
|
||||
{
|
||||
convert_cmd = cmd;
|
||||
}
|
||||
|
||||
|
||||
void Thumb::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
// first thread (objects locked)
|
||||
void Thumb::CreateThumb(long item_id, const std::wstring & source, const std::wstring & dst, size_t cx, size_t cy, int aspect_mode)
|
||||
{
|
||||
item_temp.item_id = item_id;
|
||||
item_temp.source = source;
|
||||
item_temp.dst = dst;
|
||||
item_temp.cx = cx;
|
||||
item_temp.cy = cy;
|
||||
item_temp.aspect_mode = aspect_mode;
|
||||
|
||||
thumb_tab.insert(thumb_tab.end(), item_temp);
|
||||
WakeUpThread();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread (objects locked)
|
||||
bool Thumb::SignalReceived()
|
||||
{
|
||||
return !thumb_tab.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread (objects not locked)
|
||||
void Thumb::Do()
|
||||
{
|
||||
ThumbTab::iterator i;
|
||||
bool end;
|
||||
|
||||
Lock();
|
||||
i = thumb_tab.begin();
|
||||
Unlock();
|
||||
|
||||
do
|
||||
{
|
||||
Lock();
|
||||
|
||||
if( i != thumb_tab.end() )
|
||||
{
|
||||
item_work = *i;
|
||||
thumb_tab.erase(i++);
|
||||
end = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = true;
|
||||
}
|
||||
|
||||
Unlock();
|
||||
|
||||
if( !end )
|
||||
CreateThumbnail();
|
||||
|
||||
}
|
||||
while( !end );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Thumb::EscapePath(const std::string & path)
|
||||
{
|
||||
command << '"';
|
||||
|
||||
for(size_t i=0 ; i<path.size() ; ++i)
|
||||
{
|
||||
if( path[i] == '"' )
|
||||
command << '\\';
|
||||
|
||||
command << path[i];
|
||||
}
|
||||
|
||||
command << "\" ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
from: http://www.imagemagick.org/script/command-line-processing.php#geometry
|
||||
|
||||
scale% Height and width both scaled by specified percentage.
|
||||
scale-x%xscale-y% Height and width individually scaled by specified percentages. (Only one % symbol needed.)
|
||||
width Width given, height automagically selected to preserve aspect ratio.
|
||||
xheight Height given, width automagically selected to preserve aspect ratio.
|
||||
widthxheight Maximum values of height and width given, aspect ratio preserved.
|
||||
widthxheight^ Minimum values of width and height given, aspect ratio preserved.
|
||||
widthxheight! Width and height emphatically given, original aspect ratio ignored.
|
||||
widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension.
|
||||
widthxheight< Change dimensions only if both image dimensions exceed specified dimensions.
|
||||
*/
|
||||
void Thumb::SelectAspect()
|
||||
{
|
||||
switch( item_work.aspect_mode )
|
||||
{
|
||||
case WINIX_THUMB_MODE_1:
|
||||
command << item_work.cx;
|
||||
break;
|
||||
|
||||
case WINIX_THUMB_MODE_3:
|
||||
command << item_work.cx << "x" << item_work.cy;
|
||||
break;
|
||||
|
||||
case WINIX_THUMB_MODE_4:
|
||||
command << '"' << item_work.cx << "x" << item_work.cy << "^\"";
|
||||
break;
|
||||
|
||||
case WINIX_THUMB_MODE_5:
|
||||
command << '"' << item_work.cx << "x" << item_work.cy << "!\"";
|
||||
break;
|
||||
|
||||
case WINIX_THUMB_MODE_6:
|
||||
command << '"' << item_work.cx << "x" << item_work.cy << ">\"";
|
||||
break;
|
||||
|
||||
case WINIX_THUMB_MODE_7:
|
||||
command << '"' << item_work.cx << "x" << item_work.cy << "<\"";
|
||||
break;
|
||||
|
||||
case WINIX_THUMB_MODE_2:
|
||||
default:
|
||||
command << "x" << item_work.cy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// second thread (objects are not locked)
|
||||
void Thumb::CreateThumbnail()
|
||||
{
|
||||
command.Clear();
|
||||
|
||||
Ezc::WideToUTF8(convert_cmd, tempa);
|
||||
command << tempa << " -quiet -strip -thumbnail ";
|
||||
SelectAspect();
|
||||
command << " ";
|
||||
|
||||
Ezc::WideToUTF8(item_work.source, tempa);
|
||||
EscapePath(tempa);
|
||||
|
||||
Ezc::WideToUTF8(item_work.dst, tempa);
|
||||
EscapePath(tempa);
|
||||
|
||||
if( system(command.CStr()) == 0 )
|
||||
{
|
||||
Lock();
|
||||
log << log3 << "Thumb: created a thumbnail: " << tempa << logend;
|
||||
db->EditHasThumbById(true, item_work.item_id);
|
||||
Unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
log << log3 << "Thumb: some problems with creating a thumbnail: " << tempa << logend;
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread (objects are not locked)
|
||||
// !! there is a problem with GIF files
|
||||
// Bus error (core dumped)
|
||||
/*
|
||||
#include "wand/MagickWand.h"
|
||||
|
||||
// compiler options:
|
||||
// include: -I/usr/local/include/ImageMagick
|
||||
// link with: `MagickWand-config --ldflags --libs`
|
||||
|
||||
void Thumb::CreateThumbnail()
|
||||
{
|
||||
Ezc::WideToUTF8(item_work.source, sourcea);
|
||||
Ezc::WideToUTF8(item_work.dst, dsta);
|
||||
|
||||
MagickWandGenesis();
|
||||
|
||||
MagickWand * wand = NewMagickWand();
|
||||
|
||||
if( MagickReadImage(wand, sourcea.c_str()) )
|
||||
{
|
||||
MagickThumbnailImage(wand, item_work.cx, item_work.cy);
|
||||
|
||||
if( MagickWriteImage(wand, dsta.c_str()) )
|
||||
{
|
||||
Lock();
|
||||
log << log3 << "Thumb: created a thumbnail: " << dsta << logend;
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
DestroyMagickWand(wand);
|
||||
|
||||
MagickWandTerminus();
|
||||
}
|
||||
*/
|
||||
|
||||
|
90
core/thumb.h
Executable file
90
core/thumb.h
Executable file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorethumb
|
||||
#define headerfilecmslucorethumb
|
||||
|
||||
#include "basethread.h"
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "textstream.h"
|
||||
#include "db/db.h"
|
||||
|
||||
|
||||
|
||||
// Width given, height automagically selected to preserve aspect ratio.
|
||||
#define WINIX_THUMB_MODE_1 1
|
||||
|
||||
// Height given, width automagically selected to preserve aspect ratio.
|
||||
#define WINIX_THUMB_MODE_2 2
|
||||
|
||||
// Maximum values of height and width given, aspect ratio preserved.
|
||||
#define WINIX_THUMB_MODE_3 3
|
||||
|
||||
// Minimum values of width and height given, aspect ratio preserved.
|
||||
#define WINIX_THUMB_MODE_4 4
|
||||
|
||||
// Width and height emphatically given, original aspect ratio ignored.
|
||||
#define WINIX_THUMB_MODE_5 5
|
||||
|
||||
// Change as per widthxheight but only if an image dimension exceeds a specified dimension.
|
||||
#define WINIX_THUMB_MODE_6 6
|
||||
|
||||
// Change dimensions only if both image dimensions are less than specified dimensions.
|
||||
#define WINIX_THUMB_MODE_7 7
|
||||
|
||||
|
||||
|
||||
|
||||
class Thumb : public BaseThread
|
||||
{
|
||||
public:
|
||||
|
||||
void CreateThumb(long item_id, const std::wstring & source, const std::wstring & dst,
|
||||
size_t cx, size_t cy, int aspect_mode = WINIX_THUMB_MODE_2);
|
||||
|
||||
void SetConvertCmd(const std::wstring & cmd);
|
||||
void SetDb(Db * pdb);
|
||||
|
||||
private:
|
||||
|
||||
Db * db;
|
||||
|
||||
struct ThumbItem
|
||||
{
|
||||
long item_id;
|
||||
std::wstring source;
|
||||
std::wstring dst;
|
||||
size_t cx;
|
||||
size_t cy;
|
||||
int aspect_mode;
|
||||
};
|
||||
|
||||
// queue of thumbnails to create
|
||||
typedef std::list<ThumbItem> ThumbTab;
|
||||
ThumbTab thumb_tab;
|
||||
ThumbItem item_temp;
|
||||
|
||||
// this is set before the second thread starts
|
||||
std::wstring convert_cmd;
|
||||
|
||||
// only for second thread
|
||||
ThumbItem item_work;
|
||||
std::string tempa;
|
||||
TextStream<std::string> command;
|
||||
|
||||
virtual bool SignalReceived();
|
||||
virtual void Do();
|
||||
void CreateThumbnail();
|
||||
void SelectAspect();
|
||||
void EscapePath(const std::string & path);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user