void FilterWipeBorder::applyInPlace(BitmapPtr pBmp) { AVG_ASSERT(pBmp->getPixelFormat() == I8); if (m_NumPixels != 0) { int stride = pBmp->getStride(); unsigned char * pPixels = pBmp->getPixels(); IntPoint size = pBmp->getSize(); IntPoint activeSize = pBmp->getSize()-IntPoint(2*m_NumPixels, 2*m_NumPixels); unsigned char * pSrcLine = pPixels+stride*m_NumPixels+m_NumPixels; for (int y = m_NumPixels-1; y >= 0; --y) { memcpy(pPixels+stride*y+m_NumPixels, pSrcLine, activeSize.x); } pSrcLine = pPixels+stride*(size.y-m_NumPixels-1)+m_NumPixels; for (int y = size.y-m_NumPixels; y < size.y; ++y) { memcpy(pPixels+stride*y+m_NumPixels, pSrcLine, activeSize.x); } for (int y = 0; y < size.y; ++y) { unsigned char src = *(pPixels+stride*y+m_NumPixels); memset(pPixels+stride*y, src, m_NumPixels); src = *(pPixels+stride*y+size.x-m_NumPixels-1); memset(pPixels+stride*y+size.x-m_NumPixels, src, m_NumPixels); } } }
void runFilterTests(bool bUseFloat) { BitmapPtr pBmp; GPUBlurFilterPtr pFilter; pBmp = loadTestBmp("spike"); PixelFormat destPF; if (bUseFloat) { destPF = R32G32B32A32F; } else { destPF = B8G8R8A8; } pFilter = GPUBlurFilterPtr(new GPUBlurFilter(pBmp->getSize(), pBmp->getPixelFormat(), destPF, 0.5f, false)); runImageTest(pBmp, pFilter, 0.5f, "blur05_spike"); runImageTest(pBmp, pFilter, 1, "blur1_spike"); runImageTest(pBmp, pFilter, 3, "blur3_spike"); pBmp = loadTestBmp("flat"); pFilter = GPUBlurFilterPtr(new GPUBlurFilter(pBmp->getSize(), pBmp->getPixelFormat(), destPF, 5, false)); runImageTest(pBmp, pFilter, 5, "blur05_flat", true); runImageTest("rgb24-64x64", destPF); runImageTest("rgb24alpha-64x64", destPF); }
void runTestWithBitmap(BitmapPtr pBmp) { BitmapPtr pDestBmp = FilterResizeBilinear(IntPoint(32,32)).apply(pBmp); string sName = string("ResizeBilinearResult") +getPixelFormatString(pBmp->getPixelFormat()); testEqual(*pDestBmp, sName, pBmp->getPixelFormat()); }
void Image::setFilename(const std::string& sFilename, TextureCompression comp) { assertValid(); AVG_TRACE(Logger::category::MEMORY, Logger::severity::INFO, "Loading " << sFilename); BitmapPtr pBmp = loadBitmap(sFilename); if (comp == TEXTURECOMPRESSION_B5G6R5 && pBmp->hasAlpha()) { throw Exception(AVG_ERR_UNSUPPORTED, "B5G6R5-compressed textures with an alpha channel are not supported."); } changeSource(FILE); m_pBmp = pBmp; m_sFilename = sFilename; switch (comp) { case TEXTURECOMPRESSION_B5G6R5: m_pBmp = BitmapPtr(new Bitmap(pBmp->getSize(), B5G6R5, sFilename)); if (!BitmapLoader::get()->isBlueFirst()) { FilterFlipRGB().applyInPlace(pBmp); } m_pBmp->copyPixels(*pBmp); break; case TEXTURECOMPRESSION_NONE: break; default: assert(false); } if (m_State == GPU) { m_pSurface->destroy(); setupSurface(); } assertValid(); }
void runImageTest(const string& sFName, PixelFormat destPF) { BitmapPtr pBmp = loadTestBmp(sFName); GPUBlurFilterPtr pFilter(new GPUBlurFilter(pBmp->getSize(), pBmp->getPixelFormat(), destPF, 2, false)); runImageTest(pBmp, pFilter, 2, string("blur_")+sFName, true); }
void runTests() { BitmapPtr pBmp = loadTestBmp("chromakey"); BitmapPtr pDestBmp; GPUChromaKeyFilter filter(pBmp->getSize()); for (int erosion = 0; erosion < 3; ++erosion) { filter.setParams(Pixel32(0,255,0), 0.1, 0.2, 0.1, 0.1, erosion, 0); pDestBmp = filter.apply(pBmp); testEqual(*pDestBmp, "ChromaKeyResult"+toString(erosion), B8G8R8A8, 0.3, 0.7); } filter.setParams(Pixel32(0,255,0), 0.0, 0.0, 0.0, 0.0, 0, 0.1); pDestBmp = filter.apply(pBmp); testEqual(*pDestBmp, "ChromaKeySpillResult1", B8G8R8A8, 0.3, 0.7); filter.setParams(Pixel32(0,255,0), 0.1, 0.1, 0.1, 0.0, 0, 0.1); pDestBmp = filter.apply(pBmp); testEqual(*pDestBmp, "ChromaKeySpillResult2", B8G8R8A8, 0.3, 0.7); filter.setParams(Pixel32(0,255,0), 0.1, 0.1, 0.1, 0.0, 0, 0.2); pDestBmp = filter.apply(pBmp); testEqual(*pDestBmp, "ChromaKeySpillResult3", B8G8R8A8, 0.3, 0.7); pBmp = loadTestBmp("chromakey-median"); filter.setParams(Pixel32(0,255,0), 0.1, 0.1, 0.1, 0.0, 0, 0.0); pDestBmp = filter.apply(pBmp); testEqual(*pDestBmp, "ChromaKeyMedianResult", B8G8R8A8, 1, 6); }
void GraphicsTest::testEqual(Bitmap& resultBmp, Bitmap& baselineBmp, const string& sFName, float maxAverage, float maxStdDev) { BitmapPtr pDiffBmp; try { pDiffBmp = resultBmp.subtract(baselineBmp); } catch (Exception& e) { TEST_FAILED("Error: " << e.getStr() << ". File: '" << sFName << "'."); string sResultName = "resultimages/"+sFName; resultBmp.save(sResultName+".png"); baselineBmp.save(sResultName+"_baseline.png"); } if (pDiffBmp) { float average = pDiffBmp->getAvg(); float stdDev = pDiffBmp->getStdDev(); if (average > maxAverage || stdDev > maxStdDev) { TEST_FAILED("Error: Decoded image differs from baseline '" << sFName << "'. average=" << average << ", stdDev=" << stdDev); // resultBmp.dump(); // baselineBmp.dump(); string sResultName = "resultimages/"+sFName; resultBmp.save(sResultName+".png"); baselineBmp.save(sResultName+"_baseline.png"); BitmapPtr pDiffBmp = resultBmp.subtract(baselineBmp); pDiffBmp->save(sResultName+"_diff.png"); } } }
void runMipmapTest(OGLMemoryMode memoryMode, const string& sFName) { cerr << " Testing mipmap support, " << sFName << ", " << oglMemoryMode2String(memoryMode) << endl; BitmapPtr pOrigBmp = loadTestBmp(sFName); GLContextManager* pCM = GLContextManager::get(); MCTexturePtr pTex = pCM->createTextureFromBmp(pOrigBmp, true); pCM->uploadData(); pTex->generateMipmaps(); if (GLContext::getCurrent()->isGLES()) { // GLES doesn't support attaching texture mipmap levels other than 0 to // FBOs, so moveTextureToBmp() will fail. Skip result image comparison. return; } BitmapPtr pResultBmp = pTex->moveTextureToBmp(1); IntPoint newSize(pOrigBmp->getSize()/2); TEST(pResultBmp->getSize() == newSize); FilterResizeBilinear resizer(newSize); BitmapPtr pBaselineBmp = resizer.apply(pOrigBmp); string sName; if (memoryMode == MM_PBO) { sName = "pbo-mipmap"; } else { sName = "ogl-mipmap"; } testEqual(*pResultBmp, *pBaselineBmp, sName, 7, 15); }
void CChildView::OnPaint() { CPaintDC dc(this); // device context for painting // If the unbounded_buffer object contains a Bitmap object, // draw the image to the client area. BitmapPtr pBitmap; if (try_receive(m_MandelbrotImages, pBitmap)) { if (pBitmap != NULL) { // Draw the bitmap to the client area. Graphics g(dc); g.DrawImage(pBitmap.get(), 0, 0); } } // Draw the image on a worker thread if the image is not available. else { RECT rc; GetClientRect(&rc); m_DrawingTasks.run([rc,this]() { DrawMandelbrot(BitmapPtr(new Bitmap(rc.right, rc.bottom))); }); } }
void runTests() { BitmapPtr pBmp = BitmapPtr(new Bitmap(IntPoint(16,16), I8)); FilterFill<Pixel8>(0).applyInPlace(pBmp); *(pBmp->getPixels()+pBmp->getStride()*7+7) = 255; BitmapPtr pDestBmp = FilterBlur().apply(pBmp); testEqual(*pDestBmp, "BlurResult", I8); }
void runSaveTest(PixelFormat pf) { cerr << " Testing save for " << pf << endl; BitmapPtr pBmp = initBmp(pf); pBmp->save("test.png"); BitmapPtr pLoadedBmp = loadBitmap("test.png"); ::remove("test.png"); testEqual(*pLoadedBmp, *pBmp, "BmpSave"); }
void runTests() { BitmapPtr pBmp = BitmapPtr(new Bitmap(IntPoint(4,4), I8)); FilterFill<Pixel8>(0).applyInPlace(pBmp); *(pBmp->getPixels()+pBmp->getStride()*3+3) = 252; BitmapPtr pDestBmp = FilterFastDownscale(2).apply(pBmp); testEqual(*pDestBmp, "FastDownscaleResult", I8); }
void VideoWriterThread::convertRGBImage(BitmapPtr pSrcBmp) { ScopeTimer timer(ProfilingZoneConvertImage); unsigned char* rgbData[3] = {pSrcBmp->getPixels(), NULL, NULL}; int rgbStride[3] = {pSrcBmp->getLineLen(), 0, 0}; sws_scale(m_pFrameConversionContext, rgbData, rgbStride, 0, m_Size.y, m_pConvertedFrame->data, m_pConvertedFrame->linesize); }
void runImageTests(const string& sFName, PixelFormat pf) { cerr << " Testing " << sFName << endl; BitmapPtr pBmp = loadTestBmp(sFName, pf); GPUBandpassFilter f(pBmp->getSize(), pf, 0.5, 1.5, 1, false); BitmapPtr pDestBmp = f.apply(pBmp); TEST(fabs(pDestBmp->getAvg() -128) < 0.06); testEqual(*pDestBmp, "bandpass_"+sFName, pf, 0.2, 0.5); TEST(pDestBmp->getPixelFormat() == pf); }
void runImageTest(BitmapPtr pBmp, GPUBlurFilterPtr pFilter, float stdDev, string sBmpName, bool bIgnoreBrightness = false) { cerr << " Testing " << sBmpName << ", stddev " << stdDev << endl; pFilter->setStdDev(stdDev); BitmapPtr pDestBmp = pFilter->apply(pBmp); if (!bIgnoreBrightness) { testEqualBrightness(*pDestBmp, *pBmp, 0.03); } testEqual(*pDestBmp, sBmpName, pDestBmp->getPixelFormat(), 0.1, 0.3); }
void initBmp(BitmapPtr pBmp) { PIXEL * pPixels = (PIXEL *)(pBmp->getPixels()); PIXEL color = PIXEL(0,0,0); FilterFill<PIXEL>(color).applyInPlace(pBmp); pPixels[0] = PIXEL(1,0,0); pPixels[3] = PIXEL(2,0,0); pPixels = (PIXEL*)((char *)pPixels+3*pBmp->getStride()); pPixels[0] = PIXEL(0,0,3); pPixels[3] = PIXEL(0,0,4); }
BitmapPtr VideoDecoderThread::getBmp(BitmapQueuePtr pBmpQ, const IntPoint& size, PixelFormat pf) { BitmapPtr pBmp = pBmpQ->pop(false); if (pBmp) { AVG_ASSERT (pBmp->getSize() == size && pBmp->getPixelFormat() == pf); return pBmp; } else { return BitmapPtr(new Bitmap(size, pf)); } }
Sprite::Sprite(BitmapPtr pBitmap) { m_pBitmap = pBitmap; SetRect(&m_rcPosition, 0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); m_ptVelocity.x = m_ptVelocity.y = 0; m_iZOrder = 0; SetRect(&m_rcBounds, 0, 0, 640, 480); m_baBoundsAction = BA_STOP; m_bHidden = FALSE; CalcCollisionRec(); }
void testStatistics(PixelFormat pf, const PIXEL& p00, const PIXEL& p01, const PIXEL& p10, const PIXEL& p11, float avg=1, float stdDev=1) { BitmapPtr pBmp = BitmapPtr(new Bitmap(IntPoint(2,2), pf)); pBmp->setPixel(IntPoint(0,0), p00); pBmp->setPixel(IntPoint(0,1), p01); pBmp->setPixel(IntPoint(1,0), p10); pBmp->setPixel(IntPoint(1,1), p11); TEST(almostEqual(pBmp->getAvg(), avg, 0.001)); TEST(almostEqual(pBmp->getStdDev(), stdDev, 0.001)); }
BitmapPtr Camera::convertCamFrameToDestPF(BitmapPtr pCamBmp) { ScopeTimer Timer(CameraConvertProfilingZone); BitmapPtr pDestBmp = BitmapPtr(new Bitmap(pCamBmp->getSize(), m_DestPF)); pDestBmp->copyPixels(*pCamBmp); if (m_CamPF == R8G8B8 && m_DestPF == B8G8R8X8) { pDestBmp->setPixelFormat(R8G8B8X8); FilterFlipRGB().applyInPlace(pDestBmp); } return pDestBmp; }
void runTests() { BitmapPtr pOrigBmp = loadTestBmp("rgb24-64x64"); GLContextManager* pCM = GLContextManager::get(); MCTexturePtr pTex = pCM->createTextureFromBmp(pOrigBmp); pCM->uploadData(); GPURGB2YUVFilter f(pOrigBmp->getSize()); f.apply(pTex->getCurTex()); BitmapPtr pResultBmp = f.getResults(); pResultBmp = convertYUVX444ToRGB(pResultBmp); testEqual(*pResultBmp, *pOrigBmp, "RGB2YUV", 1, 2); }
static Color Sample(const BitmapPtr bitmap, float u, float v) { u32 width = bitmap->GetWidth(); u32 height = bitmap->GetHeight(); float fx = XAddresserType::CalcAddress(u, width); int x = XAddresserType::FixAddress(Mathf::RoundToInt(fx), width); float fy = YAddresserType::CalcAddress(v, height); int y = YAddresserType::FixAddress(Mathf::RoundToInt(fy), height); return bitmap->GetColor(x, y); }
bool ConvertStreamToBitmap( const ResourceType& resourceType, std::string path, FILE * const fp, const ResourceLoadingClient& client, BitmapPtr& ptr ) { DALI_LOG_TRACE_METHOD( gLogFilter ); DALI_ASSERT_DEBUG( ResourceBitmap == resourceType.id ); bool result = false; BitmapPtr bitmap = 0; if (fp != NULL) { LoadBitmapFunction function; LoadBitmapHeaderFunction header; Bitmap::Profile profile; if ( GetBitmapLoaderFunctions( fp, GetFormatHint( path ), function, header, profile ) ) { bitmap = Bitmap::New( profile, ResourcePolicy::OWNED_DISCARD ); DALI_LOG_SET_OBJECT_STRING( bitmap, path ); const BitmapResourceType& resType = static_cast<const BitmapResourceType&>( resourceType ); const ScalingParameters scalingParameters( resType.size, resType.scalingMode, resType.samplingMode ); const ImageLoader::Input input( fp, scalingParameters, resType.orientationCorrection ); // Check for cancellation now we have hit the filesystem, done some allocation, and burned some cycles: // This won't do anything from synchronous API, it's only useful when called from another thread. client.InterruptionPoint(); // Note: By design, this can throw an exception // Run the image type decoder: result = function( client, input, *bitmap ); if (!result) { DALI_LOG_WARNING( "Unable to convert %s\n", path.c_str() ); bitmap = 0; } // Apply the requested image attributes if not interrupted: client.InterruptionPoint(); // Note: By design, this can throw an exception bitmap = Internal::Platform::ApplyAttributesToBitmap( bitmap, resType.size, resType.scalingMode, resType.samplingMode ); } else { DALI_LOG_WARNING( "Image Decoder for %s unavailable\n", path.c_str() ); } } ptr.Reset( bitmap.Get() ); return result; }
void runCompressionTest(OGLMemoryMode memoryMode, const string& sFName) { cerr << " Testing B5G6R5 compression, " << sFName << ", " << oglMemoryMode2String(memoryMode) << endl; BitmapPtr pFileBmp = loadTestBmp(sFName); BitmapPtr pOrigBmp(new Bitmap(pFileBmp->getSize(), B5G6R5)); pOrigBmp->copyPixels(*pFileBmp); GLContextManager* pCM = GLContextManager::get(); MCTexturePtr pTex = pCM->createTextureFromBmp(pOrigBmp); pCM->uploadData(); BitmapPtr pDestBmp = pTex->moveTextureToBmp(); }
Sprite::Sprite(BitmapPtr pBitmap, POINT ptPosition, POINT ptVelocity, int iZOrder, RECT& rcBounds, BOUNDSACTION baBoundsAction) { m_pBitmap = pBitmap; SetRect(&m_rcPosition, ptPosition.x, ptPosition.y, ptPosition.x + pBitmap->GetWidth(), ptPosition.y + pBitmap->GetHeight()); m_ptVelocity = ptVelocity; m_iZOrder = iZOrder; CopyRect(&m_rcBounds, &rcBounds); m_baBoundsAction = baBoundsAction; m_bHidden = FALSE; CalcCollisionRec(); }
void BmpTextureMover::moveBmpToTexture(BitmapPtr pBmp, GLTexture& tex) { AVG_ASSERT(pBmp->getSize() == tex.getSize()); AVG_ASSERT(getSize() == pBmp->getSize()); AVG_ASSERT(pBmp->getPixelFormat() == getPF()); tex.activate(); unsigned char * pStartPos = pBmp->getPixels(); IntPoint size = tex.getSize(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size.x, size.y, tex.getGLFormat(getPF()), tex.getGLType(getPF()), pStartPos); tex.generateMipmaps(); GLContext::checkError("BmpTextureMover::moveBmpToTexture: glTexSubImage2D()"); }
void runTests() { BitmapPtr pBaseBmp = initBmp(I8); BitmapPtr pBmp = BitmapPtr(new Bitmap(*pBaseBmp)); BitmapPtr nullBmp = FilterFill<Pixel8>(0).apply(pBmp); pBmp->copyPixels(*pBaseBmp); HistoryPreProcessor filt(pBaseBmp->getSize(), 1, true); pBmp = filt.apply(pBaseBmp); testEqual(*pBmp, *nullBmp, "HistoryPreprocessor1"); for(int i=0;i<1;i++){ pBmp = filt.apply(pBaseBmp); testEqual(*pBmp, *nullBmp, "HistoryPreprocessor2"); } }
BitmapPtr OffscreenCanvas::screenshot(bool bIgnoreAlpha) const { if (!isRunning() || !m_bIsRendered) { throw(Exception(AVG_ERR_UNSUPPORTED, "OffscreenCanvas::screenshot(): Canvas has not been rendered. No screenshot available")); } BitmapPtr pBmp = m_pFBO->getImage(0); if (bIgnoreAlpha) { pBmp->setPixelFormat(B8G8R8X8); } else { FilterUnmultiplyAlpha().applyInPlace(pBmp); } return pBmp; }
void runTests() { BitmapPtr pBmp = BitmapPtr(new Bitmap(IntPoint(16,16), I8)); FilterFill<Pixel8>(0).applyInPlace(pBmp); *(pBmp->getPixels()+pBmp->getStride()*7+7) = 255; BitmapPtr pDestBmp = FilterGauss(3).apply(pBmp); testEqual(*pDestBmp, "Gauss3Result", I8); pDestBmp = FilterGauss(1).apply(pBmp); testEqual(*pDestBmp, "Gauss1Result", I8); pDestBmp = FilterGauss(1.5).apply(pBmp); testEqual(*pDestBmp, "Gauss15Result", I8); pDestBmp = FilterGauss(5).apply(pBmp); testEqual(*pDestBmp, "Gauss5Result", I8); }
Sprite::Sprite(BitmapPtr pBitmap, RECT& rcBounds, BOUNDSACTION baBoundsAction) { int iXPos = rand() % (rcBounds.right - rcBounds.left); int iYPos = rand() % (rcBounds.bottom - rcBounds.top); m_pBitmap = pBitmap; SetRect(&m_rcPosition, iXPos, iYPos, iXPos + pBitmap->GetWidth(), iYPos + pBitmap->GetHeight()); m_ptVelocity.x = m_ptVelocity.y = 0; m_iZOrder = 0; CopyRect(&m_rcBounds, &rcBounds); m_baBoundsAction = baBoundsAction; m_bHidden = FALSE; CalcCollisionRec(); }