love::filesystem::FileData *ImageData::encode(EncodedFormat format, const char *filename) { FormatHandler *encoder = nullptr; FormatHandler::EncodedImage encodedimage; FormatHandler::DecodedImage rawimage; rawimage.width = width; rawimage.height = height; rawimage.size = width*height*sizeof(pixel); rawimage.data = data; for (FormatHandler *handler : formatHandlers) { if (handler->canEncode(format)) { encoder = handler; break; } } if (encoder != nullptr) { thread::Lock lock(mutex); encodedimage = encoder->encode(rawimage, format); } if (encoder == nullptr || encodedimage.data == nullptr) { const char *fname = "unknown"; getConstant(format, fname); throw love::Exception("No suitable image encoder for %s format.", fname); } love::filesystem::FileData *filedata = nullptr; try { filedata = new love::filesystem::FileData(encodedimage.size, filename); } catch (love::Exception &) { encoder->free(encodedimage.data); throw; } memcpy(filedata->getData(), encodedimage.data, encodedimage.size); encoder->free(encodedimage.data); return filedata; }
bool ExternalFile::idle( const QString& name, bool read ) { setFileName( name ); if( !TibiaFile::exists() ) { emit documentError( name, QObject::tr( "File does not exist." ), -1 ); return false; } if( !TibiaFile::open( QIODevice::ReadOnly ) ) { emit parseError( QObject::tr( "Open Error" ), TibiaFile::error() ); return false; } if( read ) { QDataStream in( this ); in.setByteOrder( QDataStream::LittleEndian ); in >> m_version; m_datFormat = g_formatHandler.getFormatByClient( m_version ); if( !m_datFormat ) { emit documentError( name, tr( "Unknown format: %1" ).arg( m_version ), -1 ); return false; } } m_idle = true; m_success = true; return m_success; }
void ItemEditor::onCurrentIndexChanged( int index ) { qint32 version = ui->comboVersions->itemData( index, Qt::UserRole ).toInt(); DatFormat *datFormat = g_formatHandler.getFormatByClient( version ); if( datFormat ) { ui->itemAttributes->setFormat( datFormat ); } }
void ImageData::decode(love::filesystem::FileData *data) { FormatHandler *decoder = nullptr; FormatHandler::DecodedImage decodedimage; for (FormatHandler *handler : formatHandlers) { if (handler->canDecode(data)) { decoder = handler; break; } } if (decoder) decodedimage = decoder->decode(data); if (decodedimage.data == nullptr) { const char *ext = data->getExtension().c_str(); throw love::Exception("Could not decode to ImageData: unrecognized format (%s)", ext); } // The decoder *must* output a 32 bits-per-pixel image. if (decodedimage.size != decodedimage.width*decodedimage.height*sizeof(pixel)) { if (decodeHandler) decodeHandler->free(decodedimage.data); else delete[] decodedimage.data; throw love::Exception("Could not convert image!"); } // Clean up any old data. if (decodeHandler) decodeHandler->free(this->data); else delete[] this->data; this->width = decodedimage.width; this->height = decodedimage.height; this->data = decodedimage.data; decodeHandler = decoder; }
ItemEditor::ItemEditor( QWidget *parent, Qt::WindowFlags flags, TibiaItem *tibiaItem, const ItemData& itemData ) : QMdiSubWindow( parent, flags ), ui( new Ui::ItemEditorClass ) { m_itemData = itemData; m_tibiaItem = tibiaItem; m_internalWidget = new QWidget; m_undoStack = new QUndoStack; ui->setupUi( m_internalWidget ); ui->buttonLayout->setAlignment ( ui->viewDirectionE, Qt::AlignCenter ); ui->buttonLayout->setAlignment ( ui->viewDirectionN, Qt::AlignCenter ); ui->buttonLayout->setAlignment ( ui->viewDirectionNE, Qt::AlignCenter ); ui->buttonLayout->setAlignment ( ui->viewDirectionNW, Qt::AlignCenter ); ui->buttonLayout->setAlignment ( ui->viewDirectionS, Qt::AlignCenter ); ui->buttonLayout->setAlignment ( ui->viewDirectionSE, Qt::AlignCenter ); ui->buttonLayout->setAlignment ( ui->viewDirectionSW, Qt::AlignCenter ); ui->buttonLayout->setAlignment ( ui->viewDirectionW, Qt::AlignCenter ); setWidget( m_internalWidget ); setAttribute( Qt::WA_DeleteOnClose ); setWindowTitle( ( tibiaItem ? TibiaItem::fullName( g_tibiaHandler.getItemFile(), tibiaItem ) : TibiaItem::typeName( itemData.type ) ) + " [*]" ); setGeometry( m_internalWidget->geometry() ); if( g_formatHandler.isLoaded() ) { for( DatFormatMap::const_iterator it = g_formatHandler.getFormatsBegin(); it != g_formatHandler.getFormatsEnd(); it++ ) ui->comboVersions->insertItem( 0, it.value()->getName(), QVariant::fromValue( it.key() ) ); } else ui->comboVersions->insertItem( 0, tr( "No Formats" ) ); QObject::connect( ui->viewImage, SIGNAL( imageChanged( const QImage& ) ), this, SLOT( onImageChanged( const QImage& ) ) ); QObject::connect( ui->viewShowNumbers, SIGNAL( toggled( bool ) ), ui->viewImage, SLOT( showNumbers( bool ) ) ); QObject::connect( ui->comboVersions, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onCurrentIndexChanged( int ) ) ); dParams.showPattern = true; ui->viewImage->setMimeDropType( MIME_TYPE_SPRITE ); ui->viewImage->setImage( g_tibiaHandler.drawItem( m_itemData, dParams ) ); ui->itemAttributes->setFormat( g_formatHandler.getBaseFormat() ); m_spriteModel = new ItemSpriteModel( ui->spriteView, &m_itemData ); m_spriteModel->setDragMimeFormat( MIME_TYPE_SPRITE ); m_spriteModel->setDropMimeFormats( QStringList() << MIME_TYPE_SPRITE ); ui->spriteView->setModel( m_spriteModel ); onLoadItem(); QObject::connect( m_undoStack, SIGNAL( canUndoChanged( bool ) ), this, SLOT( setWindowModified( bool ) ) ); QObject::connect( ui->viewAppearanceBox, SIGNAL( clicked( QAbstractButton * ) ), this, SLOT( onAppearanceButtonClicked( QAbstractButton * ) ) ); QObject::connect( ui->viewAttributeBox, SIGNAL( clicked( QAbstractButton * ) ), this, SLOT( onAttributeButtonClicked( QAbstractButton * ) ) ); QObject::connect( ui->viewBlendLayers, SIGNAL( toggled( bool ) ), this, SLOT( onToggleBlend( bool ) ) ); QObject::connect( ui->viewAnimation, SIGNAL( valueChanged( int ) ), this, SLOT( onSetAnimation( int ) ) ); QObject::connect( ui->viewLayer, SIGNAL( valueChanged( int ) ), this, SLOT( onSetLayer( int ) ) ); QObject::connect( ui->viewAddon, SIGNAL( valueChanged( int ) ), this, SLOT( onSetAddon( int ) ) ); QObject::connect( ui->viewFloorPattern, SIGNAL( valueChanged( int ) ), this, SLOT( onSetFloorPattern( int ) ) ); QObject::connect( ui->viewDirectionE, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionEast( void ) ) ); QObject::connect( ui->viewDirectionN, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionNorth( void ) ) ); QObject::connect( ui->viewDirectionNE, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionNorthEast( void ) ) ); QObject::connect( ui->viewDirectionNW, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionNorthWest( void ) ) ); QObject::connect( ui->viewDirectionS, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionSouth( void ) ) ); QObject::connect( ui->viewDirectionSE, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionSouthEast( void ) ) ); QObject::connect( ui->viewDirectionSW, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionSouthWest( void ) ) ); QObject::connect( ui->viewDirectionW, SIGNAL( toggled( bool ) ), this, SLOT( onSetDirectionWest( void ) ) ); }