SilentEye 0.4.1

modules/seformatbmp/seformatbmp.cpp

Go to the documentation of this file.
00001 //  This file is part of SilentEye.
00002 //
00003 //  SilentEye is free software: you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation, either version 3 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  SilentEye is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with SilentEye.  If not, see <http://www.gnu.org/licenses/>.
00015 
00016 #include "seformatbmp.h"
00017 
00018 namespace SEFormatBMP {
00019 
00020     SEFormatBmp::SEFormatBmp()
00021     {
00022         this->setObjectName("SEFormatBmp");
00023         m_logger = new Logger(this);
00024 
00025         m_encodeWidget = NULL;
00026         m_decodeWidget = NULL;
00027     }
00028 
00029     SEFormatBmp::~SEFormatBmp()
00030     {
00031         if (m_encodeWidget != NULL)
00032             delete m_encodeWidget;
00033         if (m_decodeWidget != NULL)
00034             delete m_decodeWidget;
00035         delete m_logger;
00036     }
00037 
00038     QString SEFormatBmp::name() const
00039     {
00040         return QString("Silent Eye Image Format BMP");
00041     }
00042 
00043     QString SEFormatBmp::version() const
00044     {
00045         return QString("1.1");
00046     }
00047 
00048     QString SEFormatBmp::status()
00049     {
00050         return "OK|";
00051     }
00052 
00053     QWidget* SEFormatBmp::encodeWidget()
00054     {
00055         if (m_encodeWidget == NULL)
00056         {
00057             m_encodeWidget = new OptionWidget();
00058             m_encodeWidget->setObjectName("EncodeWidget");
00059             connect(m_encodeWidget, SIGNAL(optionHasChanged()), this, SLOT(optionHasChanged()));
00060         }
00061         return m_encodeWidget;
00062     }
00063 
00064     QWidget* SEFormatBmp::decodeWidget()
00065     {
00066         if (m_decodeWidget == NULL)
00067         {
00068             m_decodeWidget = new OptionWidget();
00069             m_decodeWidget->setObjectName("DecodeWidget");
00070         }
00071         return m_decodeWidget;
00072     }
00073 
00074     QPointer<Image> SEFormatBmp::encodeImage(QPointer<Image> img, bool dontDuplicate)
00075     {
00076         // m_logger->debug("encodeImage");
00077         return updateImage(img, (OptionWidget*)encodeWidget(), dontDuplicate);
00078     }
00079 
00080     QPointer<Image> SEFormatBmp::decodeImage(QPointer<Image> img, bool dontDuplicate)
00081     {
00082         // m_logger->debug("decodeImage");
00083         return updateImage(img, (OptionWidget*)decodeWidget(), dontDuplicate);
00084     }
00085 
00086     QPointer<Image> SEFormatBmp::updateImage(QPointer<Image> img, OptionWidget* w, bool dontDuplicate)
00087     {
00088         QPointer<Image> imgBMP;
00089         if (dontDuplicate)
00090         {
00091             imgBMP = new ImageBMP(img); // don't copy image data
00092         }
00093         else
00094         {
00095             imgBMP = new ImageBMP(*img); // duplicate image into a new one
00096         }
00097 
00098         ImageBMP* newImage = ((ImageBMP*)imgBMP.data());
00099         newImage->setNbBits(w->nbBits());
00100         newImage->setColorUsed(w->isRedUsed(), w->isGreenUsed(), w->isBlueUsed());
00101         newImage->setDistribution(w->distribution());
00102         newImage->setHeaderPosition(w->headerPosition());
00103 
00104         return imgBMP;
00105     }
00106 
00107     QString SEFormatBmp::typeSupported() const
00108     {
00109         return QString("BMP");
00110     }
00111 
00112     bool SEFormatBmp::isEncodeWidgetReady() const
00113     {
00114         return true;
00115     }
00116 
00117     bool SEFormatBmp::isDecodeWidgetReady() const
00118     {
00119         return true;
00120     }
00121 
00122     void SEFormatBmp::optionHasChanged()
00123     {
00124         emit optionChanged();
00125     }
00126 
00127     }
00128 
00129 Q_EXPORT_PLUGIN2(seformatbmp, SEFormatBMP::SEFormatBmp)