void build_gr_cum(const TRasterImageP &image, int cum[256]) { int lx, ly, wrap, true_lx, true_ly; int i, x, y; UCHAR *pix, *buffer; int histo[256], raster_is_savebox; get_virtual_buffer(image, &lx, &ly, &wrap, &buffer); for (i = 0; i < 256; i++) histo[i] = 0; for (y = 0; y < ly; y++) { pix = buffer + y * wrap; for (x = 0; x < lx; x++) histo[*pix++]++; } raster_is_savebox = 1; TRect saveBox = image->getSavebox(); if ((saveBox.getLx() > 0 && saveBox.getLx() < image->getRaster()->getLx()) || (saveBox.getLy() > 0 && saveBox.getLy() < image->getRaster()->getLy())) raster_is_savebox = 0; if (raster_is_savebox) { true_lx = saveBox.getLx() ? saveBox.getLx() : image->getRaster()->getLx(); true_ly = saveBox.getLy() ? saveBox.getLy() : image->getRaster()->getLy(); } else { true_lx = image->getRaster()->getLx(); true_ly = image->getRaster()->getLy(); } histo[255] += true_lx * true_ly - lx * ly; build_cum(histo, cum); }
// note: create Undo BEFORE binarizing. Undo is keeping a copy of the current raster TBinarizeUndo(TXshSimpleLevel *sl, const TFrameId &fid, bool alphaEnabled) : m_levelName(sl->getName()), m_fid(fid), m_alphaEnabled(alphaEnabled) { /* FIXME: clang でコンパイルできなかったのでキャストにしたがこのダウンキャスト本当に大丈夫か? */ TRasterImageP ri = (TRasterImageP)sl->getFrame(m_fid, false)->cloneImage(); m_rasId = QString("BinarizeUndo") + QString::number((uintptr_t) this); TImageCache::instance()->add(m_rasId, ri); m_rasSize = ri->getRaster()->getLx() * ri->getRaster()->getLy() * 4; }
TRect TRasterImageUtils::convertWorldToRaster(const TRectD &area, const TRasterImageP ri) { if (area.isEmpty()) return TRect(); if (!ri || !ri->getRaster()) return TRect(tfloor(area.x0), tfloor(area.y0), tfloor(area.x1) - 1, tfloor(area.y1) - 1); TRasterP ras = ri->getRaster(); TRectD rect(area + ras->getCenterD()); return TRect(tfloor(rect.x0), tfloor(rect.y0), tceil(rect.x1) - 1, tceil(rect.y1) - 1); }
TRectD TRasterImageUtils::convertRasterToWorld(const TRect &area, const TRasterImageP ri) { if (area.isEmpty()) return TRectD(); TRectD rect(area.x0, area.y0, area.x1 + 1, area.y1 + 1); if (ri && ri->getRaster()) rect = rect - ri->getRaster()->getCenterD(); return rect; }
void FullColorBrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) { m_brushPos = m_mousePos = pos; TRasterImageP ri = (TRasterImageP)getImage(true); if (!ri) return; if (m_points.size() != 1) { double maxThickness = m_thickness.getValue().second; double thickness = m_pressure.getValue() ? computeThickness(e.m_pressure, m_thickness) : maxThickness; double opacity = (m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity) : m_opacity.getValue().second) * 0.01; TPointD rasCenter = ri->getRaster()->getCenterD(); TThickPoint point(pos + rasCenter, thickness); m_points.push_back(point); int m = m_points.size(); vector<TThickPoint> points; points.push_back(m_points[m - 3]); points.push_back(m_points[m - 2]); points.push_back(m_points[m - 1]); TRect bbox = m_brush->getBoundFromPoints(points); updateWorkAndBackupRasters(bbox); m_tileSaver->save(bbox); m_brush->addArc(points[0], points[1], points[2], m_oldOpacity, opacity); m_brush->updateDrawing(ri->getRaster(), m_backUpRas, m_currentColor, bbox, m_opacity.getValue().second * 0.01); TRectD invalidateRect = ToolUtils::getBounds(points, maxThickness); invalidate(invalidateRect.enlarge(2) - rasCenter); m_strokeRect += bbox; m_lastRect.empty(); } if (m_brush) { delete m_brush; m_brush = 0; } m_workRaster->unlock(); if (m_tileSet->getTileCount() > 0) { delete m_tileSaver; TTool::Application *app = TTool::getApplication(); TXshLevel *level = app->getCurrentLevel()->getLevel(); TXshSimpleLevelP simLevel = level->getSimpleLevel(); TFrameId frameId = getCurrentFid(); TRasterP ras = ri->getRaster()->extract(m_strokeRect)->clone(); TUndoManager::manager()->add(new FullColorBrushUndo(m_tileSet, simLevel.getPointer(), frameId, m_isFrameCreated, ras, m_strokeRect.getP00())); } notifyImageChanged(); m_strokeRect.empty(); }
void undo() const { TXshSimpleLevel *sl = getLevel(); if (!sl) return; TRasterImageP ri = sl->getFrame(m_fid, true); if (!ri) return; TRasterImageP oldRaster = TImageCache::instance()->get(m_rasId, false); ri->getRaster()->copy(oldRaster->getRaster()); notify(sl); }
/*! Add to current trasformation matrix a \b delta traslation. */ void ImageViewer::panQt(const QPoint &delta) { if (delta == QPoint()) return; // stop panning when the image is at the edge of window QPoint delta_(delta.x(), delta.y()); TToonzImageP timg = (TToonzImageP)m_image; TRasterImageP rimg = (TRasterImageP)m_image; if (timg || rimg) { bool isXPlus = delta.x() > 0; bool isYPlus = delta.y() > 0; TDimension imgSize((timg) ? timg->getSize() : rimg->getRaster()->getSize()); int subSampling = (timg) ? timg->getSubsampling() : rimg->getSubsampling(); TPointD cornerPos = TPointD(imgSize.lx * ((isXPlus) ? -1 : 1), imgSize.ly * ((isYPlus) ? 1 : -1)) * (0.5 / (double)subSampling); cornerPos = m_viewAff * cornerPos; if ((cornerPos.x > 0) == isXPlus) delta_.setX(0); if ((cornerPos.y < 0) == isYPlus) delta_.setY(0); } setViewAff(TTranslation(delta_.x(), -delta_.y()) * m_viewAff); update(); }
void TRasterImageUtils::addGlobalNumbering(const TRasterImageP &ri, const std::wstring &sceneName, int globalIndex) { if (!ri) return; TRasterP raster = ri->getRaster(); int lx = raster->getLx(), ly = raster->getLy(); QColor greyOverlay(100, 100, 100, 140); QImage image = rasterToQImage(raster, true, false); QPainter p(&image); QFont numberingFont = QFont(); numberingFont.setPixelSize(ly * 0.04); numberingFont.setBold(true); p.setFont(numberingFont); QMatrix matrix; p.setMatrix(matrix.translate(0, ly).scale(1, -1), true); QFontMetrics fm = p.fontMetrics(); int fontHeight = fm.height(); int offset = fontHeight * 0.2; QString globalFrame = QString::number(globalIndex); while (globalFrame.size() < 4) globalFrame.push_front("0"); QString globalNumberingString = QString::fromStdWString(sceneName) + ": " + globalFrame; int globalNumberingWidth = fm.width(globalNumberingString); p.setPen(Qt::NoPen); p.setBrush(QColor(255, 255, 255, 255)); p.drawRect(offset, ly - offset - fontHeight, globalNumberingWidth + offset * 2, fontHeight); p.setBrush(greyOverlay); p.drawRect(offset, ly - offset - fontHeight, globalNumberingWidth + offset * 2, fontHeight); p.setPen(Qt::white); p.drawText(2 * offset, ly - 2 * offset, globalNumberingString); p.end(); }
TPixel32 StylePicker::pickColor(const TPointD &pos, double radius2) const { TToonzImageP ti = m_image; TRasterImageP ri = m_image; if (!!ri) // !!ti || !!ri) { TRasterP raster; //if(ti) // raster = ti->getRGBM(true); //else raster = ri->getRaster(); TPoint point = getRasterPoint(pos); if (!raster->getBounds().contains(point)) return TPixel32::Transparent; TRaster32P raster32 = raster; if (raster32) return raster32->pixels(point.y)[point.x]; TRasterGR8P rasterGR8 = raster; if (rasterGR8) return toPixel32(rasterGR8->pixels(point.y)[point.x]); } else if (TVectorImageP vi = m_image) { const TPalette *palette = m_palette.getPointer(); if (!palette) return TPixel32::Transparent; int styleId = pickStyleId(pos, radius2); if (0 <= styleId && styleId < palette->getStyleCount()) return palette->getStyle(styleId)->getAverageColor(); } return TPixel32::Transparent; }
void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect) { TRasterImageP ri = TImageP(getImage(false, 1)); if (!ri) return; TRasterP ras = ri->getRaster(); TRect _rect = rect * ras->getBounds(); TRect _lastRect = m_lastRect * ras->getBounds(); if (_rect.isEmpty()) return; if (m_lastRect.isEmpty()) { m_workRaster->extract(_rect)->clear(); m_backUpRas->extract(_rect)->copy(ras->extract(_rect)); return; } QList<TRect> rects = ToolUtils::splitRect(_rect, _lastRect); for (int i = 0; i < rects.size(); i++) { m_workRaster->extract(rects[i])->clear(); m_backUpRas->extract(rects[i])->copy(ras->extract(rects[i])); } }
int BinarizePopup::getSelectedFrames() { m_frames.clear(); TSelection *selection = TSelection::getCurrent(); TCellSelection *cellSelection; TFilmstripSelection *filmstripSelection; int count = 0; if ((cellSelection = dynamic_cast<TCellSelection *>(selection))) { std::set<TRasterImage *> images; int r0, c0, r1, c1; cellSelection->getSelectedCells(r0, c0, r1, c1); TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); int c, r; for (c = c0; c <= c1; c++) { for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TRasterImageP rasImage = cell.getImage(false); if (!rasImage || !rasImage->getRaster()) continue; Frames::value_type item(cell.getSimpleLevel(), cell.getFrameId()); Frames::iterator it; it = std::lower_bound(m_frames.begin(), m_frames.end(), item); if (it == m_frames.end() || *it != item) { m_frames.insert(it, item); count++; } } } } else if ((filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection))) { TXshSimpleLevel *sl = TApp::instance()->getCurrentLevel()->getSimpleLevel(); if (sl) { std::set<TFrameId> fids = filmstripSelection->getSelectedFids(); std::set<TFrameId>::iterator it; for (it = fids.begin(); it != fids.end(); ++it) { TRasterImageP rasImage = sl->getFrame(*it, false); if (!!rasImage && !!rasImage->getRaster()) { m_frames.push_back(std::make_pair(sl, *it)); count++; } } } } else { } m_frameIndex = 0; return count; }
void PlaneViewer::draw(TRasterImageP ri) { double dpiX, dpiY; ri->getDpi(dpiX, dpiY); if (dpiX == 0.0 || dpiY == 0.0) dpiX = dpiY = Stage::inch; draw(ri->getRaster(), dpiX, dpiY); }
void FullColorBrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { m_brushPos = m_mousePos = pos; TRasterImageP ri = (TRasterImageP)getImage(true); if (!ri) return; double maxThickness = m_thickness.getValue().second; double thickness = m_pressure.getValue() ? computeThickness(e.m_pressure, m_thickness) : maxThickness; double opacity = (m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity) : m_opacity.getValue().second) * 0.01; TDimension size = m_workRaster->getSize(); TPointD rasCenter = TPointD(size.lx * 0.5, size.ly * 0.5); TThickPoint point(pos + rasCenter, thickness); TThickPoint old = m_points.back(); if (norm2(point - old) < 4) return; TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5); m_points.push_back(mid); m_points.push_back(point); TRect bbox; int m = m_points.size(); TRectD invalidateRect; if (m == 3) { // ho appena cominciato. devo disegnare un segmento TThickPoint pa = m_points.front(); vector<TThickPoint> points; points.push_back(pa); points.push_back(mid); invalidateRect = ToolUtils::getBounds(points, maxThickness); bbox = m_brush->getBoundFromPoints(points); updateWorkAndBackupRasters(bbox + m_lastRect); m_tileSaver->save(bbox); m_brush->addArc(pa, (pa + mid) * 0.5, mid, m_oldOpacity, opacity); m_lastRect += bbox; } else { // caso generale: disegno un arco vector<TThickPoint> points; points.push_back(m_points[m - 4]); points.push_back(old); points.push_back(mid); invalidateRect = ToolUtils::getBounds(points, maxThickness); bbox = m_brush->getBoundFromPoints(points); updateWorkAndBackupRasters(bbox + m_lastRect); m_tileSaver->save(bbox); m_brush->addArc(m_points[m - 4], old, mid, m_oldOpacity, opacity); m_lastRect += bbox; } m_oldOpacity = opacity; m_brush->updateDrawing(ri->getRaster(), m_backUpRas, m_currentColor, bbox, m_opacity.getValue().second * 0.01); invalidate(invalidateRect.enlarge(2) - rasCenter); m_strokeRect += bbox; }
void RasterSelectionTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { if (m_setSaveboxTool && m_modifySavebox.getValue()) { m_setSaveboxTool->leftButtonDrag(pos); invalidate(); return; } if (m_dragTool) { m_dragTool->leftButtonDrag(pos, e); invalidate(); return; } TImageP image = getImage(true); TToonzImageP ti = (TToonzImageP)image; TRasterImageP ri = (TRasterImageP)image; if (!ti && !ri) return; if (m_selecting) { if (m_strokeSelectionType.getValue() == RECT_SELECTION) { TDimension imageSize; if (ti) imageSize = ti->getSize(); else if (ri) imageSize = ri->getRaster()->getSize(); TPointD p(imageSize.lx % 2 ? 0.5 : 0.0, imageSize.ly % 2 ? 0.5 : 0.0); TRectD rectD(tround(std::min(m_firstPos.x, pos.x) - p.x) + p.x, tround(std::min(m_firstPos.y, pos.y) - p.y) + p.y, tround(std::max(m_firstPos.x, pos.x) - p.x) + p.x, tround(std::max(m_firstPos.y, pos.y) - p.y) + p.y); m_selectingRect = rectD; m_bboxs.clear(); invalidate(); } else if (m_strokeSelectionType.getValue() == FREEHAND_SELECTION) freehandDrag(pos); return; } double pixelSize = getPixelSize(); TTool::Application *app = TTool::getApplication(); if (!app || m_justSelected || !m_selecting || tdistance2(pos, m_curPos) < 9.0 * pixelSize * pixelSize) return; m_curPos = pos; if (m_strokeSelectionType.getValue() == FREEHAND_SELECTION) freehandDrag(pos); else if (m_strokeSelectionType.getValue() == RECT_SELECTION) { bool selectOverlappingStroke = (m_firstPos.x > pos.x); TRectD rect(m_firstPos, pos); m_selectingRect = rect; invalidate(); } }
TRect TRasterImageUtils::addStroke(const TRasterImageP &ri, TStroke *stroke, TRectD clip, double opacity, bool doAntialiasing) { TStroke *s = new TStroke(*stroke); TPoint riCenter = ri->getRaster()->getCenter(); s->transform(TTranslation(riCenter.x, riCenter.y)); TRect rect = fastAddInkStroke(ri, s, clip, opacity, doAntialiasing); rect -= riCenter; delete s; return rect; }
void AdjustLevelsPopup::acquireRaster() { //Retrieve current selection TApp *app = TApp::instance(); TSelection *selection = app->getCurrentSelection()->getSelection(); TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection); TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection); //Retrieve the input raster m_inputRas = TRasterP(); if (cellSelection) { TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex()); TRasterImageP rasImage = cell.getImage(true); if (rasImage && rasImage->getRaster()) m_inputRas = rasImage->getRaster(); } else if (filmstripSelection) { TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true); if (rasImage && rasImage->getRaster()) m_inputRas = rasImage->getRaster(); } } if (m_inputRas) { m_threshold = m_inputRas->getLx() * m_inputRas->getLy() * m_thresholdD; m_okBtn->setEnabled(true); } else { m_inputRas = TRasterP(); m_okBtn->setEnabled(false); } //Build histograms m_histogram->setRaster(m_inputRas); //Update the corresponding processed image in the viewer updateProcessedImage(); }
void BrightnessAndContrastPopup::setCurrentSampleRaster() { TRasterP sampleRas; m_startRas = TRasterP(); 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_contrastField->getValue(), m_brightnessField->getValue()); m_viewer->raster() = sampleRas; m_viewer->update(); }
std::vector<TRect> TRasterImageUtils::paste(const TRasterImageP &ri, const TTileSetFullColor *tileSet) { std::vector<TRect> rects; TRasterP raster = ri->getRaster(); for (int i = 0; i < tileSet->getTileCount(); i++) { const TTileSetFullColor::Tile *tile = tileSet->getTile(i); TRasterP ras; tile->getRaster(ras); assert(ras); raster->copy(ras, tile->m_rasterBounds.getP00()); rects.push_back(tile->m_rasterBounds); } return rects; }
void FullColorBrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) { m_brushPos = m_mousePos = pos; Viewer *viewer = getViewer(); if (!viewer) return; TRasterImageP ri = (TRasterImageP)getImage(true); if (!ri) ri = (TRasterImageP)touchImage(); if (!ri) return; TRasterP ras = ri->getRaster(); TDimension dim = ras->getSize(); if (!(m_workRaster && m_backUpRas)) setWorkAndBackupImages(); m_workRaster->lock(); double maxThick = m_thickness.getValue().second; double thickness = m_pressure.getValue() ? computeThickness(e.m_pressure, m_thickness) : maxThick; double opacity = (m_pressure.getValue() ? computeThickness(e.m_pressure, m_opacity) : m_opacity.getValue().second) * 0.01; TPointD rasCenter = TPointD(dim.lx * 0.5, dim.ly * 0.5); TThickPoint point(pos + rasCenter, thickness); TPointD halfThick(maxThick * 0.5, maxThick * 0.5); TRectD invalidateRect(pos - halfThick, pos + halfThick); m_points.clear(); m_points.push_back(point); m_tileSet = new TTileSetFullColor(ras->getSize()); m_tileSaver = new TTileSaverFullColor(ras, m_tileSet); double hardness = m_hardness.getValue() * 0.01; m_brush = new BluredBrush(m_workRaster, maxThick, m_brushPad, hardness == 1.0); m_strokeRect = m_brush->getBoundFromPoints(m_points); updateWorkAndBackupRasters(m_strokeRect); m_tileSaver->save(m_strokeRect); m_brush->addPoint(point, opacity); m_brush->updateDrawing(ras, m_backUpRas, m_currentColor, m_strokeRect, m_opacity.getValue().second * 0.01); m_oldOpacity = opacity; m_lastRect = m_strokeRect; invalidate(invalidateRect.enlarge(2)); }
void redo() const { TXshSimpleLevel *sl = getLevel(); if (!sl) return; TRasterImageP ri = sl->getFrame(m_fid, true); if (!ri) return; TRaster32P ras = ri->getRaster(); if (!ras) return; TBinarizer binarizer; binarizer.enableAlpha(m_alphaEnabled); binarizer.process(ras); notify(sl); }
TRect TRasterImageUtils::eraseRect(const TRasterImageP &ri, const TRectD &area) { TRasterP ras = ri->getRaster(); TRect rect = convertWorldToRaster(area, ri) * ras->getBounds(); if (rect.isEmpty()) return rect; ras->lock(); TRasterP workRas = ras->extract(rect); if (workRas->getPixelSize() == 4) workRas->clear(); else { TRasterGR8P rasGR8(workRas); if (rasGR8) rasGR8->fill(TPixelGR8::White); } ras->unlock(); return rect; }
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); }
static void get_virtual_buffer(const TRasterImageP &image, int *p_lx, int *p_ly, int *p_wrap, UCHAR **p_buffer) { int x0, y0, x1, y1; int x_margin, y_margin; int lx, ly, wrap; UCHAR *buffer; TRasterGR8P ras8(image->getRaster()); assert(ras8); double xdpi, ydpi; image->getDpi(xdpi, ydpi); /* BORDO DI MEZZO CENTIMETRO */ x_margin = troundp(mmToPixel(5.0, xdpi)); y_margin = troundp(mmToPixel(5.0, ydpi)); x0 = Window_x0 + x_margin; y0 = Window_y0 + y_margin; x1 = Window_x1 - x_margin; y1 = Window_y1 - y_margin; notLessThan(x0 + 9, x1); notLessThan(y0 + 9, y1); notLessThan(0, x0); notMoreThan(ras8->getLx() - 1, x0); notLessThan(0, y0); notMoreThan(ras8->getLy() - 1, y0); notLessThan(0, x1); notMoreThan(ras8->getLx() - 1, x1); notLessThan(0, y1); notMoreThan(ras8->getLy() - 1, y1); lx = x1 - x0 + 1; ly = y1 - y0 + 1; wrap = ras8->getWrap(); buffer = (UCHAR *)ras8->getRawData() + x0 + y0 * wrap; *p_lx = lx; *p_ly = ly; *p_wrap = wrap; *p_buffer = buffer; }
void FullColorBrushTool::setWorkAndBackupImages() { TRasterImageP ri = (TRasterImageP)getImage(false, 1); if (!ri) return; TRasterP ras = ri->getRaster(); TDimension dim = ras->getSize(); if (!m_workRaster || m_workRaster->getLx() > dim.lx || m_workRaster->getLy() > dim.ly) m_workRaster = TRaster32P(dim); if (!m_backUpRas || m_backUpRas->getLx() > dim.lx || m_backUpRas->getLy() > dim.ly || m_backUpRas->getPixelSize() != ras->getPixelSize()) m_backUpRas = ras->create(dim.lx, dim.ly); m_strokeRect.empty(); m_lastRect.empty(); }
void TImageReader::load(const TRasterP &ras, const TPoint &pos, int shrinkX, int shrinkY) { TImageP srcImage = load(); TRasterImageP srcRasImage = srcImage; TRaster32P srcRaster = srcRasImage->getRaster(); /* TRaster32P clippedRas = srcRaster->extractT (shrinkX*pos.x, shrinkY*pos.y, (pos.x + ras->getLx()) * shrinkX - 1, (pos.y + ras->getLy()) * shrinkY - 1); if (shrinkX != 1 || shrinkY != 1) { TRaster32P ras32 = ras; if (ras32) ras32->fill(TPixel32::Transparent); TRop::resample(ras, clippedRas, TScale(1./shrinkX, 1./shrinkY), TRop::ClosestPixel); } else*/ ras->copy(srcRaster); }
void BinarizePopup::apply() { if (getSelectedFrames() <= 0) { DVGui::error(tr("No raster frames selected")); return; } DVGui::ProgressDialog pd(tr("Binarizing images"), tr("Cancel"), 0, (int)m_frames.size(), 0); pd.show(); qApp->processEvents(); TBinarizer binarizer; binarizer.enableAlpha(!!m_alphaChk->checkState()); TUndoManager::manager()->beginBlock(); int count = 0; Frames::iterator it; for (it = m_frames.begin(); it != m_frames.end(); ++it) { TXshSimpleLevel *sl = it->first; if (!!m_alphaChk->checkState()) sl->getProperties()->setHasAlpha(true); TFrameId fid = it->second; TBinarizeUndo *undo = new TBinarizeUndo(sl, fid, binarizer.isAlphaEnabled()); TUndoManager::manager()->add(undo); TRasterImageP ri = sl->getFrame(fid, true); if (!ri) continue; // should never happen TRaster32P ras32 = ri->getRaster(); if (!ras32) continue; // not yet handled binarizer.process(ras32); pd.setValue(count++); qApp->processEvents(); sl->touchFrame(fid); sl->setDirtyFlag(true); IconGenerator::instance()->invalidate(sl, fid); } TUndoManager::manager()->endBlock(); TApp::instance()->getCurrentLevel()->notifyLevelChange(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void redo() const { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsheet->getCell(m_r, m_c); TRasterImageP rasImage = (TRasterImageP)cell.getImage(true); if (!rasImage) return; TRasterP ras = rasImage->getRaster(); if (!ras) return; onChange(ras, m_contrast, m_brightness); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(false); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); if (m_isLastInBlock) { TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); } }
void BinarizePopup::fetchSample() { TApp *app = TApp::instance(); TImageP img; if (app->getCurrentFrame()->isEditingLevel()) { TXshLevel *xshLevel = app->getCurrentLevel()->getLevel(); if (xshLevel && xshLevel->getSimpleLevel()) { TXshSimpleLevel *sl = xshLevel->getSimpleLevel(); img = sl->getFrame(app->getCurrentFrame()->getFid(), false); } } else { TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrame(), app->getCurrentColumn()->getColumnIndex()); img = cell.getImage(false); } TRasterImageP ri = img; if (ri) { setSample(ri->getRaster()); } else { setSample(TRasterP()); } }
void AdjustLevelsUndo::redo() const { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsheet->getCell(m_r, m_c); TRasterImageP rasImage = (TRasterImageP)cell.getImage(true); if (!rasImage) return; TRasterP ras = rasImage->getRaster(); if (!ras) return; TRop::rgbmAdjust(ras, ras, m_in0, m_in1, m_out0, m_out1); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); if (m_isLastInBlock) TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void PreviewToggleCommand::postProcess() { TApp *app = TApp::instance(); CleanupSettingsModel *model = CleanupSettingsModel::instance(); TXshSimpleLevel *sl; TFrameId fid; model->getCleanupFrame(sl, fid); assert(sl); if (!sl) return; // Retrieve transformed image TRasterImageP transformed; { TRasterImageP original; TAffine transform; model->getPreviewData(original, transformed, transform); if (!transformed) return; } // Perform post-processing TRasterImageP preview( TCleanupper::instance()->processColors(transformed->getRaster())); TPointD dpi; transformed->getDpi(dpi.x, dpi.y); preview->setDpi(dpi.x, dpi.y); transformed = TRasterImageP(); // Substitute current frame image with previewed one sl->setFrame(fid, preview); TApp::instance()->getCurrentLevel()->notifyLevelChange(); }