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";
81 bool FileDialog(
bool save_dialog,
const char **
filter,
int num_filter,
const char *caption,
char *filename,
int max_length)
83 QApplication *pApp = NULL;
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;
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());
197 uchar *ptr =
img.bits();
198 if (
img.depth() == 32)
200 unsigned char *output = pImage->
pixels;
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) 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))
335 memcpy(&pImage->
pixels[
y*width], pixels, width);
345 memcpy(&pImage->
pixels[3*
y*width], pixels, 3*width);
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) 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);
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))
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)
int width
The width of the image in pixels.
CMainWindowInterface * CreateMainWindow(int x, int y, int width, int height, const char *title)
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
bool m_bOwnMemory
Flag signaling if memory is to be freed or not.
GLuint GLuint GLsizei GLenum type
unsigned char * pixels
The pointer to the the pixels.
bool LoadImageFromFile(const char *filename, CByteImage *pImage)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
bool FileDialog(bool save_dialog, const char **filter, int num_filter, const char *caption, char *filename, int max_length)
int height
The height of the image in pixels.
Interface for the creation of GUIs with the GUI toolkit of the IVT.
int bytesPerPixel
The number of bytes used for encoding one pixel.
GLenum GLsizei GLsizei height
ImageType type
The type of the image.
CApplicationHandlerInterface * CreateApplicationHandler(int argc=0, char **argv=0)