void FullColorAreaFiller::rectFill(const TRect &rect, const FillParameters ¶ms, bool onlyUnfilled) { TRect bbox = m_ras->getBounds(); TRect r = rect * bbox; if (r.isEmpty()) return; TRaster32P workRas = m_ras->extract(r); TRaster32P copy = workRas->clone(); TPixel32 color = params.m_palette->getStyle(params.m_styleId)->getMainColor(); // Fillo tutto il quadaratino con color int x, y; for (y = 0; y < workRas->getLy(); y++) { TPixel32 *line = workRas->pixels(y); for (x = 0; x < workRas->getLx(); x++) *(line + x) = overPix(color, workRas->pixels(y)[x]); } FillParameters paramsApp = params; TPixel32 refColor; for (y = 0; y < workRas->getLy(); y++) { paramsApp.m_p = TPoint(0, y); if (y == 0 || refColor != workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]) { fill(workRas, copy, paramsApp); refColor = workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]; } } for (y = 0; y < workRas->getLy(); y++) { paramsApp.m_p = TPoint(workRas->getLx() - 1, y); if (y == 0 || refColor != workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]) { fill(workRas, copy, paramsApp); refColor = workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]; } } for (x = 0; x < workRas->getLx(); x++) { paramsApp.m_p = TPoint(x, 0); if (x == 0 || refColor != workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]) { fill(workRas, copy, paramsApp); refColor = workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]; } } for (x = 0; x < workRas->getLx(); x++) { paramsApp.m_p = TPoint(x, workRas->getLy() - 1); if (x == 0 || refColor != workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]) { fill(workRas, copy, paramsApp); refColor = workRas->pixels(paramsApp.m_p.y)[paramsApp.m_p.x]; } } }
TImageP ImageFiller::build(int imFlags, void *extData) { assert(imFlags == ImageManager::none); // Fetch image assert(extData); ImageLoader::BuildExtData *data = (ImageLoader::BuildExtData *)extData; assert(data->m_subs == 0); const std::string &srcImgId = data->m_sl->getImageId(data->m_fid); TImageP img = ImageManager::instance()->getImage(srcImgId, imFlags, extData); if (img) { TRasterImageP ri = img; if (ri) { TRaster32P ras = ri->getRaster(); if (ras) { TRaster32P newRas = ras->clone(); FullColorAreaFiller filler(newRas); TPaletteP palette = new TPalette(); int styleId = palette->getPage(0)->addStyle(TPixel32::White); FillParameters params; params.m_palette = palette.getPointer(); params.m_styleId = styleId; params.m_minFillDepth = 0; params.m_maxFillDepth = 15; filler.rectFill(newRas->getBounds(), params, false); TRasterImageP ri = TRasterImageP(newRas); return ri; } } } // Error case: return a dummy image (is it really required?) TRaster32P ras(10, 10); ras->fill(TPixel32(127, 0, 127, 127)); return TRasterImageP(ras); }
void LinesFadePopup::setCurrentSampleRaster() { TRaster32P sampleRas; m_startRas = TRaster32P(); TSelection *selection = TApp::instance()->getCurrentSelection()->getSelection(); TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection); TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection); if (cellSelection) { TApp *app = TApp::instance(); TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex()); TRasterImageP rasImage = cell.getImage(true); if (rasImage && rasImage->getRaster()) sampleRas = rasImage->getRaster()->clone(); } else if (filmstripSelection) { TApp *app = TApp::instance(); TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true); if (rasImage && rasImage->getRaster()) sampleRas = rasImage->getRaster()->clone(); } } if (!sampleRas) { m_viewer->raster() = TRasterP(); m_viewer->update(); m_okBtn->setEnabled(false); return; } m_okBtn->setEnabled(true); m_startRas = sampleRas->clone(); onChange(m_startRas, sampleRas, m_linesColorField->getColor(), m_intensity->getValue()); m_viewer->raster() = sampleRas; m_viewer->update(); }
void LinesFadePopup::apply() { TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent()); TPixel32 color = m_linesColorField->getColor(); int intensity = m_intensity->getValue(); if (cellSelection) { std::set<TRasterImage *> images; int r0, c0, r1, c1; cellSelection->getSelectedCells(r0, c0, r1, c1); TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); bool oneImageChanged = false; int c, r; TUndoManager::manager()->beginBlock(); for (c = c0; c <= c1; c++) for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TRasterImageP rasImage = (TRasterImageP)cell.getImage(true); if (!rasImage) continue; if (images.find(rasImage.getPointer()) != images.end()) continue; TRaster32P ras = rasImage->getRaster(); if (!ras) continue; images.insert(rasImage.getPointer()); TUndoManager::manager()->add(new TLineFadeUndo(color, intensity, r, c, ras->clone())); oneImageChanged = true; onChange(ras, ras, color, intensity); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); } TUndoManager::manager()->endBlock(); images.clear(); if (oneImageChanged) { close(); return; } } TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent()); if (filmstripSelection) { TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { std::set<TFrameId> fids = filmstripSelection->getSelectedFids(); bool oneImageChanged = false; for (auto const& fid : fids) { TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(fid, true); ; if (!rasImage) continue; TRaster32P ras = rasImage->getRaster(); if (!ras) continue; oneImageChanged = true; onChange(ras, ras, color, intensity); simpleLevel->touchFrame(fid); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, fid); } if (oneImageChanged) { close(); return; } } } DVGui::error(QObject::tr("The current selection is invalid.")); return; }