|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/trasterimageutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/ttileset.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstroke.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorrenderdata.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttzpimagefx.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tregion.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <qpainter></qpainter>
|
|
Toshihiro Shimizu |
890ddd |
#include <qcolor></qcolor>
|
|
Toshihiro Shimizu |
890ddd |
#include <qimage></qimage>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QImage rasterToQImage(const TRasterP &ras, bool premultiplied, bool mirrored)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (TRaster32P ras32 = ras) {
|
|
Toshihiro Shimizu |
890ddd |
QImage image(ras->getRawData(), ras->getLx(), ras->getLy(),
|
|
Toshihiro Shimizu |
890ddd |
premultiplied ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);
|
|
Toshihiro Shimizu |
890ddd |
if (mirrored)
|
|
Toshihiro Shimizu |
890ddd |
return image.mirrored();
|
|
Toshihiro Shimizu |
890ddd |
return image;
|
|
Toshihiro Shimizu |
890ddd |
} else if (TRasterGR8P ras8 = ras) {
|
|
Toshihiro Shimizu |
890ddd |
QImage image(ras->getRawData(), ras->getLx(), ras->getLy(), ras->getWrap(), QImage::Format_Indexed8);
|
|
Toshihiro Shimizu |
890ddd |
static QVector<qrgb> colorTable;</qrgb>
|
|
Toshihiro Shimizu |
890ddd |
if (colorTable.size() == 0) {
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < 256; i++)
|
|
Toshihiro Shimizu |
890ddd |
colorTable.append(QColor(i, i, i).rgb());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
image.setColorTable(colorTable);
|
|
Toshihiro Shimizu |
890ddd |
if (mirrored)
|
|
Toshihiro Shimizu |
890ddd |
return image.mirrored();
|
|
Toshihiro Shimizu |
890ddd |
return image;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return QImage();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void rasterizeWholeStroke(TOfflineGL *&gl, TStroke *stroke, TPalette *palette, bool doAnialias)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRectD bbox = stroke->getBBox();
|
|
Toshihiro Shimizu |
890ddd |
TRect rect = convert(bbox).enlarge(1);
|
|
Toshihiro Shimizu |
890ddd |
gl = new TOfflineGL(rect.getSize());
|
|
Toshihiro Shimizu |
890ddd |
gl->makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
gl->clear(TPixel32(0, 0, 0, 0));
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_ALPHA_TEST);
|
|
Toshihiro Shimizu |
890ddd |
glAlphaFunc(GL_GREATER, 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPaletteP plt = palette->clone();
|
|
Toshihiro Shimizu |
890ddd |
int styleId = stroke->getStyle();
|
|
Toshihiro Shimizu |
890ddd |
TColorStyleP style = plt->getStyle(styleId);
|
|
Toshihiro Shimizu |
890ddd |
TTranslation affine(-convert(rect.getP00()));
|
|
Toshihiro Shimizu |
890ddd |
TVectorRenderData rd(affine, gl->getBounds(), plt.getPointer(), 0, true, true);
|
|
Toshihiro Shimizu |
890ddd |
if (doAnialias)
|
|
Toshihiro Shimizu |
890ddd |
tglDraw(rd, stroke);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TStrokeProp *prop = stroke->getProp();
|
|
Toshihiro Shimizu |
890ddd |
if (prop)
|
|
Toshihiro Shimizu |
890ddd |
prop->getMutex()->lock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!style->isStrokeStyle() || style->isEnabled() == false) {
|
|
Toshihiro Shimizu |
890ddd |
if (prop)
|
|
Toshihiro Shimizu |
890ddd |
prop->getMutex()->unlock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
prop = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (!prop || style.getPointer() != prop->getColorStyle()) {
|
|
Toshihiro Shimizu |
890ddd |
if (prop)
|
|
Toshihiro Shimizu |
890ddd |
prop->getMutex()->unlock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
stroke->setProp(style->makeStrokeProp(stroke));
|
|
Toshihiro Shimizu |
890ddd |
prop = stroke->getProp();
|
|
Toshihiro Shimizu |
890ddd |
if (prop)
|
|
Toshihiro Shimizu |
890ddd |
prop->getMutex()->lock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!prop)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
prop->getMutex()->lock();
|
|
Toshihiro Shimizu |
890ddd |
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
Toshihiro Shimizu |
890ddd |
prop->draw(rd);
|
|
Toshihiro Shimizu |
890ddd |
glPopAttrib();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
glDisable(GL_ALPHA_TEST);
|
|
Toshihiro Shimizu |
890ddd |
glFinish();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect fastAddInkStroke(const TRasterImageP &ri, TStroke *stroke, TRectD clip, double opacity, bool doAntialiasing)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TOfflineGL *gl = 0;
|
|
Toshihiro Shimizu |
890ddd |
TRectD bbox = stroke->getBBox();
|
|
Toshihiro Shimizu |
890ddd |
TRect sBBox = convert(bbox).enlarge(1);
|
|
Toshihiro Shimizu |
890ddd |
TRect rectRender = sBBox * ri->getRaster()->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!rectRender.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
if (opacity < 1.0) {
|
|
Toshihiro Shimizu |
890ddd |
int styleId = stroke->getStyle();
|
|
Toshihiro Shimizu |
890ddd |
TPalette *plt = ri->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 color = plt->getStyle(styleId)->getMainColor();
|
|
Toshihiro Shimizu |
890ddd |
color.m = 255 * opacity;
|
|
Toshihiro Shimizu |
890ddd |
TPaletteP newPlt(plt);
|
|
Toshihiro Shimizu |
890ddd |
newPlt->getStyle(styleId)->setMainColor(color);
|
|
Toshihiro Shimizu |
890ddd |
rasterizeWholeStroke(gl, stroke, newPlt.getPointer(), doAntialiasing);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
rasterizeWholeStroke(gl, stroke, ri->getPalette(), doAntialiasing);
|
|
Toshihiro Shimizu |
890ddd |
TRect tmp = rectRender - sBBox.getP00();
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P glRas = gl->getRaster()->extract(tmp);
|
|
Toshihiro Shimizu |
890ddd |
TRop::over(ri->getRaster(), glRas, rectRender.getP00());
|
|
Toshihiro Shimizu |
890ddd |
delete gl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return rectRender;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect rasterizeRegion(TOfflineGL *&gl, TRect rasBounds, TRegion *region, TPalette *palette, TRectD clip)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRectD regionBBox = region->getBBox();
|
|
Toshihiro Shimizu |
890ddd |
if (!clip.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
regionBBox = regionBBox * clip;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect rect = convert(regionBBox) * rasBounds;
|
|
Toshihiro Shimizu |
890ddd |
if (!rect.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
gl = new TOfflineGL(rect.getSize());
|
|
Toshihiro Shimizu |
890ddd |
gl->makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
gl->clear(TPixel32::Transparent);
|
|
Toshihiro Shimizu |
890ddd |
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_ALPHA_TEST);
|
|
Toshihiro Shimizu |
890ddd |
glAlphaFunc(GL_GREATER, 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TTranslation affine(-convert(rect.getP00()));
|
|
Toshihiro Shimizu |
890ddd |
TVectorRenderData rd(affine, gl->getBounds(), palette, 0, true, true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDraw(rd, region);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glDisable(GL_ALPHA_TEST);
|
|
Toshihiro Shimizu |
890ddd |
glPopAttrib();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glFinish();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void fastAddPaintRegion(const TRasterImageP &ri, TRegion *region,
|
|
Toshihiro Shimizu |
890ddd |
int newPaintId, int maxStyleId, TRectD clip = TRectD())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TOfflineGL *gl;
|
|
Toshihiro Shimizu |
890ddd |
TRect rect = rasterizeRegion(gl, ras->getBounds(), region, ri->getPalette(), clip);
|
|
Toshihiro Shimizu |
890ddd |
if (rect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P glRas = gl->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
assert(TPixelCM32::getMaxTone() == 255);
|
|
Toshihiro Shimizu |
890ddd |
TRop::over(ri->getRaster(), glRas, rect.getP00());
|
|
Toshihiro Shimizu |
890ddd |
delete gl;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRegion *subregion;
|
|
Toshihiro Shimizu |
890ddd |
UINT i = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (; i < region->getSubregionCount(); ++i) {
|
|
Toshihiro Shimizu |
890ddd |
subregion = region->getSubregion(i);
|
|
Toshihiro Shimizu |
890ddd |
fastAddPaintRegion(ri, subregion, tmin(maxStyleId, subregion->getStyle()), maxStyleId);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect TRasterImageUtils::addStroke(const TRasterImageP &ri, TStroke *stroke, TRectD clip,
|
|
Toshihiro Shimizu |
890ddd |
double opacity, bool doAntialiasing)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = new TStroke(*stroke);
|
|
Toshihiro Shimizu |
890ddd |
TPoint riCenter = ri->getRaster()->getCenter();
|
|
Toshihiro Shimizu |
890ddd |
s->transform(TTranslation(riCenter.x, riCenter.y));
|
|
Toshihiro Shimizu |
890ddd |
TRect rect = fastAddInkStroke(ri, s, clip, opacity, doAntialiasing);
|
|
Toshihiro Shimizu |
890ddd |
rect -= riCenter;
|
|
Toshihiro Shimizu |
890ddd |
delete s;
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect TRasterImageUtils::convertWorldToRaster(const TRectD &area, const TRasterImageP ri)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (area.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return TRect();
|
|
Toshihiro Shimizu |
890ddd |
if (!ri || !ri->getRaster())
|
|
Toshihiro Shimizu |
890ddd |
return TRect(tfloor(area.x0), tfloor(area.y0), tfloor(area.x1) - 1, tfloor(area.y1) - 1);
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TRectD rect(area + ras->getCenterD());
|
|
Toshihiro Shimizu |
890ddd |
return TRect(tfloor(rect.x0), tfloor(rect.y0), tceil(rect.x1) - 1, tceil(rect.y1) - 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD TRasterImageUtils::convertRasterToWorld(const TRect &area, const TRasterImageP ri)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (area.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return TRectD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD rect(area.x0, area.y0, area.x1 + 1, area.y1 + 1);
|
|
Toshihiro Shimizu |
890ddd |
if (ri && ri->getRaster())
|
|
Toshihiro Shimizu |
890ddd |
rect = rect - ri->getRaster()->getCenterD();
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// DA RIFARE
|
|
Toshihiro Shimizu |
890ddd |
// e' lenta da far schifo
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!Converts a TVectorImage into a TRasterImage. The input vector image
|
|
Toshihiro Shimizu |
890ddd |
//!is transformed through the passed affine \b aff, and put into a
|
|
Toshihiro Shimizu |
890ddd |
//!TRasterImage strictly covering the bounding box of the transformed
|
|
Toshihiro Shimizu |
890ddd |
//!vector image. The output image has its lower-left position in the
|
|
Toshihiro Shimizu |
890ddd |
//!world reference specified by the \b pos parameter, which is granted to
|
|
Toshihiro Shimizu |
890ddd |
//!be an integer displacement of the passed value. Additional parameters
|
|
Toshihiro Shimizu |
890ddd |
//!include an integer \b enlarge by which the output image is enlarged with
|
|
Toshihiro Shimizu |
890ddd |
//!respect to the transformed image's bbox, and the bool \b transformThickness
|
|
Toshihiro Shimizu |
890ddd |
//!to specify whether the transformation should involve strokes' thickensses
|
|
Toshihiro Shimizu |
890ddd |
//!or not.
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP TRasterImageUtils::vectorToFullColorImage(
|
|
Toshihiro Shimizu |
890ddd |
const TVectorImageP &vimage, const TAffine &aff, TPalette *palette,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &outputPos, const TDimension &outputSize,
|
|
Shinya Kitaoka |
3bfa54 |
const std::vector<trasterfxrenderdatap> *fxs, bool transformThickness)</trasterfxrenderdatap>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!vimage || !palette)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Transform the vector image through aff
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi = vimage->clone();
|
|
Toshihiro Shimizu |
890ddd |
vi->transform(aff, transformThickness);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Allocate the output ToonzImage
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P raster(outputSize.lx, outputSize.ly);
|
|
Toshihiro Shimizu |
890ddd |
raster->clear();
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri(raster);
|
|
Toshihiro Shimizu |
890ddd |
ri->setPalette(palette->clone());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Shift outputPos to the origin
|
|
Toshihiro Shimizu |
890ddd |
vi->transform(TTranslation(-outputPos));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int strokeCount = vi->getStrokeCount();
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<int> strokeIndex(strokeCount);</int>
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tstroke *=""> strokes(strokeCount);</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeCount; ++i) {
|
|
Toshihiro Shimizu |
890ddd |
strokeIndex[i] = i;
|
|
Toshihiro Shimizu |
890ddd |
strokes[i] = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
vi->notifyChangedStrokes(strokeIndex, strokes);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int maxStyleId = palette->getStyleCount() - 1;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < (int)vi->getRegionCount(); ++i) {
|
|
Toshihiro Shimizu |
890ddd |
TRegion *region = vi->getRegion(i);
|
|
Toshihiro Shimizu |
890ddd |
fastAddPaintRegion(ri, region, tmin(maxStyleId, region->getStyle()), maxStyleId);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
set<int> colors;</int>
|
|
Toshihiro Shimizu |
890ddd |
if (fxs) {
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < (int)fxs->size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
SandorFxRenderData *sandorData = dynamic_cast<sandorfxrenderdata *="">((*fxs)[i].getPointer());</sandorfxrenderdata>
|
|
Toshihiro Shimizu |
890ddd |
if (sandorData && sandorData->m_type == BlendTz) {
|
|
Shinya Kitaoka |
3bfa54 |
std::string indexes = toString(sandorData->m_blendParams.m_colorIndex);
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::string> items;</std::string>
|
|
Toshihiro Shimizu |
890ddd |
parseIndexes(indexes, items);
|
|
Toshihiro Shimizu |
890ddd |
PaletteFilterFxRenderData paletteFilterData;
|
|
Toshihiro Shimizu |
890ddd |
insertIndexes(items, &paletteFilterData);
|
|
Toshihiro Shimizu |
890ddd |
colors = paletteFilterData.m_colors;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeCount; ++i) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool visible = false;
|
|
Toshihiro Shimizu |
890ddd |
int styleId = stroke->getStyle();
|
|
Toshihiro Shimizu |
890ddd |
TColorStyleP style = palette->getStyle(styleId);
|
|
Toshihiro Shimizu |
890ddd |
assert(style);
|
|
Toshihiro Shimizu |
890ddd |
int colorCount = style->getColorParamCount();
|
|
Toshihiro Shimizu |
890ddd |
if (colorCount == 0)
|
|
Toshihiro Shimizu |
890ddd |
visible = true;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
visible = false;
|
|
Toshihiro Shimizu |
890ddd |
for (int j = 0; j < style->getColorParamCount() && !visible; j++) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 color = style->getColorParamValue(j);
|
|
Toshihiro Shimizu |
890ddd |
if (color.m != 0)
|
|
Toshihiro Shimizu |
890ddd |
visible = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (visible)
|
|
Toshihiro Shimizu |
890ddd |
fastAddInkStroke(ri, stroke, TRectD(), 1, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return ri;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect TRasterImageUtils::eraseRect(const TRasterImageP &ri, const TRectD &area)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TRect rect = convertWorldToRaster(area, ri) * ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
if (rect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
ras->lock();
|
|
Toshihiro Shimizu |
890ddd |
TRasterP workRas = ras->extract(rect);
|
|
Toshihiro Shimizu |
890ddd |
if (workRas->getPixelSize() == 4)
|
|
Toshihiro Shimizu |
890ddd |
workRas->clear();
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TRasterGR8P rasGR8(workRas);
|
|
Toshihiro Shimizu |
890ddd |
if (rasGR8)
|
|
Toshihiro Shimizu |
890ddd |
rasGR8->fill(TPixelGR8::White);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<trect> TRasterImageUtils::paste(const TRasterImageP &ri, const TTileSetFullColor *tileSet)</trect>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<trect> rects;</trect>
|
|
Toshihiro Shimizu |
890ddd |
TRasterP raster = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < tileSet->getTileCount(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
const TTileSetFullColor::Tile *tile = tileSet->getTile(i);
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras;
|
|
Toshihiro Shimizu |
890ddd |
tile->getRaster(ras);
|
|
Toshihiro Shimizu |
890ddd |
assert(ras);
|
|
Toshihiro Shimizu |
890ddd |
raster->copy(ras, tile->m_rasterBounds.getP00());
|
|
Toshihiro Shimizu |
890ddd |
rects.push_back(tile->m_rasterBounds);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return rects;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRasterImageUtils::addSceneNumbering(const TRasterImageP &ri, int globalIndex,
|
|
Shinya Kitaoka |
3bfa54 |
const std::wstring &sceneName, int sceneIndex)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
TRasterP raster = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
int lx = raster->getLx(), ly = raster->getLy();
|
|
Toshihiro Shimizu |
890ddd |
QColor greyOverlay(100, 100, 100, 140);
|
|
Toshihiro Shimizu |
890ddd |
QImage image = rasterToQImage(raster, true, false);
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(&image);
|
|
Toshihiro Shimizu |
890ddd |
QFont numberingFont = QFont();
|
|
Toshihiro Shimizu |
890ddd |
numberingFont.setPixelSize(ly * 0.04);
|
|
Toshihiro Shimizu |
890ddd |
numberingFont.setBold(true);
|
|
Toshihiro Shimizu |
890ddd |
p.setFont(numberingFont);
|
|
Toshihiro Shimizu |
890ddd |
QMatrix matrix;
|
|
Toshihiro Shimizu |
890ddd |
p.setMatrix(matrix.translate(0, ly).scale(1, -1), true);
|
|
Toshihiro Shimizu |
890ddd |
QFontMetrics fm = p.fontMetrics();
|
|
Toshihiro Shimizu |
890ddd |
int fontHeight = fm.height();
|
|
Toshihiro Shimizu |
890ddd |
int offset = fontHeight * 0.2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//write the scenename and the scene frame
|
|
Toshihiro Shimizu |
890ddd |
QString sceneFrame = QString::number(sceneIndex);
|
|
Toshihiro Shimizu |
890ddd |
while (sceneFrame.size() < 4)
|
|
Toshihiro Shimizu |
890ddd |
sceneFrame.push_front("0");
|
|
Toshihiro Shimizu |
890ddd |
QString sceneNumberingString = QString::fromStdWString(sceneName) + ": " + sceneFrame;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int sceneNumberingWidth = fm.width(sceneNumberingString);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(Qt::NoPen);
|
|
Toshihiro Shimizu |
890ddd |
p.setBrush(QColor(255, 255, 255, 255));
|
|
Toshihiro Shimizu |
890ddd |
p.drawRect(offset, ly - offset - fontHeight, sceneNumberingWidth + offset * 2, fontHeight);
|
|
Toshihiro Shimizu |
890ddd |
p.setBrush(greyOverlay);
|
|
Toshihiro Shimizu |
890ddd |
p.drawRect(offset, ly - offset - fontHeight, sceneNumberingWidth + offset * 2, fontHeight);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(Qt::white);
|
|
Toshihiro Shimizu |
890ddd |
p.drawText(2 * offset, ly - 2 * offset, sceneNumberingString);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//write the global frame
|
|
Toshihiro Shimizu |
890ddd |
QString globalFrame = QString::number(globalIndex);
|
|
Toshihiro Shimizu |
890ddd |
while (globalFrame.size() < 4)
|
|
Toshihiro Shimizu |
890ddd |
globalFrame.push_front("0");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int gloablNumberingWidth = fm.width(globalFrame);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(Qt::NoPen);
|
|
Toshihiro Shimizu |
890ddd |
p.setBrush(QColor(255, 255, 255, 255));
|
|
Toshihiro Shimizu |
890ddd |
p.drawRect(lx - 3 * offset - gloablNumberingWidth, ly - offset - fontHeight, gloablNumberingWidth + offset * 2, fontHeight);
|
|
Toshihiro Shimizu |
890ddd |
p.setBrush(greyOverlay);
|
|
Toshihiro Shimizu |
890ddd |
p.drawRect(lx - 3 * offset - gloablNumberingWidth, ly - offset - fontHeight, gloablNumberingWidth + offset * 2, fontHeight);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(Qt::white);
|
|
Toshihiro Shimizu |
890ddd |
p.drawText(lx - 2 * offset - gloablNumberingWidth, ly - 2 * offset, globalFrame);
|
|
Toshihiro Shimizu |
890ddd |
p.end();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TRasterImageUtils::addGlobalNumbering(const TRasterImageP &ri, const std::wstring &sceneName, int globalIndex)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!ri)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
TRasterP raster = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
int lx = raster->getLx(), ly = raster->getLy();
|
|
Toshihiro Shimizu |
890ddd |
QColor greyOverlay(100, 100, 100, 140);
|
|
Toshihiro Shimizu |
890ddd |
QImage image = rasterToQImage(raster, true, false);
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(&image);
|
|
Toshihiro Shimizu |
890ddd |
QFont numberingFont = QFont();
|
|
Toshihiro Shimizu |
890ddd |
numberingFont.setPixelSize(ly * 0.04);
|
|
Toshihiro Shimizu |
890ddd |
numberingFont.setBold(true);
|
|
Toshihiro Shimizu |
890ddd |
p.setFont(numberingFont);
|
|
Toshihiro Shimizu |
890ddd |
QMatrix matrix;
|
|
Toshihiro Shimizu |
890ddd |
p.setMatrix(matrix.translate(0, ly).scale(1, -1), true);
|
|
Toshihiro Shimizu |
890ddd |
QFontMetrics fm = p.fontMetrics();
|
|
Toshihiro Shimizu |
890ddd |
int fontHeight = fm.height();
|
|
Toshihiro Shimizu |
890ddd |
int offset = fontHeight * 0.2;
|
|
Toshihiro Shimizu |
890ddd |
QString globalFrame = QString::number(globalIndex);
|
|
Toshihiro Shimizu |
890ddd |
while (globalFrame.size() < 4)
|
|
Toshihiro Shimizu |
890ddd |
globalFrame.push_front("0");
|
|
Toshihiro Shimizu |
890ddd |
QString globalNumberingString = QString::fromStdWString(sceneName) + ": " + globalFrame;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int globalNumberingWidth = fm.width(globalNumberingString);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(Qt::NoPen);
|
|
Toshihiro Shimizu |
890ddd |
p.setBrush(QColor(255, 255, 255, 255));
|
|
Toshihiro Shimizu |
890ddd |
p.drawRect(offset, ly - offset - fontHeight, globalNumberingWidth + offset * 2, fontHeight);
|
|
Toshihiro Shimizu |
890ddd |
p.setBrush(greyOverlay);
|
|
Toshihiro Shimizu |
890ddd |
p.drawRect(offset, ly - offset - fontHeight, globalNumberingWidth + offset * 2, fontHeight);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(Qt::white);
|
|
Toshihiro Shimizu |
890ddd |
p.drawText(2 * offset, ly - 2 * offset, globalNumberingString);
|
|
Toshihiro Shimizu |
890ddd |
p.end();
|
|
Toshihiro Shimizu |
890ddd |
}
|