mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
reorganizing repo
git-svn-id: svn://ultimatepp.org/upp/trunk@9206 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
7d17505cfe
commit
e3e8d627f5
3840 changed files with 0 additions and 1161578 deletions
|
|
@ -1,78 +0,0 @@
|
|||
#ifndef _ThreadedImageLoader_ThreadedImageLoader_h
|
||||
#define _ThreadedImageLoader_ThreadedImageLoader_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <plugin/jpg/jpg.h>
|
||||
#include <ImageDisplayCtrl/ImageDisplayCtrl.h>
|
||||
|
||||
#define LAYOUTFILE <ThreadedImageLoader/ThreadedImageLoader.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
struct ThreadedImageLoadInfo : Moveable<ThreadedImageLoadInfo> {
|
||||
String filepath;
|
||||
|
||||
ThreadedImageLoadInfo() {}
|
||||
ThreadedImageLoadInfo(const String& in_filepath) : filepath(in_filepath) {}
|
||||
};
|
||||
struct ThreadedImageLoadResult : public ThreadedImageLoadInfo , Moveable<ThreadedImageLoadResult> {
|
||||
PixelArray image;
|
||||
bool valid;
|
||||
ThreadedImageLoadResult() : valid(false) {}
|
||||
};
|
||||
|
||||
|
||||
class ImageLoader
|
||||
{
|
||||
public:
|
||||
ImageLoader();
|
||||
|
||||
Callback WhenImageReady;
|
||||
|
||||
volatile bool ReadyToLoad() const { return ready_to_load_; }
|
||||
volatile bool NewImageAvailable() const { return new_image_ready_; }
|
||||
inline void Reset() { new_image_ready_ = false; }
|
||||
|
||||
const ThreadedImageLoadResult& Result() const { return loading_info_; }
|
||||
|
||||
void LoadNextImage( const ThreadedImageLoadInfo& info );
|
||||
void Die();
|
||||
|
||||
String Status() const { return status_; }
|
||||
|
||||
void LoadingThreadFunction();
|
||||
|
||||
protected:
|
||||
volatile bool ready_to_load_;
|
||||
volatile bool new_image_ready_;
|
||||
volatile bool time_to_die_;
|
||||
|
||||
ThreadedImageLoadResult loading_info_;
|
||||
|
||||
String status_;
|
||||
|
||||
Event job_ready_;
|
||||
};
|
||||
|
||||
|
||||
class ThreadedImageLoader : public WithThreadedImageLoaderLayout<TopWindow> {
|
||||
public:
|
||||
typedef ThreadedImageLoader CLASSNAME;
|
||||
ThreadedImageLoader();
|
||||
~ThreadedImageLoader();
|
||||
|
||||
void OnImageLoaded();
|
||||
void OnSelectDir();
|
||||
void SyncTime();
|
||||
|
||||
public:
|
||||
// Menu control
|
||||
MenuBar menus;
|
||||
void SetupMainMenu(Bar& bar);
|
||||
|
||||
protected:
|
||||
ImageLoader loader;
|
||||
Thread loader_thread;
|
||||
Vector<String> remaining;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
LAYOUT(ThreadedImageLoaderLayout, 220, 190)
|
||||
ITEM(ImageDisplayCtrl, display, HSizePosZ(4, 4).VSizePosZ(4, 26))
|
||||
ITEM(EditField, time, SetEditable(false).HSizePosZ(2, 4).BottomPosZ(3, 19))
|
||||
END_LAYOUT
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
ImageDisplayCtrl,
|
||||
plugin\jpg;
|
||||
|
||||
file
|
||||
ThreadedImageLoader.h,
|
||||
main.cpp,
|
||||
ThreadedImageLoader.lay;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI MT";
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
#include "ThreadedImageLoader.h"
|
||||
|
||||
#define LLOG(x) TLOG(x)
|
||||
|
||||
String LogTime()
|
||||
{
|
||||
String out;
|
||||
out << GetSysTime() << " % " << (dword)msecs() % 10000;
|
||||
return out;
|
||||
}
|
||||
|
||||
String LogContext()
|
||||
{
|
||||
String out = LogTime();
|
||||
out << ", t=" << (int)GetCurrentThreadId() << ": ";
|
||||
return out;
|
||||
}
|
||||
|
||||
#define TLOG(x) RLOG(LogContext() << x);
|
||||
|
||||
ImageLoader::ImageLoader() :
|
||||
ready_to_load_(false),
|
||||
time_to_die_(false),
|
||||
new_image_ready_(false),
|
||||
status_("Thread not started") {
|
||||
LLOG("LoadingThread> "+status_);
|
||||
}
|
||||
|
||||
void ImageLoader::LoadingThreadFunction()
|
||||
{
|
||||
// Repeat until time_to_die, then exit
|
||||
ready_to_load_ = true;
|
||||
while (!time_to_die_) {
|
||||
status_ = "Waiting for job";
|
||||
LLOG("Wait");
|
||||
job_ready_.Wait();
|
||||
LLOG("//Wait");
|
||||
if (time_to_die_)
|
||||
break;
|
||||
|
||||
status_ = "Loading";
|
||||
LLOG("StdLoadImage");
|
||||
loading_info_.image = StdLoadArrayFile(loading_info_.filepath).pixel;
|
||||
LLOG("//StdLoadImage");
|
||||
//------------------------------------------------------
|
||||
Size cachesize = GetFitSize(loading_info_.image.GetSize(), ScreenInfo().GetClip().Size());
|
||||
LLOG("Image ctr");
|
||||
// Image cacheimage(cachesize);
|
||||
LLOG("//Image ctr");
|
||||
LLOG("srcim");
|
||||
const PixelArray& srcim = loading_info_.image;
|
||||
// PixelArray srcim(ImageToPixelArray(loading_info_.image));
|
||||
LLOG("dstim");
|
||||
PixelArray dstim(cachesize, -3);
|
||||
// PixelArray dstim(ImageToPixelArray(cacheimage));
|
||||
//-- Either just resize or resize with anti-aliasing
|
||||
//PixelCopy(dstim,cacheimage.GetSize(),srcim,loading_info_.image.GetSize());
|
||||
TLOG("PixelCopyAntiAlias");
|
||||
PixelCopyAntiAlias(dstim,dstim.GetSize(),srcim,srcim.GetSize());
|
||||
TLOG("//PixelCopyAntiAlias");
|
||||
loading_info_.image = dstim; //PixelArrayToImage(dstim);
|
||||
TLOG("//PixelArrayToImage");
|
||||
//------------------------------------------------------
|
||||
loading_info_.valid = true;
|
||||
status_ = "Image ready";
|
||||
LLOG("LoadingThread> "+status_);
|
||||
new_image_ready_ = true;
|
||||
ready_to_load_ = true;
|
||||
PostCallback(WhenImageReady);
|
||||
}
|
||||
status_ = "Finished";
|
||||
//LLOG("LoadingThread> "+status_);
|
||||
// Thread::Exit(0);
|
||||
}
|
||||
void ImageLoader::LoadNextImage(const ThreadedImageLoadInfo& info)
|
||||
{
|
||||
Reset();
|
||||
ready_to_load_ = false;
|
||||
|
||||
ThreadedImageLoadInfo& blah = loading_info_;
|
||||
blah = info;
|
||||
loading_info_.image = PixelArray();
|
||||
loading_info_.valid = false;
|
||||
|
||||
TLOG("LoadNextImage / Set");
|
||||
job_ready_.Set();
|
||||
TLOG("//LoadNextImage / Set");
|
||||
}
|
||||
void ImageLoader::Die()
|
||||
{
|
||||
WhenImageReady = Callback::Empty();
|
||||
new_image_ready_ = false;
|
||||
time_to_die_ = true;
|
||||
ready_to_load_ = false;
|
||||
status_ = "Terminating";
|
||||
job_ready_.Set();
|
||||
}
|
||||
|
||||
ThreadedImageLoader::ThreadedImageLoader()
|
||||
{
|
||||
CtrlLayout(*this, "Threaded Image Loader");
|
||||
AddFrame(menus);
|
||||
menus.Set(THISBACK(SetupMainMenu));
|
||||
loader.WhenImageReady = THISBACK(OnImageLoaded);
|
||||
loader_thread.Run(callback(&loader,ImageLoader::LoadingThreadFunction));
|
||||
loader_thread.Priority(0);
|
||||
Zoomable().Sizeable();
|
||||
SetTimeCallback(-200, THISBACK(SyncTime));
|
||||
}
|
||||
ThreadedImageLoader::~ThreadedImageLoader()
|
||||
{
|
||||
loader.Die();
|
||||
loader_thread.Wait();
|
||||
}
|
||||
void ThreadedImageLoader::SyncTime()
|
||||
{
|
||||
time <<= LogTime();
|
||||
}
|
||||
void ThreadedImageLoader::OnImageLoaded() {
|
||||
TLOG("OnImageLoaded, display.SetImage");
|
||||
display.SetImage(PixelArrayToImage(loader.Result().image));
|
||||
TLOG("//display.SetImage");
|
||||
TLOG("Loaded Image: "+loader.Result().filepath);
|
||||
if (!remaining.IsEmpty()) {
|
||||
TLOG(" - next is: "+remaining.Top());
|
||||
loader.LoadNextImage(remaining.Pop());
|
||||
}
|
||||
}
|
||||
void ThreadedImageLoader::OnSelectDir() {
|
||||
FileSel filesel;
|
||||
filesel.Type("All Images","*.jpg;*.png;*.bmp;*.jpeg");
|
||||
filesel.Type("All files","*.*");
|
||||
if (!filesel.ExecuteSelectDir("Select directory")) {
|
||||
return;
|
||||
}
|
||||
remaining.Clear();
|
||||
String dirname = filesel;
|
||||
FindFile ff(dirname + "\\*.jpg");
|
||||
while (ff.Next()) {
|
||||
remaining.Insert(0,dirname+"\\"+ff.GetName());
|
||||
}
|
||||
LLOG("Adding files to load list from directory: "+dirname);
|
||||
for (int i = 0; i < remaining.GetCount(); ++i)
|
||||
LLOG(" "+remaining[i]);
|
||||
|
||||
if (!remaining.IsEmpty())
|
||||
loader.LoadNextImage(remaining.Pop());
|
||||
}
|
||||
void ThreadedImageLoader::SetupMainMenu(Bar& bar)
|
||||
{
|
||||
bar.Add("[E&xit]",THISBACK(Close)).Key(K_CTRL_E);
|
||||
bar.Add("[Select &Directory]",THISBACK(OnSelectDir)).Key(K_CTRL_D);
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
JpgEncoder::Register();
|
||||
ThreadedImageLoader().Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue