54 #include "gui/Qt/QtApplicationHandler.h"
55 #include "gui/Qt/QtMainWindow.h"
59 return new CQtApplicationHandler(argc, argv);
64 return new CQtMainWindow(x, y, width, height, title);
67 #include <qapplication.h>
68 #include <qfiledialog.h>
70 #if QT_VERSION >= 0x040000
71 #define GET_ASCII toAscii
73 #define GET_ASCII ascii
76 static char app_name[] =
"IVT_APPLICATION\0";
77 static int my_argc = 1;
78 static char *my_argv[2] = { app_name, NULL};
81 bool FileDialog(
bool save_dialog,
const char **filter,
int num_filter,
const char *caption,
char *filename,
int max_length)
83 QApplication *pApp = NULL;
86 pApp =
new QApplication(my_argc, my_argv);
89 char filter_str[1024];
90 char *fs = filter_str;
93 for (
int i = 0; i < num_filter; i++)
95 if (i == num_filter - 1)
97 sprintf(fs,
"%s (%s)", filter[(2*i)], filter[(2*i) + 1]);
98 fs += strlen(filter[(2*i)]) + strlen(filter[(2*i) + 1]) + 3;
102 sprintf(fs,
"%s (%s);;", filter[(2*i)], filter[(2*i) + 1]);
103 fs += strlen(filter[(2*i)]) + strlen(filter[(2*i) + 1]) + 5;
110 #if QT_VERSION >= 0x040000
111 QString s = QFileDialog::getSaveFileName(0, caption, NULL, filter_str);
113 QString s = QFileDialog::getSaveFileName(QString(filename), filter_str, 0,
"Save File Dialog", caption);
118 strncpy(filename, s.GET_ASCII(), max_length);
131 #if QT_VERSION >= 0x040000
132 QString s = QFileDialog::getOpenFileName(0, caption, NULL, filter_str);
134 QString s = QFileDialog::getOpenFileName(QString(filename), filter_str, 0,
"Open File Dialog", caption);
139 strncpy(filename, s.GET_ASCII(), max_length);
165 QApplication *pApp = NULL;
169 char *argv[] = {app_name, NULL};
171 pApp =
new QApplication(argc, argv);
174 QImage img(filename, 0);
178 if (img.depth() != 8 && img.depth() != 24 && img.depth() != 32)
180 printf(
"error: LoadImageFromFile: image '%s' has an unsupported bit depth of %d bpp\n", filename, img.depth());
184 int width = img.width();
185 int height = img.height();
190 pImage->
width = width;
197 uchar *ptr = img.bits();
198 if (img.depth() == 32)
200 unsigned char *output = pImage->
pixels;
202 int size = width * height;
203 for (
int i = 0; i < size; i++)
205 output[3*i ] = ptr[4*i + 2];
206 output[3*i + 1] = ptr[4*i + 1];
207 output[3*i + 2] = ptr[4*i ];
236 #if defined(USE_GTKGUI) && !defined(USE_REMOTEGUI)
238 #include "gui/GTK/GTKApplicationHandler.h"
239 #include "gui/GTK/GTKMainWindow.h"
243 return new CGTKApplicationHandler(argc, argv);
248 return new CGTKMainWindow(x, y, width, height, title);
252 bool FileDialog(
bool save_dialog,
const char **filter,
int num_filter,
const char *caption,
char *filename,
int max_length)
259 dialog = gtk_file_chooser_dialog_new (caption,
261 GTK_FILE_CHOOSER_ACTION_SAVE,
262 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
263 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
268 dialog = gtk_file_chooser_dialog_new (caption,
270 GTK_FILE_CHOOSER_ACTION_OPEN,
271 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
272 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
276 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), filename);
278 for (
int i = 0; i < num_filter; i++)
280 GtkFileFilter *f = gtk_file_filter_new();
281 gtk_file_filter_set_name(f, filter[2*i]);
282 gtk_file_filter_add_pattern(f, filter[2*i+1]);
283 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), f);
286 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
289 file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
290 strncpy(filename, file, max_length);
293 gtk_widget_destroy (dialog);
298 gtk_widget_destroy (dialog);
307 bool success =
false;
309 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
312 int channels = gdk_pixbuf_get_n_channels(pixbuf);
313 int bits_per_sample = gdk_pixbuf_get_bits_per_sample(pixbuf);
314 unsigned char *pixels = gdk_pixbuf_get_pixels(pixbuf);
315 int width = gdk_pixbuf_get_width(pixbuf);
316 int height = gdk_pixbuf_get_height(pixbuf);
317 int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
319 if (bits_per_sample == 8 && (channels == 1 || channels == 3 || channels == 4))
324 pImage->
width = width;
333 for (
int y = 0; y < height; y++)
335 memcpy(&pImage->
pixels[y*width], pixels, width);
343 for (
int y = 0; y < height; y++)
345 memcpy(&pImage->
pixels[3*y*width], pixels, 3*width);
352 for (
int y = 0; y < height; y++)
354 for (
int x = 0; x < width; x++)
356 pImage->
pixels[3*(y*width + x)] = pixels[4*x];
357 pImage->
pixels[3*(y*width + x)+1] = pixels[4*x+1];
358 pImage->
pixels[3*(y*width + x)+2] = pixels[4*x+2];
377 #if defined(WIN32) && !defined(USE_REMOTEGUI)
379 #include "gui/win32/Win32ApplicationHandler.h"
380 #include "gui/win32/Win32MainWindow.h"
384 return new CWin32ApplicationHandler();
389 return new CWin32MainWindow(x, y, width, height, title);
395 bool FileDialog(
bool save_dialog,
const char **filter,
int num_filter,
const char *caption,
char *filename,
int max_length)
397 char filter_str[1024];
398 char *fs = filter_str;
401 for (
int i = 0; i < num_filter; i++)
403 sprintf(fs,
"%s", filter[(2*i)]);
404 fs += strlen(filter[(2*i)]) + 1;
406 sprintf(fs,
"%s", filter[(2*i) + 1]);
407 fs += strlen(filter[(2*i) + 1]) + 1;
412 memset(&ofn, 0,
sizeof(OPENFILENAME));
414 ofn.lStructSize =
sizeof(OPENFILENAME);
415 ofn.hwndOwner = NULL;
416 ofn.hInstance = NULL;
417 ofn.lpstrFilter = filter_str;
418 ofn.lpstrCustomFilter = NULL;
419 ofn.nMaxCustFilter = 0;
420 ofn.nFilterIndex = 1;
421 ofn.lpstrFile = filename;
422 ofn.nMaxFile = max_length;
423 ofn.lpstrFileTitle = NULL;
424 ofn.nMaxFileTitle = 0;
425 ofn.lpstrInitialDir = NULL;
426 ofn.lpstrTitle = caption;
429 ofn.nFileExtension = 0;
430 ofn.lpstrDefExt = NULL;
433 ofn.lpTemplateName = NULL;
437 if (GetSaveFileName(&ofn))
444 if (GetOpenFileName(&ofn))
461 OLECHAR wszPath[MAX_PATH+1];
467 MultiByteToWideChar(CP_ACP, 0, filename, -1, wszPath, MAX_PATH);
468 HRESULT hr = OleLoadPicturePath(wszPath, 0, 0, 0, IID_IPicture, (
void**)&pPicture);
473 hdcTemp = CreateCompatibleDC(GetDC(0));
480 pPicture->get_Width(&lWidth);
481 lWidthPixels = MulDiv(lWidth, GetDeviceCaps(hdcTemp, LOGPIXELSX), 2540);
482 pPicture->get_Height(&lHeight);
483 lHeightPixels = MulDiv(lHeight, GetDeviceCaps(hdcTemp, LOGPIXELSY), 2540);
489 bi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
490 bi.bmiHeader.biBitCount = 32;
491 bi.bmiHeader.biWidth = lWidthPixels;
492 bi.bmiHeader.biHeight = lHeightPixels;
493 bi.bmiHeader.biCompression = BI_RGB;
494 bi.bmiHeader.biPlanes = 1;
497 hbmpTemp = CreateDIBSection(hdcTemp, &bi, DIB_RGB_COLORS, (
void**)&pBits, 0, 0);
506 SelectObject(hdcTemp, hbmpTemp);
509 pPicture->Render(hdcTemp, 0, 0, lWidthPixels, lHeightPixels, 0, 0, lWidth, lHeight, 0);
515 pImage->
width = lWidthPixels;
516 pImage->
height = lHeightPixels;
522 unsigned char *output = pImage->
pixels;
525 for(
long i = 0; i < lWidthPixels * lHeightPixels; i++)
527 BYTE* pPixel = (BYTE*)(&pBits[i]);
528 output[3*i] = pPixel[2];
529 output[3*i + 1] = pPixel[1];
530 output[3*i + 2] = pPixel[0];
533 DeleteObject(hbmpTemp);
546 #include "gui/Cocoa/CocoaApplicationHandler.h"
547 #include "gui/Cocoa/CocoaMainWindow.h"
551 return new CCocoaApplicationHandler();
556 return new CCocoaMainWindow(x, y, width, height, title);
562 bool CocoaFileDialog(
bool save_dialog,
const char **filter,
int num_filter,
const char *caption,
char *filename,
int max_length);
563 bool CocoaLoadImage(
const char *filename,
unsigned char **ptr,
int *width,
int *height,
int *type);
564 void CocoaFreeImageMem(
unsigned char *ptr);
568 bool FileDialog(
bool save_dialog,
const char **filter,
int num_filter,
const char *caption,
char *filename,
int max_length)
572 char **cocoa_filters = NULL;
573 if (filter != NULL) {
574 cocoa_filters =
new char*[num_filter];
575 for (
int i = 0; i < num_filter; i++)
577 sscanf(filter[2*i + 1],
"*.%s", buf);
578 cocoa_filters[i] =
new char[strlen(buf) + 1];
579 strcpy(cocoa_filters[i], buf);
583 bool result = CocoaFileDialog(save_dialog, (
const char**)cocoa_filters, num_filter, caption, filename, max_length);
585 if (cocoa_filters != NULL)
587 for (
int i = 0; i < num_filter; i++)
589 delete [] cocoa_filters[i];
591 delete [] cocoa_filters;
600 unsigned char *ptr = NULL;
605 if (CocoaLoadImage(filename, &ptr, &width, &height, &type))
610 pImage->
width = width;
619 CocoaFreeImageMem(ptr);
632 #include "gui/Remote/RemoteApplicationHandler.h"
633 #include "gui/Remote/RemoteMainWindow.h"
637 return new CRemoteApplicationHandler(argc, argv);
642 CRemoteApplicationHandler *app_handler = CRemoteApplicationHandler::GetApplicationHandler();
647 return app_handler->CreateMainWindow(x, y, width, height, title);
651 bool FileDialog(
bool save_dialog,
const char **filter,
int num_filter,
const char *caption,
char *filename,
int max_length)
bool m_bOwnMemory
Flag signaling if memory is to be freed or not.
bool FileDialog(bool save_dialog, const char **filter, int num_filter, const char *caption, char *filename, int max_length)
ImageType type
The type of the image.
int width
The width of the image in pixels.
int height
The height of the image in pixels.
Interface for the creation of GUIs with the GUI toolkit of the IVT.
unsigned char * pixels
The pointer to the the pixels.
bool LoadImageFromFile(const char *filename, CByteImage *pImage)
CApplicationHandlerInterface * CreateApplicationHandler(int argc=0, char **argv=0)
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
CMainWindowInterface * CreateMainWindow(int x, int y, int width, int height, const char *title)
int bytesPerPixel
The number of bytes used for encoding one pixel.