Skip to content

Commit

Permalink
Fix for review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandagrapher committed Nov 23, 2024
1 parent f242a27 commit 03e9aeb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 89 deletions.
8 changes: 4 additions & 4 deletions rtgui/editbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ int ObjectMOBuffer::getObjectID(const rtengine::Coord& location)
}

if (objectMode == OM_255) {
// In OM_255 mode, size of pixel is 1 Byte (i.e. size of unsigned char)
memcpy(&id, ( objectMap->get_data() + location.y * objectMap->get_stride() + sizeof(unsigned char) * location.x ), sizeof(unsigned char));
// In OM_255 mode, size of pixel is 1 Byte (i.e. size of uint8_t)
memcpy(&id, ( objectMap->get_data() + location.y * objectMap->get_stride() + sizeof(std::uint8_t) * location.x ), sizeof(std::uint8_t));
} else {
// In OM_65535 mode, size of pixel is 2 Bytes (i.e. size on unsigned short)
memcpy(&id, ( objectMap->get_data() + location.y * objectMap->get_stride() + sizeof(unsigned short) * location.x ), sizeof(unsigned short));
// In OM_65535 mode, size of pixel is 2 Bytes (i.e. size of uint16_t)
memcpy(&id, ( objectMap->get_data() + location.y * objectMap->get_stride() + sizeof(std::uint16_t) * location.x ), sizeof(std::uint16_t));
}

return id - 1;
Expand Down
125 changes: 40 additions & 85 deletions rtgui/editwidgets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ RGBColor Geometry::getOuterLineColor ()
return color;
}

void Geometry::setMOChannelColor(Cairo::RefPtr<Cairo::Context> &cr, ObjectMOBuffer *objectBuffer, unsigned short id)
{
switch (objectBuffer->getObjectMode()) {
case OM_255:
/* In OM_255 mode, FORMAT_A8 format is used:
- Alpha is represented with 8 bits (mask = 0xFF) from 0 to 255
*/
cr->set_source_rgba (0., 0., 0., ((id + 1) & 0xFF) / 255.);
break;
case OM_65535:
default:
/* In OM_65535 mode, FORMAT_RGB16_565 format is used:
- Red is represented with 5 bits (mask = 0xF800, left shift = 11) from 0 to 31
- Green is represented with 6 bits (mask = 0x7E0, left shift = 5) from 0 to 63
- Blue is represented with 5 bits (mask = 0x1F) from 0 to 31
*/
const double red = (((id + 1) & 0xF800) >> 11) / 31.;
const double green = (((id + 1) & 0x7E0) >> 5) / 63.;
const double blue = ((id + 1) & 0x1F) / 31.;
cr->set_source_rgb (red, green, blue);
}
}

#ifdef GUIVERSION

void Circle::drawOuterGeometry(Cairo::RefPtr<Cairo::Context> &cr, ObjectMOBuffer *objectBuffer, EditCoordSystem &coordSystem)
Expand Down Expand Up @@ -169,23 +192,9 @@ void Circle::drawToMOChannel (Cairo::RefPtr<Cairo::Context> &cr, unsigned short
center_ += objectBuffer->getDataProvider()->posScreen + objectBuffer->getDataProvider()->deltaScreen;
}

// setting the color to the objet's ID
if (objectBuffer->getObjectMode() == OM_255) {
/* In OM_255 mode, FORMAT_A8 format is used:
- Alpha is represented with 8 bits (mask = 0xFF) from 0 to 255
*/
cr->set_source_rgba (0., 0., 0., ((id + 1) & 0xFF) / 255.);
} else {
/* In OM_65535 mode, FORMAT_RGB16_565 format is used:
- Red is represented with 5 bits (mask = 0xF800, left shift = 11) from 0 to 31
- Green is represented with 6 bits (mask = 0x7E0, left shift = 5) from 0 to 63
- Blue is represented with 5 bits (mask = 0x1F) from 0 to 31
*/
const double red = (((id + 1) & 0xF800) >> 11) / 31.;
const double green = (((id + 1) & 0x7E0) >> 5) / 63.;
const double blue = ((id + 1) & 0x1F) / 31.;
cr->set_source_rgb (red, green, blue);
}
// Setting MO Channel color according to the objet's ID
setMOChannelColor(cr, objectBuffer, id);

