bool exportEntry() { wxFileName fn(appPath(entry->getName(), DIR_TEMP)); fn.SetExt("png"); // Create image from entry SImage image; if (!Misc::loadImageFromEntry(&image, entry)) { Global::error = "Could not read graphic"; return false; } // Set export info gfx_format = image.getFormat()->getId(); offsets = image.offset(); palette.copyPalette(theMainWindow->getPaletteChooser()->getSelectedPalette(entry)); // Write png data MemChunk png; SIFormat* fmt_png = SIFormat::getFormat("png"); if (!fmt_png->saveImage(image, png, &palette)) { Global::error = "Error converting to png"; return false; } // Export file and start monitoring if successful filename = fn.GetFullPath(); if (png.exportFile(filename)) { file_modified = wxFileModificationTime(filename); Start(1000); return true; } return false; }
/* GfxEntryPanel::saveEntry * Saves any changes to the entry *******************************************************************/ bool GfxEntryPanel::saveEntry() { // Write new image data if modified bool ok = true; if (image_data_modified) { SImage* image = getImage(); SIFormat* format = image->getFormat(); string error = ""; ok = false; int writable = format->canWrite(*image); if (format == SIFormat::unknownFormat()) error = "Image is of unknown format"; else if (writable == SIFormat::NOTWRITABLE) error = S_FMT("Writing unsupported for format \"%s\"", format->getName()); else { // Convert image if necessary (using default options) if (writable == SIFormat::CONVERTIBLE) { format->convertWritable(*image, SIFormat::convert_options_t()); wxLogMessage("Image converted for writing"); } if (format->saveImage(*image, entry->getMCData(), gfx_canvas->getPalette())) ok = true; else error = "Error writing image"; } if (ok) { // Set modified entry->setState(1); // Re-detect type EntryType* oldtype = entry->getType(); EntryType::detectEntryType(entry); // Update extension if type changed if (oldtype != entry->getType()) entry->setExtensionByType(); } else wxMessageBox(wxString("Cannot save changes to image: ") + error, "Error", wxICON_ERROR); } // Otherwise just set offsets else EntryOperations::setGfxOffsets(entry, spin_xoffset->GetValue(), spin_yoffset->GetValue()); // Apply alPh/tRNS options if (entry->getType()->getFormat() == "img_png") { bool alph = EntryOperations::getalPhChunk(entry); bool trns = EntryOperations::gettRNSChunk(entry); if (alph != menu_custom->IsChecked(theApp->getAction("pgfx_alph")->getWxId())) EntryOperations::modifyalPhChunk(entry, !alph); if (trns != menu_custom->IsChecked(theApp->getAction("pgfx_trns")->getWxId())) EntryOperations::modifytRNSChunk(entry, !trns); } if (ok) setModified(false); return ok; }