static void tglDoDraw(const TVectorRenderData &rd, const TStroke *s) { bool visible = false; int colorCount = 0; const TPalette *palette = rd.m_palette; int styleId = s->getStyle(); // assert(0<=styleId && styleId<stylesCount); TColorStyleP style = palette->getStyle(styleId); assert(style); colorCount = style->getColorParamCount(); if (colorCount == 0) visible = true; else { visible = false; for (int j = 0; j < style->getColorParamCount() && !visible; j++) { TPixel32 color = style->getColorParamValue(j); if (rd.m_cf) color = (*(rd.m_cf))(color); if (color.m != 0) visible = true; } } if (visible) { // Change stroke color to blue if guided drawing if (rd.m_showGuidedDrawing && rd.m_highLightNow) { TVectorRenderData *newRd = new TVectorRenderData( rd, rd.m_aff, rd.m_clippingRect, rd.m_palette, rd.m_guidedCf); tglDraw(*newRd, s, false); delete newRd; TStroke *new_s = (TStroke *)s; drawFirstControlPoint(rd, new_s); } else { tglDraw(rd, s, false); } } #ifdef _DEBUG // drawControlPoints(rd, vim->getStroke(i), sqrt(tglGetPixelSize2()), true); // assert(checkQuadraticDistance(vim->getStroke(i),true)); #endif }
static void tglDoDraw(const TVectorRenderData &rd, TRegion *r) { bool visible = false; int colorCount = 0; if (!r) return; TColorStyleP style = rd.m_palette->getStyle(r->getStyle()); colorCount = style->getColorParamCount(); if (colorCount == 0) // for example texture visible = true; else { visible = false; for (int j = 0; j < colorCount && !visible; j++) { TPixel32 color = style->getColorParamValue(j); if (rd.m_cf) color = (*(rd.m_cf))(color); if (color.m != 0) visible = true; } } if (visible) tglDraw(rd, r, false); else for (UINT j = 0; j < r->getSubregionCount(); j++) tglDraw(rd, r->getSubregion(j), false); }
//!Converts a TVectorImage into a TRasterImage. The input vector image //!is transformed through the passed affine \b aff, and put into a //!TRasterImage strictly covering the bounding box of the transformed //!vector image. The output image has its lower-left position in the //!world reference specified by the \b pos parameter, which is granted to //!be an integer displacement of the passed value. Additional parameters //!include an integer \b enlarge by which the output image is enlarged with //!respect to the transformed image's bbox, and the bool \b transformThickness //!to specify whether the transformation should involve strokes' thickensses //!or not. TRasterImageP TRasterImageUtils::vectorToFullColorImage( const TVectorImageP &vimage, const TAffine &aff, TPalette *palette, const TPointD &outputPos, const TDimension &outputSize, const std::vector<TRasterFxRenderDataP> *fxs, bool transformThickness) { if (!vimage || !palette) return 0; //Transform the vector image through aff TVectorImageP vi = vimage->clone(); vi->transform(aff, transformThickness); //Allocate the output ToonzImage TRaster32P raster(outputSize.lx, outputSize.ly); raster->clear(); TRasterImageP ri(raster); ri->setPalette(palette->clone()); //Shift outputPos to the origin vi->transform(TTranslation(-outputPos)); int strokeCount = vi->getStrokeCount(); std::vector<int> strokeIndex(strokeCount); std::vector<TStroke *> strokes(strokeCount); int i; for (i = 0; i < strokeCount; ++i) { strokeIndex[i] = i; strokes[i] = vi->getStroke(i); } vi->notifyChangedStrokes(strokeIndex, strokes); int maxStyleId = palette->getStyleCount() - 1; for (i = 0; i < (int)vi->getRegionCount(); ++i) { TRegion *region = vi->getRegion(i); fastAddPaintRegion(ri, region, tmin(maxStyleId, region->getStyle()), maxStyleId); } set<int> colors; if (fxs) { for (i = 0; i < (int)fxs->size(); i++) { SandorFxRenderData *sandorData = dynamic_cast<SandorFxRenderData *>((*fxs)[i].getPointer()); if (sandorData && sandorData->m_type == BlendTz) { std::string indexes = toString(sandorData->m_blendParams.m_colorIndex); std::vector<std::string> items; parseIndexes(indexes, items); PaletteFilterFxRenderData paletteFilterData; insertIndexes(items, &paletteFilterData); colors = paletteFilterData.m_colors; break; } } } for (i = 0; i < strokeCount; ++i) { TStroke *stroke = vi->getStroke(i); bool visible = false; int styleId = stroke->getStyle(); TColorStyleP style = palette->getStyle(styleId); assert(style); int colorCount = style->getColorParamCount(); if (colorCount == 0) visible = true; else { visible = false; for (int j = 0; j < style->getColorParamCount() && !visible; j++) { TPixel32 color = style->getColorParamValue(j); if (color.m != 0) visible = true; } } if (visible) fastAddInkStroke(ri, stroke, TRectD(), 1, true); } return ri; }
void tglDraw(const TVectorRenderData &rd, const TStroke *s, bool pushAttribs) { assert(s); if (!s) return; TStrokeProp *prop = 0; bool pushedAttribs = false; try { TColorStyleP style; TStroke *stroke = const_cast<TStroke *>(s); if (rd.m_inkCheckEnabled && s->getStyle() == rd.m_colorCheckIndex) { static TSolidColorStyle *redColor = new TSolidColorStyle(); redColor->addRef(); redColor->setMainColor(TPixel::Red); style = redColor; } else if (rd.m_tcheckEnabled) { static TSolidColorStyle *color = new TSolidColorStyle(); color->addRef(); color->setMainColor(rd.m_tCheckInk); style = color; } else style = rd.m_palette->getStyle(stroke->getStyle()); if (!rd.m_show0ThickStrokes && isOThick(s) && dynamic_cast<TSolidColorStyle *>( style.getPointer()) // This is probably to exclude // TCenterlineStrokeStyle-like styles && !rd.m_tcheckEnabled) // I wonder why this? return; // const TStroke& stroke = *s; //serve??? assert(rd.m_palette); prop = s->getProp(/*rd.m_palette*/); /////questo codice stava dentro tstroke::getprop///////// if (prop) prop->getMutex()->lock(); if (!style->isStrokeStyle() || style->isEnabled() == false) { if (prop) prop->getMutex()->unlock(); prop = 0; } else { // Warning: the following pointers check is conceptually wrong - we // keep it because the props maintain SMART POINTER-like reference to // the associated style. This prevents the style from being destroyed // while still referenced by the prop. if (!prop || style.getPointer() != prop->getColorStyle()) { if (prop) prop->getMutex()->unlock(); stroke->setProp(style->makeStrokeProp(stroke)); prop = stroke->getProp(); if (prop) prop->getMutex()->lock(); } } //--------- draw ------------ if (!prop) return; if (pushAttribs) glPushAttrib(GL_ALL_ATTRIB_BITS), pushedAttribs = true; bool alphaChannel = rd.m_alphaChannel, antialias = rd.m_antiAliasing; TVectorImagePatternStrokeProp *aux = dynamic_cast<TVectorImagePatternStrokeProp *>(prop); if (aux) // gli image pattern vettoriali tornano in questa funzione....non // facendo il corpo dell'else'si evita di disegnarli due volte! prop->draw(rd); else { if (antialias) tglEnableLineSmooth(true); else tglEnableLineSmooth(false); if (alphaChannel) { GLboolean red, green, blue, alpha; tglGetColorMask(red, green, blue, alpha); // Draw RGB channels tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColorMask(red, green, blue, GL_FALSE); prop->draw(rd); // Draw Matte channel tglEnableBlending(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, alpha); prop->draw(rd); glColorMask(red, green, blue, alpha); } else { tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); prop->draw(rd); } } if (pushAttribs) glPopAttrib(), pushedAttribs = false; prop->getMutex()->unlock(); //--------------------- } catch (...) { if (prop) prop->getMutex()->unlock(); if (pushedAttribs) glPopAttrib(); } }
void tglDraw(const TVectorRenderData &rd, TRegion *r, bool pushAttribs) { checkErrorsByGL; assert(r); checkErrorsByGL; if (!r) return; bool alphaChannel = rd.m_alphaChannel; checkErrorsByGL; int j = 0; bool visible = false; int colorCount = 0; TColorStyleP style; if (rd.m_paintCheckEnabled && r->getStyle() == rd.m_colorCheckIndex) { static TSolidColorStyle *redColor = new TSolidColorStyle(); redColor->addRef(); redColor->setMainColor(TPixel::Red); style = redColor; } else if (rd.m_tcheckEnabled) { static TSolidColorStyle *color = new TSolidColorStyle(); color->addRef(); color->setMainColor(rd.m_tCheckPaint); style = color; } else style = rd.m_palette->getStyle(r->getStyle()); colorCount = style->getColorParamCount(); if (colorCount == 0) { // for example texture visible = true; } else { visible = false; for (j = 0; j < colorCount && !visible; j++) { TPixel32 color = style->getColorParamValue(j); if (rd.m_cf) color = (*(rd.m_cf))(color); if (color.m != 0) visible = true; } } if (visible) { TRegionProp *prop = r->getProp(/*rd.m_palette*/); /// questo codice satva dentro tregion::getprop///// int styleId = r->getStyle(); if (styleId) { // TColorStyle * style = rd.m_palette->getStyle(styleId); if (!style->isRegionStyle() || style->isEnabled() == false) { prop = 0; } else { // Warning: The same remark of stroke props holds here. if (!prop || style.getPointer() != prop->getColorStyle()) { r->setProp(style->makeRegionProp(r)); prop = r->getProp(); } } } ////// draw if (prop) { if (pushAttribs) glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableLineSmooth(true); //#define DRAW_EDGE_NUMBERS #ifdef DRAW_EDGE_NUMBERS glPushMatrix(); tglMultMatrix(rd.m_aff); switch (Index % 7) { case 0: tglColor(TPixel::Red); break; case 1: tglColor(TPixel::Green); break; case 2: tglColor(TPixel::Blue); break; case 3: tglColor(TPixel::Cyan); break; case 4: tglColor(TPixel::Magenta); break; case 5: tglColor(TPixel::Yellow); break; case 6: tglColor(TPixel::Black); break; default: tglColor(TPixel::Red); break; } Index++; if (rIndex == 2) { double y = r->getEdge(0) ->m_s ->getThickPoint( (r->getEdge(0)->m_w0 + r->getEdge(0)->m_w1) / 2.0) .y; tglDrawSegment(TPointD(-1000, y), TPointD(1000, y)); } for (int i = 0; i < (int)r->getEdgeCount(); i++) { TEdge *e = r->getEdge(i); TPointD p = e->m_s->getPoint(0.8 * e->m_w0 + 0.2 * e->m_w1); if (i == 0) tglDrawText(p, (QString::number(rIndex) + QString("-0")).toStdString()); else tglDrawText(p, QString::number(i).toStdString()); if (e->m_index == 3) { tglColor(TPixel::Black); TStroke *s = e->m_s; drawPoint(s->getChunk(0)->getP0(), .3); tglColor(TPixel::Red); tglDrawText(s->getChunk(0)->getP0(), QString::number(0).toStdString()); for (int ii = 0; ii < s->getChunkCount(); ii++) { drawPoint(s->getChunk(ii)->getP2(), .3); if (ii < s->getChunkCount() - 1) { tglColor(TPixel::Red); tglDrawText(s->getChunk(ii)->getP2(), QString::number(ii + 1).toStdString()); } } } } glPopMatrix(); #endif if (alphaChannel) { GLboolean red, green, blue, alpha; tglGetColorMask(red, green, blue, alpha); // Draw RGB channels tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColorMask(red, green, blue, GL_FALSE); prop->draw(rd); // Draw Matte channel tglEnableBlending(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, alpha); prop->draw(rd); glColorMask(red, green, blue, alpha); } else { // pezza: in render, le aree fillate dei custom styles sparivano. if (!rd.m_isOfflineRender || !rd.m_isImagePattern) tglRgbOnlyColorMask(); // RGB components only prop->draw(rd); } if (pushAttribs) glPopAttrib(); } } for (UINT i = 0; i < r->getSubregionCount(); i++) tglDraw(rd, r->getSubregion(i), pushAttribs); checkErrorsByGL; }