cr->arc(center_.x + 0.5, center_.y + 0.5, radius_, 0, 2.*rtengine::RT_PI);

if (filled) {
Expand Down Expand Up @@ -302,23 +311,9 @@ void Line::drawToMOChannel(Cairo::RefPtr<Cairo::Context> &cr, unsigned short id,
end_ += objectBuffer->getDataProvider()->posScreen + objectBuffer->getDataProvider()->deltaScreen;
}

// setting the color to the objet's ID
if (objectBuffer->getObjectMode() == OM_255) {
/* In OM_255 mode, FORMAT_A8 format is used:
- Alpha is represented with 8 bits (mask = 0xFF) from 0 to 255
*/
cr->set_source_rgba (0., 0., 0., ((id + 1) & 0xFF) / 255.);
} else {
/* In OM_65535 mode, FORMAT_RGB16_565 format is used:
- Red is represented with 5 bits (mask = 0xF800, left shift = 11) from 0 to 31
- Green is represented with 6 bits (mask = 0x7E0, left shift = 5) from 0 to 63
- Blue is represented with 5 bits (mask = 0x1F) from 0 to 31
*/
const double red = (((id + 1) & 0xF800) >> 11) / 31.;
const double green = (((id + 1) & 0x7E0) >> 5) / 63.;
const double blue = ((id + 1) & 0x1F) / 31.;
cr->set_source_rgb (red, green, blue);
}
// Setting MO Channel color according to the objet's ID
setMOChannelColor(cr, objectBuffer, id);

cr->move_to(begin_.x + 0.5, begin_.y + 0.5);
cr->line_to(end_.x + 0.5, end_.y + 0.5);
cr->stroke();
Expand Down Expand Up @@ -455,23 +450,8 @@ void Polyline::drawToMOChannel (Cairo::RefPtr<Cairo::Context> &cr, unsigned shor
if ((flags & F_HOVERABLE) && points.size() > 1) {
rtengine::Coord currPos;

// setting the color to the objet's ID
if (objectBuffer->getObjectMode() == OM_255) {
/* In OM_255 mode, FORMAT_A8 format is used:
- Alpha is represented with 8 bits (mask = 0xFF) from 0 to 255
*/
cr->set_source_rgba (0., 0., 0., ((id + 1) & 0xFF) / 255.);
} else {
/* In OM_65535 mode, FORMAT_RGB16_565 format is used:
- Red is represented with 5 bits (mask = 0xF800, left shift = 11) from 0 to 31
- Green is represented with 6 bits (mask = 0x7E0, left shift = 5) from 0 to 63
- Blue is represented with 5 bits (mask = 0x1F) from 0 to 31
*/
const double red = (((id + 1) & 0xF800) >> 11) / 31.;
const double green = (((id + 1) & 0x7E0) >> 5) / 63.;
const double blue = ((id + 1) & 0x1F) / 31.;
cr->set_source_rgb (red, green, blue);
}
// Setting MO Channel color according to the objet's ID
setMOChannelColor(cr, objectBuffer, id);

cr->set_line_width( getMouseOverLineWidth() );
cr->set_line_cap(Cairo::LINE_CAP_ROUND);
Expand Down Expand Up @@ -661,23 +641,9 @@ void EditRectangle::drawToMOChannel(Cairo::RefPtr<Cairo::Context> &cr, unsigned
br = bottomRight + objectBuffer->getDataProvider()->posScreen + objectBuffer->getDataProvider()->deltaScreen;
}

// setting the color to the objet's ID
if (objectBuffer->getObjectMode() == OM_255) {
/* In OM_255 mode, FORMAT_A8 format is used:
- Alpha is represented with 8 bits (mask = 0xFF) from 0 to 255
*/
cr->set_source_rgba (0., 0., 0., ((id + 1) & 0xFF) / 255.);
} else {
/* In OM_65535 mode, FORMAT_RGB16_565 format is used:
- Red is represented with 5 bits (mask = 0xF800, left shift = 11) from 0 to 31
- Green is represented with 6 bits (mask = 0x7E0, left shift = 5) from 0 to 63
- Blue is represented with 5 bits (mask = 0x1F) from 0 to 31
*/
const double red = (((id + 1) & 0xF800) >> 11) / 31.;
const double green = (((id + 1) & 0x7E0) >> 5) / 63.;
const double blue = ((id + 1) & 0x1F) / 31.;
cr->set_source_rgb (red, green, blue);
}
// Setting MO Channel color according to the objet's ID
setMOChannelColor(cr, objectBuffer, id);

cr->rectangle(tl.x + 0.5, tl.y + 0.5, br.x - tl.x, br.y - tl.y);

if (filled) {
Expand Down Expand Up @@ -924,6 +890,9 @@ void Ellipse::drawToMOChannel (Cairo::RefPtr<Cairo::Context> &cr, unsigned short
center_ += objectBuffer->getDataProvider()->posScreen + objectBuffer->getDataProvider()->deltaScreen;
}

// Setting MO Channel color according to the objet's ID
setMOChannelColor(cr, objectBuffer, id);

if (radYT_ > 0 && radY_ > 0 && radXL_ > 0 && radX_ > 0) {
// To have an ellipse with radius of (radX, radX), a circle of radius 1. shall be twisted with a scale
// of radX for x-axis, radY for y-axis
Expand Down Expand Up @@ -1154,23 +1123,9 @@ void OPIcon::drawMOImage(std::shared_ptr<RTSurface> &img, Cairo::RefPtr<Cairo::C
rtengine::Coord tl, br; // Coordinate of the rectangle in the CropBuffer coordinate system
drivenPointToRectangle(pos, tl, br, imgW, imgH);

// drawing the lower byte's value
if (objectBuffer->getObjectMode() == OM_255) {
/* In OM_255 mode, FORMAT_A8 format is used:
- Alpha is represented with 8 bits (mask = 0xFF) from 0 to 255
*/
cr->set_source_rgba (0., 0., 0., ((id + 1) & 0xFF) / 255.);
} else {
/* In OM_65535 mode, FORMAT_RGB16_565 format is used:
- Red is represented with 5 bits (mask = 0xF800, left shift = 11) from 0 to 31
- Green is represented with 6 bits (mask = 0x7E0, left shift = 5) from 0 to 63
- Blue is represented with 5 bits (mask = 0x1F) from 0 to 31
*/
const double red = (((id + 1) & 0xF800) >> 11) / 31.;
const double green = (((id + 1) & 0x7E0) >> 5) / 63.;
const double blue = ((id + 1) & 0x1F) / 31.;
cr->set_source_rgb (red, green, blue);
}
// Setting MO Channel color according to the objet's ID
setMOChannelColor(cr, objectBuffer, id);

cr->set_line_width(0.);
cr->rectangle(tl.x, tl.y, imgW, imgH);
cr->fill();
Expand Down
3 changes: 3 additions & 0 deletions rtgui/editwidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class Geometry
RGBColor outerLineColor;
short flags;

// Set MO Channel color according to Edit Widget id and MO Channel mode
static void setMOChannelColor (Cairo::RefPtr<Cairo::Context> &cr, ObjectMOBuffer *objectBuffer, unsigned short id);

public:
float innerLineWidth; // ...outerLineWidth = innerLineWidth+2
Datum datum;
Expand Down

0 comments on commit 03e9aeb

Please sign in to comment.