Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/imagepainter.h"
Toshihiro Shimizu 890ddd
#include "toonz/glrasterpainter.h"
Toshihiro Shimizu 890ddd
#include "trastercm.h"
Toshihiro Shimizu 890ddd
#include "tropcm.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tvectorgl.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/fill.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ImagePainter;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookWhiteBgToggle("FlipBookWhiteBgToggle", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookBlackBgToggle("FlipBookBlackBgToggle", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookCheckBgToggle("FlipBookCheckBgToggle", 0);
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P keepChannels(const TRasterP &rin, TPalette *palette, UCHAR channel)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P rout(rin->getSize());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if ((TRasterCM32P)rin)
Toshihiro Shimizu 890ddd
		TRop::convert(rout, (TRasterCM32P)rin, TPaletteP(palette));
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		TRop::copy(rout, rin);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPixel32 *pix = (TPixel32 *)rout->getRawData();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(channel & TRop::MChan);
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < rout->getLx() * rout->getLy(); i++, pix++) {
Toshihiro Shimizu 890ddd
		if (!(channel & TRop::RChan))
Toshihiro Shimizu 890ddd
			pix->r = 0;
Toshihiro Shimizu 890ddd
		if (!(channel & TRop::GChan))
Toshihiro Shimizu 890ddd
			pix->g = 0;
Toshihiro Shimizu 890ddd
		if (!(channel & TRop::BChan))
Toshihiro Shimizu 890ddd
			pix->b = 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return rout;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline void quickput(const TRasterP &rout, const TRasterP &rin, const TPaletteP &palette, const TAffine &aff, bool useChecks)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (TRasterCM32P srcCM32 = rin) {
Toshihiro Shimizu 890ddd
		if (useChecks) {
Toshihiro Shimizu 890ddd
			bool inksOnly = false;
Toshihiro Shimizu 890ddd
			TPixel32 colorscale = TPixel32(0, 0, 0, 255);
Toshihiro Shimizu 890ddd
			int tc = ToonzCheck::instance()->getChecks();
Toshihiro Shimizu 890ddd
			int index = ToonzCheck::instance()->getColorIndex();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (tc & ToonzCheck::eGap) {
Toshihiro Shimizu 890ddd
				srcCM32 = srcCM32->clone();
Toshihiro Shimizu 890ddd
				AreaFiller(srcCM32).rectFill(srcCM32->getBounds(), 1, true, true, false);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (tc == 0 || tc == ToonzCheck::eBlackBg)
Toshihiro Shimizu 890ddd
				TRop::quickPut(rout, srcCM32, palette, aff, colorscale, inksOnly);
Toshihiro Shimizu 890ddd
			else {
Toshihiro Shimizu 890ddd
				TRop::CmappedQuickputSettings settings;
Toshihiro Shimizu 890ddd
				settings.m_globalColorScale = colorscale;
Toshihiro Shimizu 890ddd
				settings.m_inksOnly = inksOnly;
Toshihiro Shimizu 890ddd
				settings.m_transparencyCheck = tc & (ToonzCheck::eTransparency | ToonzCheck::eGap);
Toshihiro Shimizu 890ddd
				settings.m_blackBgCheck = tc & ToonzCheck::eBlackBg;
Toshihiro Shimizu 890ddd
				settings.m_inkIndex = tc & ToonzCheck::eInk ? index : (tc & ToonzCheck::eInk1 ? 1 : -1);
Toshihiro Shimizu 890ddd
				settings.m_paintIndex = tc & ToonzCheck::ePaint ? index : -1;
Toshihiro Shimizu 890ddd
				Preferences::instance()->getTranspCheckData(settings.m_transpCheckBg,
Toshihiro Shimizu 890ddd
															settings.m_transpCheckInk,
Toshihiro Shimizu 890ddd
															settings.m_transpCheckPaint);
Toshihiro Shimizu 890ddd
				TRop::quickPut(rout, srcCM32, palette, aff, settings);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			srcCM32 = TRasterCM32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			TRop::quickPut(rout, rin, palette, aff);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		TRop::quickPut(rout, rin, aff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPixel32 *getBuffer(const TRect &rect)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	static std::vector<char> buffer;</char>
Toshihiro Shimizu 890ddd
	int size = rect.getLx() * rect.getLy() * 4;
Toshihiro Shimizu 890ddd
	if (size > (int)buffer.size())
Toshihiro Shimizu 890ddd
		buffer.resize(size);
Toshihiro Shimizu 890ddd
	return (TPixel32 *)&buffer[0];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P getCheckBoard(const TRect &rect, const TAffine &aff, TSceneProperties *sprop)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double scale = sqrt(fabs(aff.det()));
Toshihiro Shimizu 890ddd
	TPixel32 col1, col2;
Toshihiro Shimizu 890ddd
	Preferences::instance()->getChessboardColors(col1, col2);
Toshihiro Shimizu 890ddd
	TRaster32P ras(rect.getLx(), rect.getLy(), rect.getLx(), getBuffer(rect));
Toshihiro Shimizu 890ddd
	TRop::checkBoard(ras, col1, col2, TDimensionD(50 * scale, 50 * scale), TPointD(-aff.a13, -aff.a23));
Toshihiro Shimizu 890ddd
	return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void drawCompareLines(const TDimension &dim, double compareX, double compareY)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
	glLoadIdentity();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glColor3d(0.0, 0.0, 0.0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glBegin(GL_LINES);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx * compareX - 1, 0);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx * compareX - 1, dim.ly - 1);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx * compareX + 1, 0);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx * compareX + 1, dim.ly - 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glVertex2d(0, dim.ly * compareY - 1);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx - 1, dim.ly * compareY - 1);
Toshihiro Shimizu 890ddd
	glVertex2d(0, dim.ly * compareY + 1);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx - 1, dim.ly * compareY + 1);
Toshihiro Shimizu 890ddd
	glEnd();
Toshihiro Shimizu 890ddd
	glColor3d(1.0, 0.0, 0.0);
Toshihiro Shimizu 890ddd
	glBegin(GL_LINES);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx * compareX, 0);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx * compareX, dim.ly - 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glVertex2d(0, dim.ly * compareY);
Toshihiro Shimizu 890ddd
	glVertex2d(dim.lx - 1, dim.ly * compareY);
Toshihiro Shimizu 890ddd
	glEnd();
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Painter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDimension m_dim;
Toshihiro Shimizu 890ddd
	TDimension m_imageSize;
Toshihiro Shimizu 890ddd
	TAffine m_aff;
Toshihiro Shimizu 890ddd
	TAffine m_finalAff;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *m_palette;
Toshihiro Shimizu 890ddd
	TRectD m_bbox;
Toshihiro Shimizu 890ddd
	TRasterP m_raster;
Toshihiro Shimizu 890ddd
	bool m_useTexture;
Toshihiro Shimizu 890ddd
	bool m_drawExternalBG;
Toshihiro Shimizu 890ddd
	VisualSettings m_vSettings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Painter(
Toshihiro Shimizu 890ddd
		const TDimension &dim,
Toshihiro Shimizu 890ddd
		const TDimension &imageSize,
Toshihiro Shimizu 890ddd
		const TAffine &viewAff,
Toshihiro Shimizu 890ddd
		TPalette *palette,
Toshihiro Shimizu 890ddd
		const VisualSettings &visualSettings);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void flushRasterImages(const TRect &loadbox, double compareX, double compareY, bool swapCompared);
Toshihiro Shimizu 890ddd
	void doFlushRasterImages(const TRasterP &rin, int bg, const TPointD &offs = TPointD());
Toshihiro Shimizu 890ddd
	void onVectorImage(TVectorImage *vi);
Toshihiro Shimizu 890ddd
	void onRasterImage(TRasterImage *ri);
Toshihiro Shimizu 890ddd
	void onToonzImage(TToonzImage *ti);
Toshihiro Shimizu 890ddd
	void drawBlank();
Toshihiro Shimizu 890ddd
	TRaster32P buildCheckboard(int bg, const TDimension &dim);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Painter::Painter(
Toshihiro Shimizu 890ddd
	const TDimension &dim,
Toshihiro Shimizu 890ddd
	const TDimension &imageSize,
Toshihiro Shimizu 890ddd
	const TAffine &viewAff,
Toshihiro Shimizu 890ddd
	TPalette *palette,
Toshihiro Shimizu 890ddd
	const VisualSettings &visualSettings)
Toshihiro Shimizu 890ddd
	: m_dim(dim), m_imageSize(imageSize), m_aff(viewAff), m_palette(palette), m_bbox(), m_raster(), m_vSettings(visualSettings)
Toshihiro Shimizu 890ddd
//, m_channel(visualSettings.m_colorMask)
Toshihiro Shimizu 890ddd
//, m_greytones(visualSettings.m_greytones)
Toshihiro Shimizu 890ddd
//, m_sceneProperties(visualSettings.m_sceneProperties)
Toshihiro Shimizu 890ddd
//, m_useTexture(visualSettings.m_useTexture)
Toshihiro Shimizu 890ddd
//, m_drawExternalBG(visualSettings.m_drawExternalBG)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Painter::flushRasterImages(const TRect &loadbox, double compareX, double compareY, bool swapCompare)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_raster)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	glDisable(GL_DEPTH_TEST);
Toshihiro Shimizu 890ddd
	glDisable(GL_DITHER);
Toshihiro Shimizu 890ddd
	glDisable(GL_LOGIC_OP);
Toshihiro Shimizu 890ddd
	glDisable(GL_STENCIL_TEST);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GL_EXT_convolution
Toshihiro Shimizu 890ddd
	glDisable(GL_CONVOLUTION_1D_EXT);
Toshihiro Shimizu 890ddd
	glDisable(GL_CONVOLUTION_2D_EXT);
Toshihiro Shimizu 890ddd
	glDisable(GL_SEPARABLE_2D_EXT);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GL_EXT_histogram
Toshihiro Shimizu 890ddd
	glDisable(GL_HISTOGRAM_EXT);
Toshihiro Shimizu 890ddd
	glDisable(GL_MINMAX_EXT);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef GL_EXT_texture3D
Toshihiro Shimizu 890ddd
	glDisable(GL_TEXTURE_3D_EXT);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UCHAR m = m_vSettings.m_colorMask;
Toshihiro Shimizu 890ddd
	bool showBg = (m == 0 ||
Toshihiro Shimizu 890ddd
				   (m & TRop::MChan && !m_vSettings.m_greytones &&
Toshihiro Shimizu 890ddd
					(m & TRop::RChan || m & TRop::GChan || m & TRop::BChan)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int bg = showBg ? m_vSettings.m_bg : 0x40000;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_vSettings.m_drawExternalBG) {
Toshihiro Shimizu 890ddd
		if (m_vSettings.m_colorMask != 0) {
Toshihiro Shimizu 890ddd
			glClearColor(0, 0, 0, 1.0);
Toshihiro Shimizu 890ddd
			glClear(GL_COLOR_BUFFER_BIT);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			TPixel bgColor = Preferences::instance()->getPreviewBgColor();
Toshihiro Shimizu 890ddd
			glClearColor(bgColor.r / 255.0f, bgColor.g / 255.0f, bgColor.b / 255.0f, 1.0);
Toshihiro Shimizu 890ddd
			glClear(GL_COLOR_BUFFER_BIT);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	UCHAR chan = m_vSettings.m_colorMask;
Toshihiro Shimizu 890ddd
	if (chan != 0 && !(chan & TRop::MChan) && !(chan != TRop::MChan && chan & TRop::MChan) && !m_vSettings.m_greytones)
Toshihiro Shimizu 890ddd
		glColorMask((chan & TRop::RChan) ? GL_TRUE : GL_FALSE,
Toshihiro Shimizu 890ddd
					(chan & TRop::GChan) ? GL_TRUE : GL_FALSE,
Toshihiro Shimizu 890ddd
					(chan & TRop::BChan) ? GL_TRUE : GL_FALSE,
Toshihiro Shimizu 890ddd
					GL_TRUE);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (compareX != DefaultCompareValue || compareY != DefaultCompareValue) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glEnable(GL_SCISSOR_TEST);
Toshihiro Shimizu 890ddd
		//draw right/down part of the screen...
Toshihiro Shimizu 890ddd
		if (swapCompare)
Toshihiro Shimizu 890ddd
			glScissor(0, 0, m_dim.lx * (compareX == DefaultCompareValue ? 1 : compareX), m_dim.ly * (compareY == DefaultCompareValue ? 1 : compareY));
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			glScissor(m_dim.lx * (compareX == DefaultCompareValue ? 0 : compareX), m_dim.ly * (compareY == DefaultCompareValue ? 0 : compareY), m_dim.lx, m_dim.ly);
Toshihiro Shimizu 890ddd
		doFlushRasterImages(m_raster, bg, convert(loadbox.getP00()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TImageP refimg = TImageCache::instance()->get(QString("TnzCompareImg"), false);
Toshihiro Shimizu 890ddd
		if ((TToonzImageP)refimg || (TRasterImageP)refimg) {
Toshihiro Shimizu 890ddd
			//draw left/up part of the screen...
Toshihiro Shimizu 890ddd
			TRasterP raux, rref;
Toshihiro Shimizu 890ddd
			if ((TToonzImageP)refimg)
Toshihiro Shimizu 890ddd
				rref = ((TToonzImageP)refimg)->getCMapped();
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				rref = ((TRasterImageP)refimg)->getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TRect rect = loadbox;
Toshihiro Shimizu 890ddd
			raux = loadbox != TRect() ? rref->extract(rect) : rref;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TPointD cmpOffs = TPointD(0.5 * (((m_imageSize.lx == 0) ? m_raster->getLx() : m_imageSize.lx) - rref->getLx()),
Toshihiro Shimizu 890ddd
									  0.5 * (((m_imageSize.ly == 0) ? m_raster->getLy() : m_imageSize.ly) - rref->getLy()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (swapCompare)
Toshihiro Shimizu 890ddd
				glScissor(m_dim.lx * (compareX == DefaultCompareValue ? 0 : compareX), m_dim.ly * (compareY == DefaultCompareValue ? 0 : compareY), m_dim.lx, m_dim.ly);
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				glScissor(0, 0, m_dim.lx * (compareX == DefaultCompareValue ? 1 : compareX), m_dim.ly * (compareY == DefaultCompareValue ? 1 : compareY));
Toshihiro Shimizu 890ddd
			doFlushRasterImages(raux, bg, cmpOffs + convert(loadbox.getP00()));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		glDisable(GL_SCISSOR_TEST);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		doFlushRasterImages(m_raster, bg, convert(loadbox.getP00()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_raster = TRasterP();
Toshihiro Shimizu 890ddd
	m_palette = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P Painter::buildCheckboard(int bg, const TDimension &dim)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P checkBoard = TRaster32P(100, 100);
Toshihiro Shimizu 890ddd
	if (bg == 0x100000) {
Toshihiro Shimizu 890ddd
		TPixel col1, col2;
Toshihiro Shimizu 890ddd
		Preferences::instance()->getChessboardColors(col1, col2);
Toshihiro Shimizu 890ddd
		TPointD p = TPointD(0, 0);
Toshihiro Shimizu 890ddd
		if (m_vSettings.m_useTexture)
Toshihiro Shimizu 890ddd
			p = TPointD(m_bbox.x0 > 0 ? 0 : -m_bbox.x0, m_bbox.y0 > 0 ? 0 : -m_bbox.y0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		assert(checkBoard.getPointer());
Toshihiro Shimizu 890ddd
		TRop::checkBoard(checkBoard, col1, col2, TDimensionD(50, 50), p);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		TPixel pix = bg == 0x40000 ? TPixel::Black : TPixel::White;
Toshihiro Shimizu 890ddd
		assert(checkBoard.getPointer());
Toshihiro Shimizu 890ddd
		checkBoard->fill(pix);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//TRaster32P textureBackGround;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//if(m_vSettings.m_useTexture)
Toshihiro Shimizu 890ddd
	//  textureBackGround = TRaster32P(dim.lx,dim.ly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(checkBoard.getPointer());
Toshihiro Shimizu 890ddd
	int lx = (m_imageSize.lx == 0 ? dim.lx : m_imageSize.lx);
Toshihiro Shimizu 890ddd
	int ly = (m_imageSize.ly == 0 ? dim.ly : m_imageSize.ly);
Toshihiro Shimizu 890ddd
	int x, y;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P checkBoardRas(lx, ly);
Toshihiro Shimizu 890ddd
	for (y = 0; y < ly; y += 100) {
Toshihiro Shimizu 890ddd
		for (x = 0; x < lx; x += 100) {
Toshihiro Shimizu 890ddd
			//TAffine checkTrans = TTranslation(x,y);
Toshihiro Shimizu 890ddd
			//if(m_vSettings.m_useTexture)
Toshihiro Shimizu 890ddd
			//  quickput(textureBackGround, checkBoard, m_palette, checkTrans);
Toshihiro Shimizu 890ddd
			// else
Toshihiro Shimizu 890ddd
			quickput(checkBoardRas, checkBoard, m_palette, TTranslation(x, y), false);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return checkBoardRas;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Painter::doFlushRasterImages(const TRasterP &rin, int bg, const TPointD &offs)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!rin)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TRectD viewRect(0.0, 0.0, m_dim.lx - 1, m_dim.ly - 1);
Toshihiro Shimizu 890ddd
	TRectD bbox;
Toshihiro Shimizu 890ddd
	if (m_vSettings.m_useTexture)
Toshihiro Shimizu 890ddd
		bbox = m_bbox;
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		double delta = sqrt(fabs(m_finalAff.det()));
Toshihiro Shimizu 890ddd
		bbox = m_bbox.enlarge(delta) * viewRect;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UCHAR chan = m_vSettings.m_colorMask;
Toshihiro Shimizu 890ddd
	TRect rect(tfloor(bbox.x0), tfloor(bbox.y0), tceil(bbox.x1), tceil(bbox.y1));
Toshihiro Shimizu 890ddd
	if (rect.isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P ras;
Toshihiro Shimizu 890ddd
	TRasterP _rin = rin;
Toshihiro Shimizu 890ddd
	TAffine aff;
Toshihiro Shimizu 890ddd
	if (m_vSettings.m_useTexture) {
Toshihiro Shimizu 890ddd
		ras = _rin;
Toshihiro Shimizu 890ddd
		aff = m_aff;
Toshihiro Shimizu 890ddd
		//ras->clear();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		int lx = rect.getLx(), ly = rect.getLy();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Following lines are used to solve a problem that occurs with some graphics cards!
Toshihiro Shimizu 890ddd
		// It seems that the glReadPixels() function is very slow if the lx lenght
Toshihiro Shimizu 890ddd
		// isn't a multiple of 8!
Toshihiro Shimizu 890ddd
		TDimension backgroundDim(lx, ly);
Toshihiro Shimizu 890ddd
		backgroundDim.lx = (lx & 0x7) == 0 ? lx : lx + 8 - (lx & 0x7);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		static std::vector<char> buffer;</char>
Toshihiro Shimizu 890ddd
		int size = backgroundDim.lx * backgroundDim.ly * 4;
Toshihiro Shimizu 890ddd
		if (size > (int)buffer.size())
Toshihiro Shimizu 890ddd
			buffer.resize(size);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRaster32P backgroundRas(backgroundDim.lx, backgroundDim.ly, backgroundDim.lx, (TPixel32 *)&buffer[0]);
Toshihiro Shimizu 890ddd
		glReadPixels(rect.x0, rect.y0, backgroundDim.lx, backgroundDim.ly,
Toshihiro Shimizu 890ddd
					 TGL_FMT, TGL_TYPE, backgroundRas->getRawData());
Toshihiro Shimizu 890ddd
		TRect r = rect - rect.getP00();
Toshihiro Shimizu 890ddd
		ras = backgroundRas->extract(r);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		aff = TTranslation(-rect.x0, -rect.y0) * m_finalAff;
Toshihiro Shimizu 890ddd
		aff *= TTranslation(TPointD(0.5, 0.5)); //very quick and very dirty fix: in camerastand the images seems shifted of an half pixel...it's a quickput approximation?
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool showChannelsOnMatte = (chan != TRop::MChan && chan != 0 && !m_vSettings.m_greytones);
Toshihiro Shimizu 890ddd
	if ((!showChannelsOnMatte && !m_vSettings.m_useTexture && chan != 0) ||
Toshihiro Shimizu 890ddd
		(!showChannelsOnMatte && m_vSettings.m_useTexture && (chan == TRop::MChan || m_vSettings.m_greytones))) {
Toshihiro Shimizu 890ddd
		TRasterP app = _rin->create(_rin->getLx(), _rin->getLy());
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			TRop::setChannel(_rin, app, chan, m_vSettings.m_greytones);
Toshihiro Shimizu 890ddd
			if (!m_vSettings.m_useTexture)
Toshihiro Shimizu 890ddd
				_rin = app;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				ras = app;
Toshihiro Shimizu 890ddd
		} catch (...) {
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_vSettings.m_useTexture) {
Toshihiro Shimizu 890ddd
		TRaster32P checkBoardRas = buildCheckboard(bg, _rin->getSize());
Toshihiro Shimizu 890ddd
		GLRasterPainter::drawRaster(aff, checkBoardRas->getRawData(), checkBoardRas->getWrap(), 4, checkBoardRas->getSize(), true);
Toshihiro Shimizu 890ddd
		if (showChannelsOnMatte)
Toshihiro Shimizu 890ddd
			ras = keepChannels(_rin, m_palette, chan);
Toshihiro Shimizu 890ddd
		GLRasterPainter::drawRaster(aff, ras->getRawData(), ras->getWrap(), 4, ras->getSize(), true);
Toshihiro Shimizu 890ddd
		ras->unlock();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (bg == 0x100000)
Toshihiro Shimizu 890ddd
			quickput(ras, buildCheckboard(bg, _rin->getSize()), m_palette, aff, false);
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			int lx = (m_imageSize.lx == 0 ? _rin->getLx() : m_imageSize.lx);
Toshihiro Shimizu 890ddd
			int ly = (m_imageSize.ly == 0 ? _rin->getLy() : m_imageSize.ly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TRect rect = convert(aff * TRectD(0, 0, lx - 1, ly - 1));
Toshihiro Shimizu 890ddd
			TRaster32P raux = ras->extract(rect);
Toshihiro Shimizu 890ddd
			raux->fill(bg == 0x40000 ? TPixel::Black : TPixel::White);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (showChannelsOnMatte)
Toshihiro Shimizu 890ddd
			quickput(ras, keepChannels(_rin, m_palette, chan), m_palette, m_vSettings.m_useTexture ? TAffine() : aff * TTranslation(offs), m_vSettings.m_useChecks);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			quickput(ras, _rin, m_palette, aff * TTranslation(offs), m_vSettings.m_useChecks);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glDisable(GL_BLEND);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		glLoadIdentity();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glRasterPos2d(rect.x0, rect.y0);
Toshihiro Shimizu 890ddd
		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glDrawPixels(ras->getWrap(), ras->getLy(),
Toshihiro Shimizu 890ddd
					 TGL_FMT, TGL_TYPE, ras->getRawData());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		CHECK_ERRORS_BY_GL
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ras->unlock();
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Painter::onVectorImage(TVectorImage *vi)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect clipRect = m_dim;
Toshihiro Shimizu 890ddd
	clipRect -= TPoint(m_dim.lx * 0.5, m_dim.ly * 0.5);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool thereIsColorFilter = (m_vSettings.m_colorMask != 0 && m_vSettings.m_colorMask != TRop::MChan);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_vSettings.m_bg == 0x100000 && !thereIsColorFilter) {
Toshihiro Shimizu 890ddd
		TRaster32P check = getCheckBoard(clipRect, m_aff, m_vSettings.m_sceneProperties);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glDisable(GL_BLEND);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		glLoadIdentity();
Toshihiro Shimizu 890ddd
		glRasterPos2d(0, 0);
Toshihiro Shimizu 890ddd
		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glDrawPixels(check->getLx(), check->getLy(), TGL_FMT, TGL_TYPE, check->getRawData());
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (m_vSettings.m_bg == 0x40000 || thereIsColorFilter)
Toshihiro Shimizu 890ddd
			glClearColor(0.0, 0.0, 0.0, 1.0);
Toshihiro Shimizu 890ddd
		else if (m_vSettings.m_bg == 0x80000)
Toshihiro Shimizu 890ddd
			glClearColor(1.0, 1.0, 1.0, 1.0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glClear(GL_COLOR_BUFFER_BIT);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TVectorRenderData rd(m_aff,
Toshihiro Shimizu 890ddd
						 clipRect,
Toshihiro Shimizu 890ddd
						 vi->getPalette(),
Toshihiro Shimizu 890ddd
						 0,
Toshihiro Shimizu 890ddd
						 true // alfa enabled
Toshihiro Shimizu 890ddd
						 );
Toshihiro Shimizu 890ddd
	if (m_vSettings.m_useChecks) {
Toshihiro Shimizu 890ddd
		ToonzCheck *tc = ToonzCheck::instance();
Toshihiro Shimizu 890ddd
		int checks = tc->getChecks(); // &ToonzCheck::eBlackBg
Toshihiro Shimizu 890ddd
		rd.m_inkCheckEnabled = checks & ToonzCheck::eInk;
Toshihiro Shimizu 890ddd
		rd.m_paintCheckEnabled = checks & ToonzCheck::ePaint;
Toshihiro Shimizu 890ddd
		rd.m_colorCheckIndex = tc->getColorIndex();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	tglDraw(rd, vi);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Painter::onRasterImage(TRasterImage *ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TDimension imageSize = (m_imageSize.lx == 0 ? ri->getRaster()->getSize() : m_imageSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_finalAff = m_vSettings.m_useTexture ? m_aff
Toshihiro Shimizu 890ddd
										  : TTranslation(m_dim.lx * 0.5, m_dim.ly * 0.5) * m_aff * TTranslation(-TPointD(0.5 * imageSize.lx, 0.5 * imageSize.ly));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD bbox = TRectD(0, 0, imageSize.lx - 1, imageSize.ly - 1);
Toshihiro Shimizu 890ddd
	m_bbox = m_vSettings.m_useTexture ? bbox : m_finalAff * bbox;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_bbox.overlaps(TRectD(0, 0, m_dim.lx - 1, m_dim.ly - 1)))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_raster = ri->getRaster();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Painter::onToonzImage(TToonzImage *ti)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TDimension imageSize = (m_imageSize.lx == 0 ? ti->getRaster()->getSize() : m_imageSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_finalAff = m_vSettings.m_useTexture ? m_aff
Toshihiro Shimizu 890ddd
										  : TTranslation(m_dim.lx * 0.5, m_dim.ly * 0.5) * m_aff * TTranslation(-TPointD(0.5 * imageSize.lx, 0.5 * imageSize.ly));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD bbox = TRectD(0, 0, imageSize.lx - 1, imageSize.ly - 1);
Toshihiro Shimizu 890ddd
	m_bbox = m_vSettings.m_useTexture ? bbox : m_finalAff * bbox;
Toshihiro Shimizu 890ddd
	if (!m_bbox.overlaps(TRectD(0, 0, m_dim.lx - 1, m_dim.ly - 1)))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_raster = ti->getRaster();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Painter::drawBlank()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPixel bgColor = Preferences::instance()->getPreviewBgColor();
Toshihiro Shimizu 890ddd
	glClearColor(bgColor.r / 255.0f, bgColor.g / 255.0f, bgColor.b / 255.0f, 1.0);
Toshihiro Shimizu 890ddd
	glClear(GL_COLOR_BUFFER_BIT);
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
	glLoadIdentity();
Toshihiro Shimizu 890ddd
	tglColor(m_vSettings.m_blankColor);
Toshihiro Shimizu 890ddd
	tglFillRect(m_bbox);
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ImagePainter::VisualSettings::VisualSettings()
Toshihiro Shimizu 890ddd
	: m_colorMask(0), m_greytones(false), m_doCompare(false), m_defineLoadbox(false), m_useLoadbox(false), m_blankColor(TPixel::Transparent), m_useTexture(false), m_drawExternalBG(false), m_showBBox(false), m_sceneProperties(0), m_recomputeIfNeeded(true), m_drawBlankFrame(false), m_useChecks(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (FlipBookBlackBgToggle)
Toshihiro Shimizu 890ddd
		m_bg = 0x40000;
Toshihiro Shimizu 890ddd
	if (FlipBookWhiteBgToggle)
Toshihiro Shimizu 890ddd
		m_bg = 0x80000;
Toshihiro Shimizu 890ddd
	if (FlipBookCheckBgToggle)
Toshihiro Shimizu 890ddd
		m_bg = 0x100000;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool ImagePainter::VisualSettings::needRepaint(const VisualSettings &vs) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return !(m_colorMask == vs.m_colorMask &&
Toshihiro Shimizu 890ddd
			 m_greytones == vs.m_greytones &&
Toshihiro Shimizu 890ddd
			 m_bg == vs.m_bg &&
Toshihiro Shimizu 890ddd
			 m_doCompare == vs.m_doCompare &&
Toshihiro Shimizu 890ddd
			 m_defineLoadbox == vs.m_defineLoadbox &&
Toshihiro Shimizu 890ddd
			 m_useLoadbox == vs.m_useLoadbox &&
Toshihiro Shimizu 890ddd
			 m_useTexture == vs.m_useTexture &&
Toshihiro Shimizu 890ddd
			 m_drawExternalBG == vs.m_drawExternalBG);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ImagePainter::CompareSettings::CompareSettings()
Toshihiro Shimizu 890ddd
	: m_compareX(0.5), m_compareY(DefaultCompareValue), m_dragCompareX(false), m_dragCompareY(false), m_swapCompared(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ImagePainter::paintImage(const TImageP &image, const TDimension &imageSize,
Toshihiro Shimizu 890ddd
							  const TDimension &viewerSize,
Toshihiro Shimizu 890ddd
							  const TAffine &aff,
Toshihiro Shimizu 890ddd
							  const VisualSettings &visualSettings,
Toshihiro Shimizu 890ddd
							  const CompareSettings &compareSettings,
Toshihiro Shimizu 890ddd
							  const TRect &loadbox)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	glDisable(GL_DEPTH_TEST);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (visualSettings.m_drawExternalBG) {
Toshihiro Shimizu 890ddd
		glClearColor(0.0, 0.0, 0.0, 0.0);
Toshihiro Shimizu 890ddd
		glClear(GL_COLOR_BUFFER_BIT);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	GLenum error = glGetError();
Toshihiro Shimizu 890ddd
	//assert(error==GL_NO_ERROR);
Toshihiro Shimizu 890ddd
	if (error != GL_NO_ERROR) {
Toshihiro Shimizu 890ddd
		printf("ImagePainter::paintImage() gl_error:%d\n", error);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!image)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterImageP rimg = (TRasterImageP)image;
Toshihiro Shimizu 890ddd
	TVectorImageP vimg = (TVectorImageP)image;
Toshihiro Shimizu 890ddd
	TToonzImageP timg = (TToonzImageP)image;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRect clipRect(viewerSize);
Toshihiro Shimizu 890ddd
	clipRect -= TPoint(viewerSize.lx * 0.5, viewerSize.ly * 0.5);
Toshihiro Shimizu 890ddd
	Painter painter(viewerSize, imageSize, aff, image->getPalette(), visualSettings);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (rimg)
Toshihiro Shimizu 890ddd
		painter.onRasterImage(rimg.getPointer());
Toshihiro Shimizu 890ddd
	else if (vimg)
Toshihiro Shimizu 890ddd
		painter.onVectorImage(vimg.getPointer());
Toshihiro Shimizu 890ddd
	else if (timg)
Toshihiro Shimizu 890ddd
		painter.onToonzImage(timg.getPointer());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (visualSettings.m_blankColor != TPixel::Transparent) {
Toshihiro Shimizu 890ddd
		painter.drawBlank();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//if I have a color filter applied using a glmask, , drawing of images must be done on black bg!
Toshihiro Shimizu 890ddd
	if (!vimg)
Toshihiro Shimizu 890ddd
		painter.flushRasterImages(loadbox,
Toshihiro Shimizu 890ddd
								  visualSettings.m_doCompare ? compareSettings.m_compareX : DefaultCompareValue,
Toshihiro Shimizu 890ddd
								  visualSettings.m_doCompare ? compareSettings.m_compareY : DefaultCompareValue,
Toshihiro Shimizu 890ddd
								  compareSettings.m_swapCompared);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (visualSettings.m_doCompare)
Toshihiro Shimizu 890ddd
		drawCompareLines(viewerSize, compareSettings.m_compareX, compareSettings.m_compareY);
Toshihiro Shimizu 890ddd
}