First patch of the LockableColorPicker tool.

Still Work In Progress, but can be used without too much hassle.
This commit is contained in:
Hombre
2016-09-30 01:03:57 +02:00
parent db6b43e3c0
commit f904bc8f84
43 changed files with 14509 additions and 97 deletions

View File

@@ -22,6 +22,7 @@
#include <cstring>
#include "guiutils.h"
#include "cropwindow.h"
#include "imagearea.h"
#include "../rtengine/dcrop.h"
#include "../rtengine/refreshmap.h"
#include "../rtengine/rt_math.h"
@@ -188,6 +189,15 @@ void CropHandler::setZoom (int z, int centerx, int centery)
}
}
float CropHandler::getZoomFactor ()
{
if (zoom >= 1000) {
return zoom / 1000;
} else {
return 1.f / (float)zoom;
}
}
void CropHandler::setWSize (int w, int h)
{
@@ -465,6 +475,63 @@ bool CropHandler::getEnabled ()
return enabled;
}
void CropHandler::colorPick (rtengine::Coord pickerPos, float &r, float &g, float &b, LockableColorPicker::PickerSize size)
{
int xSize = (int)size;
int ySize = (int)size;
int pixbufW = cropPixbuf->get_width();
rtengine::Coord topLeftPos(pickerPos.x - xSize/2, pickerPos.y - ySize/2);
if (topLeftPos.x > pixbufW || topLeftPos.y > pixbufW || topLeftPos.x + xSize < 0 || topLeftPos.y + ySize < 0) {
return;
}
// Store the position of the center of the picker
int radius = (int)size / 2;
// X/Width clip
if (topLeftPos.x < 0) {
xSize += topLeftPos.x;
topLeftPos.x = 0;
}
if (topLeftPos.x + xSize > pixbufW) {
xSize = pixbufW - topLeftPos.x;
}
// Y/Height clip
if (topLeftPos.y < 0) {
ySize += topLeftPos.y;
topLeftPos.y = 0;
}
if (topLeftPos.y + ySize > cropimg_height) {
ySize = cropimg_height - topLeftPos.y;
}
// Accumulating the data
std::uint32_t r2=0, g2=0, b2=0;
std::uint32_t count = 0;
const guint8* data = cropPixbuf->get_pixels();
for (int j = topLeftPos.y ; j < topLeftPos.y + ySize ; ++j) {
const guint8* data2 = data + cropPixbuf->get_rowstride()*j;
for (int i = topLeftPos.x ; i < topLeftPos.x + xSize ; ++i) {
const guint8* data3 = data2 + i*3;
rtengine::Coord currPos(i, j);
rtengine::Coord delta = pickerPos - currPos;
rtengine::PolarCoord p(delta);
if (p.radius <= radius) {
r2 += *data3;
g2 += *(data3+1);
b2 += *(data3+2);
++count;
}
}
}
// Averaging
r = (float)r2 / (float)count / 255.f;
g = (float)g2 / (float)count / 255.f;
b = (float)b2 / (float)count / 255.f;
}
void CropHandler::getSize (int& w, int& h)
{