AppImageGuiPy.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "PreCompiled.h"
00024 #ifndef _PreComp_
00025 # include <QIcon>
00026 # include <QImage>
00027 # include <QFileInfo>
00028 #endif
00029
00030 #include "ImageView.h"
00031
00032 #include <Base/Console.h>
00033 #include <Base/Exception.h>
00034 #include <Base/FileInfo.h>
00035 #include <App/Application.h>
00036 #include <Gui/MainWindow.h>
00037 #include <Gui/BitmapFactory.h>
00038
00039 using namespace ImageGui;
00040
00041
00042
00043 static PyObject *
00044 open(PyObject *self, PyObject *args)
00045 {
00046 const char* Name;
00047 const char* DocName=0;
00048 if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
00049 return NULL;
00050
00051 PY_TRY {
00052 QString fileName = QString::fromUtf8(Name);
00053 QFileInfo file(fileName);
00054
00055
00056 QImage imageq(fileName);
00057
00058
00059 int format = IB_CF_RGB24;
00060 unsigned char *pPixelData = NULL;
00061 if (imageq.isNull() == false) {
00062 pPixelData = new unsigned char[3 * (unsigned long)imageq.width() * (unsigned long)imageq.height()];
00063 unsigned char *pPix = pPixelData;
00064 for (int r = 0; r < imageq.height(); r++) {
00065 for (int c = 0; c < imageq.width(); c++) {
00066 QRgb rgb = imageq.pixel(c,r);
00067 *pPix = (unsigned char)qRed(rgb);
00068 *(pPix + 1) = (unsigned char)qGreen(rgb);
00069 *(pPix + 2) = (unsigned char)qBlue(rgb);
00070 pPix += 3;
00071 }
00072 }
00073 }
00074 else
00075 Py_Error(PyExc_Exception,"Could not load image");
00076
00077
00078
00079 ImageView* iView = new ImageView(Gui::getMainWindow());
00080 iView->setWindowIcon( Gui::BitmapFactory().pixmap("colors") );
00081 iView->setWindowTitle(file.fileName());
00082 iView->resize( 400, 300 );
00083 Gui::getMainWindow()->addWindow( iView );
00084 iView->pointImageTo((void *)pPixelData, (unsigned long)imageq.width(), (unsigned long)imageq.height(), format, 0, true);
00085
00086 } PY_CATCH;
00087
00088 Py_Return;
00089 }
00090
00091
00092
00093 static PyObject *
00094 insert(PyObject *self, PyObject *args)
00095 {
00096 return open(self, args);
00097 }
00098
00099
00100 struct PyMethodDef ImageGui_Import_methods[] = {
00101 {"open" ,open , 1},
00102 {"insert" ,insert, 1},
00103 {NULL, NULL}
00104 };