MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / getColorAtRect

Method getColorAtRect

Gui/ViewerGL.cpp:4467–4657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4465} // getColorAt
4466
4467bool
4468ViewerGL::getColorAtRect(const RectD &rect, // rectangle in canonical coordinates
4469 bool forceLinear,
4470 int textureIndex,
4471 float* r,
4472 float* g,
4473 float* b,
4474 float* a,
4475 unsigned int* imgMm)
4476{
4477 // always running in the main thread
4478 assert( qApp && qApp->thread() == QThread::currentThread() );
4479 assert(r && g && b && a);
4480 assert(textureIndex == 0 || textureIndex == 1);
4481
4482 unsigned int mipMapLevel = (unsigned int)getMipMapLevelCombinedToZoomFactor();
4483 ImagePtr image = getLastRenderedImageByMipMapLevel(textureIndex, mipMapLevel);
4484
4485 if (image) {
4486 mipMapLevel = image->getMipMapLevel();
4487 *imgMm = mipMapLevel;
4488 }
4489
4490 ///Convert to pixel coords
4491 RectI rectPixel;
4492 rectPixel.x1 = int( std::floor( rect.left() ) ) >> mipMapLevel;
4493 rectPixel.y1 = int( std::floor( rect.bottom() ) ) >> mipMapLevel;
4494 rectPixel.x2 = int( std::floor( rect.right() ) ) >> mipMapLevel;
4495 rectPixel.y2 = int( std::floor( rect.top() ) ) >> mipMapLevel;
4496 assert( rect.bottom() <= rect.top() && rect.left() <= rect.right() );
4497 assert( rectPixel.y1 <= rectPixel.y2 && rectPixel.x1 <= rectPixel.x2 );
4498 double rSum = 0.;
4499 double gSum = 0.;
4500 double bSum = 0.;
4501 double aSum = 0.;
4502 if (!image) {
4503 return false;
4504 //don't do this as this is 8 bit
4505 /*
4506 Texture::DataTypeEnum type;
4507 if (_imp->displayTextures[0]) {
4508 type = _imp->displayTextures[0]->type();
4509 } else if (_imp->displayTextures[1]) {
4510 type = _imp->displayTextures[1]->type();
4511 } else {
4512 return false;
4513 }
4514
4515 if ( (type == Texture::eDataTypeByte) ) {
4516 std::vector<U32> pixels(rectPixel.width() * rectPixel.height());
4517 glReadBuffer(GL_FRONT);
4518 glReadPixels(rectPixel.left(), rectPixel.right(), rectPixel.width(), rectPixel.height(),
4519 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &pixels.front());
4520 double rF,gF,bF,aF;
4521 for (U32 i = 0 ; i < pixels.size(); ++i) {
4522 U8 red = 0, green = 0, blue = 0, alpha = 0;
4523 blue |= pixels[i];
4524 green |= (pixels[i] >> 8);

Callers

nothing calls this directly

Calls 11

lutFromColorspaceFunction · 0.85
floorFunction · 0.50
getMipMapLevelMethod · 0.45
leftMethod · 0.45
bottomMethod · 0.45
rightMethod · 0.45
topMethod · 0.45
getBitDepthMethod · 0.45
getAppMethod · 0.45
getGuiMethod · 0.45

Tested by

no test coverage detected