Commits

Andrew Fenn committed 6ae19ca

Added a limit on to the pixmap size so it doesn't crash upon conversion
Fixed an crash issue with unimplemented save function
Added more formats to the image editor
Fixed an transparency bug in the image converter

Comments (0)

Files changed (4)

Dependencies/GenericImageEditor/src/genericimageeditor.cpp

     GenericImageEditor::registerCodecFactory("tiff",        genCodecFactory);
     GenericImageEditor::registerCodecFactory("xbm",         genCodecFactory);
     GenericImageEditor::registerCodecFactory("xpm",         genCodecFactory);
+    GenericImageEditor::registerCodecFactory("f32",         heightCodecFactory);
 
     // Below are files generated via render target. Perhaps only make these read only.
     GenericImageEditor::registerCodecFactory("dds",         genCodecFactory);
 
-    GenericImageEditor::registerCodecFactory("f32",         heightCodecFactory);
-
     Ogitors::EventManager::getSingletonPtr()->connectEvent(Ogitors::EventManager::MODIFIED_STATE_CHANGE, this, true, 0, true, 0, EVENT_CALLBACK(GenericImageEditor, onModifiedStateChanged));
     Ogitors::EventManager::getSingletonPtr()->connectEvent(Ogitors::EventManager::LOAD_STATE_CHANGE, this, true, 0, true, 0, EVENT_CALLBACK(GenericImageEditor, onLoadStateChanged));
 }
 //-----------------------------------------------------------------------------------------
 void GenericImageEditor::onSave()
 {
-    mActSave->setEnabled(false);
+  //  mActSave->setEnabled(false);
 }
 //-----------------------------------------------------------------------------------------
 void GenericImageEditor::registerCodecFactory(QString extension, IImageEditorCodecFactory* codec)
 //-----------------------------------------------------------------------------------------
 void GenericImageEditor::tabContentChange()
 {
-    mActSave->setEnabled(true);
+  //  mActSave->setEnabled(true);
 }
 //-----------------------------------------------------------------------------------------
 void GenericImageEditor::closeTab(int index)

Dependencies/GenericImageEditor/src/genericimageeditorcodec.cpp

     Ogre::Image image;
     image.load(stream);
 
-    ImageConverter imageConverter(image.getWidth(), image.getHeight());
+    size_t width = image.getWidth();
+    size_t height = image.getHeight();
+    
+    if (width > 256) width = 256;
+    if (height > 256) height = 256;
 
-    if (!mPixmap.convertFromImage(imageConverter.fromOgreImage(image)))
+    /** FIXME: Flaw in the implementation of GenericImageEditor, using pixmaps means
+    that you can not have large images, implementation should be changed to
+    QImageReader so that the full size of the image can be displayed */
+
+    ImageConverter imageConverter(width, height);
+    /* Propper use of this line should be:
+        ImageConverter imageConverter(image.getWidth(), image.getHeight());
+
+       If you use this with a pixmap the image conversion will crash, a pixmap is too small and
+       needs to be changed. */
+
+    if (mPixmap.convertFromImage(imageConverter.fromOgreImage(image)))
         return mPixmap;
 
+    mPixmap = 0;
     return mPixmap;
 }
 //-----------------------------------------------------------------------------------------

Dependencies/GenericImageEditor/src/genericimageeditordocument.cpp

     mLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
 
     setWidget(mLabel);
-
-    QString tabTitle = docName;
-    if(tabTitle.length() > 25)
-        tabTitle = tabTitle.left(12) + "..." + tabTitle.right(10);
-    setWindowTitle(tabTitle + QString("[*]"));
     setWindowModified(false);
 
     mCodec->onAfterDisplay();

Dependencies/ImageConverter/src/imageconverter.cpp

 
 QImage ImageConverter::_imageFromRenderTarget(const Ogre::Image& img)
 {
-    Ogre::TextureManager::getSingletonPtr()->loadImage("QTTextureName", mResourceGroup, img);
+    Ogre::TextureManager::getSingletonPtr()->loadImage("QTTextureName", "QTImageConverter", img);
 
     // create our material
-    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->create("terrainMaterial", mResourceGroup);
+    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->create("terrainMaterial", "QTImageConverter");
     Ogre::Technique * technique = material->getTechnique(0);
     Ogre::Pass* pass = technique->getPass(0);
     Ogre::TextureUnitState* textureUnit = pass->createTextureUnitState();
 
     mRttTex->update();
 
-    size_t size = Ogre::PixelUtil::getMemorySize(mWidth, mHeight, 1, Ogre::PF_B8G8R8);
+    size_t size = Ogre::PixelUtil::getMemorySize(mWidth, mHeight, 1, Ogre::PF_A8R8G8B8);
     unsigned char *dataptr = OGRE_ALLOC_T(unsigned char, size, Ogre::MEMCATEGORY_GENERAL);
-    Ogre::PixelBox pb(mWidth,mHeight,1,Ogre::PF_B8G8R8, dataptr);
+    Ogre::PixelBox pb(mWidth,mHeight,1,Ogre::PF_A8R8G8B8, dataptr);
     pb.setConsecutive();
 
     mRttTex->copyContentsToMemory(pb, Ogre::RenderTarget::FB_FRONT);
-    QImage qimg(dataptr, pb.getWidth(), pb.getHeight(), QImage::Format_RGB888);
+    QImage qimg(dataptr, pb.getWidth(), pb.getHeight(), QImage::Format_ARGB32);
 
     OGRE_FREE(dataptr, Ogre::MEMCATEGORY_GENERAL);
-    
+
     return qimg;
 }