void PlaneViewer::draw(TVectorImageP vi) { TRectD bbox(vi->getBBox()); TRect bboxI(tfloor(bbox.x0), tfloor(bbox.y0), tceil(bbox.x1) - 1, tceil(bbox.y1) - 1); TVectorRenderData rd(TAffine(), bboxI, vi->getPalette(), 0, true, true); tglDraw(rd, vi.getPointer()); }
void SkeletonTool::drawLevelBoundingBox(int frame, int columnIndex) { TAffine affine = getCurrentColumnMatrix(); TXshCell cell = getXsheet()->getCell(frame, columnIndex); TImageP image = cell.getImage(false); TToonzImageP ti = image; TVectorImageP vi = image; glPushMatrix(); if (affine != getMatrix()) tglMultMatrix(getMatrix().inv() * affine); if (ti) { TPointD dpiScale = getViewer()->getDpiScale(); glScaled(dpiScale.x, dpiScale.y, 1); TRectD bbox = ToonzImageUtils::convertRasterToWorld(convert(ti->getBBox()), ti); ToolUtils::drawRect(bbox * ti->getSubsampling(), TPixel32(200, 200, 200), 0x5555); } if (vi) { TRectD bbox = vi->getBBox(); ToolUtils::drawRect(bbox, TPixel32(200, 200, 200), 0x5555); } glPopMatrix(); }
void SkeletonTool::getImageBoundingBox(TRectD &bbox, TAffine &aff, int frame, int columnIndex) { TAffine columnAff = getXsheet()->getPlacement(TStageObjectId::ColumnId(columnIndex), frame); // TAffine affine = getColumnMatrix(columnIndex); TXshCell cell = getXsheet()->getCell(frame, columnIndex); TImageP image = cell.getImage(false); TToonzImageP ti = image; TVectorImageP vi = image; if (ti) { TAffine imageDpiAff; if (cell.m_level->getSimpleLevel()) imageDpiAff = getDpiAffine(cell.m_level->getSimpleLevel(), cell.m_frameId, true); aff = columnAff * imageDpiAff; bbox = ToonzImageUtils::convertRasterToWorld(convert(ti->getBBox()), ti) * ti->getSubsampling(); ToolUtils::drawRect(bbox * ti->getSubsampling(), TPixel32(200, 200, 200), 0x5555); } else if (vi) { bbox = vi->getBBox(); aff = columnAff; } else { bbox = TRectD(); aff = TAffine(); } }
void TColorStyle::makeIcon(const TDimension &d) { checkErrorsByGL; TColorStyle *style = this->clone(); checkErrorsByGL; TPaletteP tmpPalette = new TPalette(); checkErrorsByGL; int id = tmpPalette->addStyle(style); checkErrorsByGL; int contextLx = pow(2.0, tceil(log((double)d.lx) / log(2.0))); int contextLy = pow(2.0, tceil(log((double)d.ly) / log(2.0))); TDimension dim(contextLx, contextLy); TOfflineGL *glContext = TOfflineGL::getStock(dim); checkErrorsByGL; glContext->clear(TPixel32::White); checkErrorsByGL; TVectorImageP img = new TVectorImage; checkErrorsByGL; img->setPalette(tmpPalette.getPointer()); checkErrorsByGL; std::vector<TThickPoint> points(3); if (isRegionStyle() && !isStrokeStyle()) { points[0] = TThickPoint(-55, -50, 1); points[1] = TThickPoint(0, -60, 1); points[2] = TThickPoint(55, -50, 1); TStroke *stroke1 = new TStroke(points); img->addStroke(stroke1); points[0] = TThickPoint(50, -55, 1); points[1] = TThickPoint(60, 0, 1); points[2] = TThickPoint(50, 55, 1); TStroke *stroke2 = new TStroke(points); img->addStroke(stroke2); points[0] = TThickPoint(55, 50, 1); points[1] = TThickPoint(0, 60, 1); points[2] = TThickPoint(-55, 50, 1); TStroke *stroke3 = new TStroke(points); img->addStroke(stroke3); points[0] = TThickPoint(-50, 55, 1); points[1] = TThickPoint(-60, 0, 1); points[2] = TThickPoint(-50, -55, 1); TStroke *stroke4 = new TStroke(points); img->addStroke(stroke4); img->fill(TPointD(0, 0), id); } else if (isStrokeStyle() && !isRegionStyle()) { double rasX05 = d.lx * 0.5; double rasY05 = d.ly * 0.5; points[0] = TThickPoint(-rasX05, -rasY05, 7); points[1] = TThickPoint(0, -rasY05, 9); points[2] = TThickPoint(rasX05, rasY05, 12); TStroke *stroke1 = new TStroke(points); stroke1->setStyle(id); img->addStroke(stroke1); points.clear(); } else if (!isRasterStyle()) { assert(isStrokeStyle() && isRegionStyle()); points[0] = TThickPoint(-60, -30, 0.5); points[1] = TThickPoint(0, -30, 0.5); points[2] = TThickPoint(60, -30, 0.5); TStroke *stroke1 = new TStroke(points); stroke1->setStyle(id); img->addStroke(stroke1); points[0] = TThickPoint(60, -30, 0.5); points[1] = TThickPoint(60, 0, 0.5); points[2] = TThickPoint(60, 30, 0.5); TStroke *stroke2 = new TStroke(points); stroke2->setStyle(id); img->addStroke(stroke2); points[0] = TThickPoint(60, 30, 0.5); points[1] = TThickPoint(0, 30, 0.5); points[2] = TThickPoint(-60, 30, 0.5); TStroke *stroke3 = new TStroke(points); stroke3->setStyle(id); img->addStroke(stroke3); points[0] = TThickPoint(-60, 30, 0.5); points[1] = TThickPoint(-60, 0, 0.5); points[2] = TThickPoint(-60, -30, 0.5); TStroke *stroke4 = new TStroke(points); stroke4->setStyle(id); img->addStroke(stroke4); img->fill(TPointD(0, 0), id); } TRectD bbox = img->getBBox(); checkErrorsByGL; bbox = bbox.enlarge(TDimensionD(-10, -10)); checkErrorsByGL; double scx = 0.9 * d.lx / bbox.getLx(); double scy = 0.9 * d.ly / bbox.getLy(); double sc = std::min(scx, scy); double dx = (d.lx - bbox.getLx() * sc) * 0.5; double dy = (d.ly - bbox.getLy() * sc) * 0.5; TAffine aff = TScale(scx, scy) * TTranslation(-bbox.getP00() + TPointD(dx, dy)); checkErrorsByGL; if (isRegionStyle() && !isStrokeStyle()) aff = aff * TTranslation(-10, -10); checkErrorsByGL; const TVectorRenderData rd(aff, TRect(), tmpPalette.getPointer(), 0, true); checkErrorsByGL; glContext->draw(img, rd); checkErrorsByGL; TRect rect(d); if (!m_icon || m_icon->getSize() != d) { checkErrorsByGL; m_icon = glContext->getRaster()->extract(rect)->clone(); } else { checkErrorsByGL; m_icon->copy(glContext->getRaster()->extract(rect)); } }
TImageP ImageRasterizer::build(int imFlags, void *extData) { assert(!(imFlags & ~(ImageManager::dontPutInCache | ImageManager::forceRebuild))); TDimension d(10, 10); TPoint off(0, 0); // Fetch image assert(extData); ImageLoader::BuildExtData *data = (ImageLoader::BuildExtData *)extData; const std::string &srcImgId = data->m_sl->getImageId(data->m_fid); TImageP img = ImageManager::instance()->getImage(srcImgId, imFlags, extData); if (img) { TVectorImageP vi = img; if (vi) { TRectD bbox = vi->getBBox(); d = TDimension(tceil(bbox.getLx()) + 1, tceil(bbox.getLy()) + 1); off = TPoint((int)bbox.x0, (int)bbox.y0); TPalette *vpalette = vi->getPalette(); TVectorRenderData rd(TTranslation(-off.x, -off.y), TRect(TPoint(0, 0), d), vpalette, 0, true, true); TGlContext oldContext = tglGetCurrentContext(); // this is too slow. { QSurfaceFormat format; format.setProfile(QSurfaceFormat::CompatibilityProfile); TRaster32P ras(d); glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_MODELVIEW), glPushMatrix(); glMatrixMode(GL_PROJECTION), glPushMatrix(); { std::unique_ptr<QOpenGLFramebufferObject> fb(new QOpenGLFramebufferObject(d.lx, d.ly)); fb->bind(); assert(glGetError() == 0); glViewport(0, 0, d.lx, d.ly); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, d.lx, 0, d.ly); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.375, 0.375, 0.0); assert(glGetError() == 0); tglDraw(rd, vi.getPointer()); assert(glGetError() == 0); assert(glGetError() == 0); glFlush(); assert(glGetError() == 0); QImage img = fb->toImage().scaled(QSize(d.lx, d.ly), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); int wrap = ras->getLx() * sizeof(TPixel32); uchar *srcPix = img.bits(); uchar *dstPix = ras->getRawData() + wrap * (d.ly - 1); for (int y = 0; y < d.ly; y++) { memcpy(dstPix, srcPix, wrap); dstPix -= wrap; srcPix += wrap; } fb->release(); } glMatrixMode(GL_MODELVIEW), glPopMatrix(); glMatrixMode(GL_PROJECTION), glPopMatrix(); glPopAttrib(); tglMakeCurrent(oldContext); TRasterImageP ri = TRasterImageP(ras); ri->setOffset(off + ras->getCenter()); return ri; } } } // Error case: return a dummy image (is it really required?) TRaster32P ras(d); ras->fill(TPixel32(127, 0, 127, 127)); return TRasterImageP(ras); }