Ejemplo n.º 1
0
	void updateLevel()
	{
		TTool::Application *app = TTool::getApplication();
		if (!app->getCurrentLevel()->getLevel())
			return;
		TXshSimpleLevelP xl = app->getCurrentLevel()->getLevel()->getSimpleLevel();
		if (app->getCurrentFrame()->getFrameType() != TFrameHandle::LevelFrame)
			return;

		TFrameId fid = app->getCurrentFrame()->getFid();
		TVectorImageP src = xl->getFrame(fid, true);
		int count = src->getStrokeCount();

		for (int i = 1; i < 10; i++) {
			++fid;
			if (!xl->isFid(fid)) {
				TVectorImageP vi = new TVectorImage();
				xl->setFrame(fid, vi);
			}
			TVectorImageP vi = xl->getFrame(fid, true);
			TVectorImageP dst = src->clone();
			deform(dst.getPointer(), src.getPointer(), (double)i / (double)9);
			count = dst->getStrokeCount();
			vi->mergeImage(dst, TAffine());
			app->getCurrentTool()->getTool()->notifyImageChanged(fid);
		}
	}
Ejemplo n.º 2
0
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());
}
Ejemplo n.º 3
0
void ImagePainter::paintImage(const TImageP &image, const TDimension &imageSize,
                              const TDimension &viewerSize, const TAffine &aff,
                              const VisualSettings &visualSettings,
                              const CompareSettings &compareSettings,
                              const TRect &loadbox) {
  glDisable(GL_DEPTH_TEST);

  if (visualSettings.m_drawExternalBG) {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
  }

  GLenum error = glGetError();
  // assert(error==GL_NO_ERROR);
  if (error != GL_NO_ERROR) {
    printf("ImagePainter::paintImage() gl_error:%d\n", error);
  }

  if (!image) return;

  TRasterImageP rimg = (TRasterImageP)image;
  TVectorImageP vimg = (TVectorImageP)image;
  TToonzImageP timg  = (TToonzImageP)image;

  TRect clipRect(viewerSize);
  clipRect -= TPoint(viewerSize.lx * 0.5, viewerSize.ly * 0.5);
  Painter painter(viewerSize, imageSize, aff, image->getPalette(),
                  visualSettings);

  if (rimg)
    painter.onRasterImage(rimg.getPointer());
  else if (vimg)
    painter.onVectorImage(vimg.getPointer());
  else if (timg)
    painter.onToonzImage(timg.getPointer());

  if (visualSettings.m_blankColor != TPixel::Transparent) {
    painter.drawBlank();
    return;
  }

  // if I have a color filter applied using a glmask, , drawing of images must
  // be done on black bg!
  if (!vimg)
    painter.flushRasterImages(
        loadbox, visualSettings.m_doCompare ? compareSettings.m_compareX
                                            : DefaultCompareValue,
        visualSettings.m_doCompare ? compareSettings.m_compareY
                                   : DefaultCompareValue,
        compareSettings.m_swapCompared);

  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

  if (visualSettings.m_doCompare)
    drawCompareLines(viewerSize, compareSettings.m_compareX,
                     compareSettings.m_compareY);
}
Ejemplo n.º 4
0
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);
}