void WriteGlyphAsTGA(FT_Library &library, const std::string &fileName, wchar_t ch, FT_Face &face, int size, const Pixel32 &fontCol, const Pixel32 outlineCol, float outlineWidth) { // Set the size to use. if (FT_Set_Char_Size(face, size << 6, size << 6, 90, 90) == 0) { // Load the glyph we are looking for. FT_UInt gindex = FT_Get_Char_Index(face, ch); if (FT_Load_Glyph(face, gindex, FT_LOAD_NO_BITMAP) == 0) { // Need an outline for this to work. if (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) { // Render the basic glyph to a span list. Spans spans; RenderSpans(library, &face->glyph->outline, &spans); // Next we need the spans for the outline. Spans outlineSpans; // Set up a stroker. FT_Stroker stroker; FT_Stroker_New(library, &stroker); FT_Stroker_Set(stroker, (int)(outlineWidth * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); FT_Glyph glyph; if (FT_Get_Glyph(face->glyph, &glyph) == 0) { FT_Glyph_StrokeBorder(&glyph, stroker, 0, 1); // Again, this needs to be an outline to work. if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { // Render the outline spans to the span list FT_Outline *o = &reinterpret_cast<FT_OutlineGlyph>(glyph)->outline; RenderSpans(library, o, &outlineSpans); } // Clean up afterwards. FT_Stroker_Done(stroker); FT_Done_Glyph(glyph); // Now we need to put it all together. if (!spans.empty()) { // Figure out what the bounding rect is for both the span lists. Rect rect(spans.front().x, spans.front().y, spans.front().x, spans.front().y); for (Spans::iterator s = spans.begin(); s != spans.end(); ++s) { rect.Include(Vec2(s->x, s->y)); rect.Include(Vec2(s->x + s->width - 1, s->y)); } for (Spans::iterator s = outlineSpans.begin(); s != outlineSpans.end(); ++s) { rect.Include(Vec2(s->x, s->y)); rect.Include(Vec2(s->x + s->width - 1, s->y)); } #if 0 // This is unused in this test but you would need this to draw // more than one glyph. float bearingX = face->glyph->metrics.horiBearingX >> 6; float bearingY = face->glyph->metrics.horiBearingY >> 6; float advance = face->glyph->advance.x >> 6; #endif // Get some metrics of our image. int imgWidth = rect.Width(), imgHeight = rect.Height(), imgSize = imgWidth * imgHeight; // Allocate data for our image and clear it out to transparent. Pixel32 *pxl = new Pixel32[imgSize]; memset(pxl, 0, sizeof(Pixel32) * imgSize); // Loop over the outline spans and just draw them into the // image. for (Spans::iterator s = outlineSpans.begin(); s != outlineSpans.end(); ++s) for (int w = 0; w < s->width; ++w) pxl[(int)((imgHeight - 1 - (s->y - rect.ymin)) * imgWidth + s->x - rect.xmin + w)] = Pixel32(outlineCol.r, outlineCol.g, outlineCol.b, s->coverage); // Then loop over the regular glyph spans and blend them into // the image. for (Spans::iterator s = spans.begin(); s != spans.end(); ++s) for (int w = 0; w < s->width; ++w) { Pixel32 &dst = pxl[(int)((imgHeight - 1 - (s->y - rect.ymin)) * imgWidth + s->x - rect.xmin + w)]; Pixel32 src = Pixel32(fontCol.r, fontCol.g, fontCol.b, s->coverage); dst.r = (int)(dst.r + ((src.r - dst.r) * src.a) / 255.0f); dst.g = (int)(dst.g + ((src.g - dst.g) * src.a) / 255.0f); dst.b = (int)(dst.b + ((src.b - dst.b) * src.a) / 255.0f); dst.a = MIN(255, dst.a + src.a); } // Dump the image to disk. WriteTGA(fileName, pxl, imgWidth, imgHeight); delete [] pxl; } }
void DivNode::preRender(const VertexArrayPtr& pVA, bool bIsParentActive, float parentEffectiveOpacity) { AreaNode::preRender(pVA, bIsParentActive, parentEffectiveOpacity); if (getCrop() && getSize() != glm::vec2(0,0)) { pVA->startSubVA(m_ClipVA); glm::vec2 viewport = getSize(); m_ClipVA.appendPos(glm::vec2(0,0), glm::vec2(0,0), Pixel32(0,0,0,0)); m_ClipVA.appendPos(glm::vec2(0,viewport.y), glm::vec2(0,0), Pixel32(0,0,0,0)); m_ClipVA.appendPos(glm::vec2(viewport.x,0), glm::vec2(0,0), Pixel32(0,0,0,0)); m_ClipVA.appendPos(viewport, glm::vec2(0,0), Pixel32(0,0,0,0)); m_ClipVA.appendQuadIndexes(0, 1, 2, 3); } for (unsigned i = 0; i < getNumChildren(); i++) { m_Children[i]->preRender(pVA, bIsParentActive, getEffectiveOpacity()); } }
void AreaNode::setElementOutlineColor(const std::string& sColor) { m_sElementOutlineColor = sColor; if (sColor == "") { m_ElementOutlineColor = Pixel32(0,0,0,0); } else { m_ElementOutlineColor = colorStringToColor(m_sElementOutlineColor); } }
Pixel32 colorStringToColor(const UTF8String& s) { int r, g, b; int numChars; int numItems = sscanf(s.c_str(), "%2x%2x%2x%n", &r, &g, &b, &numChars); if (s.length() != 6 || numChars != 6 || numItems != 3) { throw(Exception (AVG_ERR_INVALID_ARGS, "colorstring cannot be parsed.")); } return Pixel32(r, g, b); }
void DivNode::render() { glm::vec2 viewport = getSize(); m_pClipVertexes->reset(); m_pClipVertexes->appendPos(glm::vec2(0,0), glm::vec2(0,0), Pixel32(0,0,0,0)); m_pClipVertexes->appendPos(glm::vec2(0,viewport.y), glm::vec2(0,0), Pixel32(0,0,0,0)); m_pClipVertexes->appendPos(glm::vec2(viewport.x,0), glm::vec2(0,0), Pixel32(0,0,0,0)); m_pClipVertexes->appendPos(viewport, glm::vec2(0,0), Pixel32(0,0,0,0)); m_pClipVertexes->appendQuadIndexes(0, 1, 2, 3); if (getCrop()) { getCanvas()->pushClipRect(getTransform(), m_pClipVertexes); } for (unsigned i = 0; i < getNumChildren(); i++) { getChild(i)->maybeRender(); } if (getCrop()) { glLoadMatrixf(glm::value_ptr(getTransform())); getCanvas()->popClipRect(getTransform(), m_pClipVertexes); } }
void AreaNode::renderOutlines(const VertexArrayPtr& pVA, Pixel32 parentColor) { Pixel32 effColor = getEffectiveOutlineColor(parentColor); if (effColor != Pixel32(0,0,0,0)) { glm::vec2 size = getSize(); glm::vec2 p0 = getAbsPos(glm::vec2(0.5, 0.5)); glm::vec2 p1 = getAbsPos(glm::vec2(size.x+0.5,0.5)); glm::vec2 p2 = getAbsPos(glm::vec2(size.x+0.5,size.y+0.5)); glm::vec2 p3 = getAbsPos(glm::vec2(0.5,size.y+0.5)); pVA->addLineData(effColor, p0, p1, 1); pVA->addLineData(effColor, p1, p2, 1); pVA->addLineData(effColor, p2, p3, 1); pVA->addLineData(effColor, p3, p0, 1); } }
void Canvas::renderOutlines(GLContext* pContext, const glm::mat4& transform) { VertexArrayPtr pVA = GLContextManager::get()->createVertexArray(); pVA->initForGLContext(pContext); pContext->setBlendMode(GLContext::BLEND_BLEND, false); m_pRootNode->renderOutlines(pVA, Pixel32(0,0,0,0)); StandardShader* pShader = pContext->getStandardShader(); pShader->setTransform(transform); pShader->setUntextured(); pShader->setAlpha(0.5f); pShader->activate(); if (pVA->getNumVerts() != 0) { pVA->draw(pContext); } }
void Canvas::renderOutlines(const glm::mat4& transform) { GLContext* pContext = GLContext::getMain(); VertexArrayPtr pVA(new VertexArray); pContext->setBlendMode(GLContext::BLEND_BLEND, false); m_pRootNode->renderOutlines(pVA, Pixel32(0,0,0,0)); StandardShaderPtr pShader = pContext->getStandardShader(); pShader->setTransform(transform); pShader->setUntextured(); pShader->setAlpha(0.5f); pShader->activate(); if (pVA->getNumVerts() != 0) { pVA->update(); pVA->draw(); } }
void Canvas::renderOutlines() { GLContext* pContext = GLContext::getCurrent(); VertexArrayPtr pVA(new VertexArray); pContext->setBlendMode(GLContext::BLEND_BLEND, false); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(glm::value_ptr(glm::mat4(1.0))); m_pRootNode->renderOutlines(pVA, Pixel32(0,0,0,0)); StandardShaderPtr pShader = GLContext::getCurrent()->getStandardShader(); pShader->setUntextured(); pShader->activate(); if (pVA->getCurVert() != 0) { pVA->update(); pContext->enableGLColorArray(true); pVA->draw(); } }
void TrackerThread::drawBlobs(BlobVectorPtr pBlobs, BitmapPtr pSrcBmp, BitmapPtr pDestBmp, int Offset, bool bTouch) { if (!pDestBmp) { return; } ScopeTimer timer(ProfilingZoneDraw); string sConfigPrefix; if (bTouch) { sConfigPrefix = "/tracker/touch/"; } else { sConfigPrefix = "/tracker/track/"; } int minArea = m_pConfig->getIntParam(sConfigPrefix+"areabounds/@min"); int maxArea = m_pConfig->getIntParam(sConfigPrefix+"areabounds/@max"); float minEccentricity = m_pConfig->getFloatParam( sConfigPrefix+"eccentricitybounds/@min"); float maxEccentricity = m_pConfig->getFloatParam( sConfigPrefix+"eccentricitybounds/@max"); // Get max. pixel value in Bitmap int max = 0; HistogramPtr pHist = pSrcBmp->getHistogram(4); int i; for (i = 255; i >= 0; i--) { if ((*pHist)[i] != 0) { max = i; i = 0; } } for (BlobVector::iterator it2 = pBlobs->begin(); it2 != pBlobs->end(); ++it2) { if (isRelevant(*it2, minArea, maxArea, minEccentricity, maxEccentricity)) { if (bTouch) { (*it2)->render(pSrcBmp, pDestBmp, Pixel32(0xFF, 0xFF, 0xFF, 0xFF), Offset, max, bTouch, true, Pixel32(0x00, 0x00, 0xFF, 0xFF)); } else { (*it2)->render(pSrcBmp, pDestBmp, Pixel32(0xFF, 0xFF, 0x00, 0x80), Offset, max, bTouch, true, Pixel32(0x00, 0x00, 0xFF, 0xFF)); } } else { if (bTouch) { (*it2)->render(pSrcBmp, pDestBmp, Pixel32(0xFF, 0x00, 0x00, 0xFF), Offset, max, bTouch, false); } else { (*it2)->render(pSrcBmp, pDestBmp, Pixel32(0x80, 0x80, 0x00, 0x80), Offset, max, bTouch, false); } } } }
void DivNode::renderOutlines(const VertexArrayPtr& pVA, Pixel32 parentColor) { Pixel32 effColor = getEffectiveOutlineColor(parentColor); if (effColor != Pixel32(0,0,0,0)) { glm::vec2 size = getSize(); if (size == glm::vec2(0,0)) { glm::vec2 p0 = getAbsPos(glm::vec2(-4, 0.5)); glm::vec2 p1 = getAbsPos(glm::vec2(5, 0.5)); glm::vec2 p2 = getAbsPos(glm::vec2(0.5, -4)); glm::vec2 p3 = getAbsPos(glm::vec2(0.5, 5)); pVA->addLineData(effColor, p0, p1, 1); pVA->addLineData(effColor, p2, p3, 1); } else { AreaNode::renderOutlines(pVA, parentColor); } } for (unsigned i = 0; i < getNumChildren(); i++) { getChild(i)->renderOutlines(pVA, effColor); } }
void CameraNode::open() { m_pCamera->startCapture(); setViewport(-32767, -32767, -32767, -32767); PixelFormat pf = getPixelFormat(); IntPoint size = getMediaSize(); bool bMipmap = getMaterial().getUseMipmaps(); m_pTex = GLTexturePtr(new GLTexture(size, pf, bMipmap)); m_pTex->enableStreaming(); getSurface()->create(pf, m_pTex); BitmapPtr pBmp = m_pTex->lockStreamingBmp(); if (pf == B8G8R8X8 || pf == B8G8R8A8) { FilterFill<Pixel32> Filter(Pixel32(0,0,0,255)); Filter.applyInPlace(pBmp); } else if (pf == I8) { FilterFill<Pixel8> Filter(0); Filter.applyInPlace(pBmp); } m_pTex->unlockStreamingBmp(true); setupFX(true); }
void CameraNode::preRender() { Node::preRender(); if (isAutoUpdateCameraImage()) { ScopeTimer Timer(CameraFetchImage); updateToLatestCameraImage(); } if (m_bNewBmp && isVisible()) { ScopeTimer Timer(CameraDownloadProfilingZone); m_FrameNum++; BitmapPtr pBmp = m_pTex->lockStreamingBmp(); if (pBmp->getPixelFormat() != m_pCurBmp->getPixelFormat()) { cerr << "Surface: " << pBmp->getPixelFormat() << ", CamDest: " << m_pCurBmp->getPixelFormat() << endl; } AVG_ASSERT(pBmp->getPixelFormat() == m_pCurBmp->getPixelFormat()); pBmp->copyPixels(*m_pCurBmp); m_pTex->unlockStreamingBmp(true); bind(); renderFX(getSize(), Pixel32(255, 255, 255, 255), false); m_bNewBmp = false; } }
Pixel32 Image32::NearestSample(const float& x,const float& y) const { return Pixel32(); }
Color::operator Pixel32() const { return Pixel32(m_R, m_G, m_B); }
Pixel32 Image32::BilinearSample(const float& x,const float& y) const { return Pixel32(); }
Pixel32 Image32::GaussianSample(const float& x,const float& y,const float& variance,const float& radius) const { return Pixel32(); }
void VideoWriter::writeDummyFrame() { BitmapPtr pBmp = BitmapPtr(new Bitmap(m_FrameSize, B8G8R8X8)); FilterFill<Pixel32>(Pixel32(0,0,0,255)).applyInPlace(pBmp); sendFrameToEncoder(pBmp); }