Skip to content

Commit

Permalink
Merge pull request robotology#3145 from randaz81/image_no_topIsLow
Browse files Browse the repository at this point in the history
Removed topIsLow in yarp image
  • Loading branch information
randaz81 authored Nov 12, 2024
2 parents 209637c + b590f07 commit 1e4c5ee
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 80 deletions.
15 changes: 0 additions & 15 deletions src/devices/fake/fakeFrameGrabber/FakeFrameGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ bool FakeFrameGrabber::read(yarp::os::ConnectionReader& connection)
reply.addString("set_mode <mode>");
reply.addString("set_image <file_name>/off");
reply.addString("available modes: ball, line, grid, size, rand, none, time");
reply.addString("set_topIsLow on/off");
reply.addString("set_noise on/off");
reply.addString("set_snr <snr>");
reply.addString("");
Expand Down Expand Up @@ -163,18 +162,6 @@ bool FakeFrameGrabber::read(yarp::os::ConnectionReader& connection)
}
}
}
else if (command.get(0).asString() == "set_topIsLow")
{
if (command.get(1).asString() == "off") {
m_topIsLow = false;
reply.addString("ack");
} else if (command.get(1).asString() == "on") {
m_topIsLow = true;
reply.addString("ack");
} else {
reply.addString("err");
}
}
else if (command.get(0).asString() == "set_noise")
{
if (command.get(1).asString() == "off") {
Expand Down Expand Up @@ -830,8 +817,6 @@ void FakeFrameGrabber::createTestImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>&
image.pixel(6, 0).g = ttxt[19] - '0';
image.pixel(6, 0).b = ttxt[20] - '0';
}

image.setTopIsLowIndex(m_topIsLow);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// This is an automatically generated file. Please do not edit it.
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.

// Generated on: Thu Mar 7 17:59:43 2024
// Generated on: Mon Sep 16 16:44:50 2024


#include "FakeFrameGrabber_ParamsParser.h"
Expand Down Expand Up @@ -188,20 +188,6 @@ bool FakeFrameGrabber_ParamsParser::parseParams(const yarp::os::Searchable
prop_check.unput("syncro");
}

//Parser of parameter topIsLow
{
if (config.check("topIsLow"))
{
m_topIsLow = config.find("topIsLow").asBool();
yCInfo(FakeFrameGrabberParamsCOMPONENT) << "Parameter 'topIsLow' using value:" << m_topIsLow;
}
else
{
yCInfo(FakeFrameGrabberParamsCOMPONENT) << "Parameter 'topIsLow' using DEFAULT value:" << m_topIsLow;
}
prop_check.unput("topIsLow");
}

//Parser of parameter physFocalLength
{
if (config.check("physFocalLength"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// This is an automatically generated file. Please do not edit it.
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.

// Generated on: Thu Mar 7 17:59:43 2024
// Generated on: Mon Sep 16 16:44:50 2024


#ifndef FAKEFRAMEGRABBER_PARAMSPARSER_H
Expand Down Expand Up @@ -120,7 +120,6 @@ class FakeFrameGrabber_ParamsParser : public yarp::dev::IDeviceDriverParams
std::string m_fakeFrameGrabber_rpc_port = {"/fakeFrameGrabber/rpc"};
bool m_mirror = {false};
bool m_syncro = {false};
bool m_topIsLow = {true};
double m_physFocalLength = {3.0};
double m_focalLengthX = {4.0};
double m_focalLengthY = {5.0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* | | fakeFrameGrabber_rpc_port | string | - | /fakeFrameGrabber/rpc | No | rpc port for the fakeFrameGrabber | |
* | | mirror | bool | - | false | No | mirror height of test image | |
* | | syncro | bool | - | false | No | synchronize producer and consumer, so that all images are used once and only once | |
* | | topIsLow | bool | - | true | No | explicitly set the topIsLow field in the images | |
* | | physFocalLength | double | - | 3.0 | No | Physical focal length | |
* | | focalLengthX | double | - | 4.0 | No | Horizontal component of the focal length | |
* | | focalLengthY | double | - | 5.0 | No | Vertical component of the focal length | |
Expand Down
23 changes: 1 addition & 22 deletions src/libYARP_sig/src/yarp/sig/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,6 @@ void Image::setQuantum(size_t imgQuantum) {
}
}


void Image::setTopIsLowIndex(bool flag) {
topIsLow = flag;

if (implementation) {
auto* impl = static_cast<ImageStorage*>(implementation);
if (impl->pImage) {
impl->pImage->origin = topIsLow ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;
}
}
}

void Image::synchronize() {
auto* impl = static_cast<ImageStorage*>(implementation);
yAssert(impl!=nullptr);
Expand Down Expand Up @@ -540,8 +528,6 @@ bool Image::read(yarp::os::ConnectionReader& connection) {
}
}

setTopIsLowIndex(header.topIsLow == 0);

// handle easy case, received and current image are compatible, no conversion needed
if (getPixelCode() == header.id && q == static_cast<size_t>(header.quantum) && imgPixelSize == static_cast<size_t>(header.depth))
{
Expand All @@ -554,7 +540,6 @@ bool Image::read(yarp::os::ConnectionReader& connection) {
FlexImage flex;
flex.setPixelCode(header.id);
flex.setQuantum(header.quantum);
flex.setTopIsLowIndex(header.topIsLow == 0);
ok = readFromConnection(flex, header, connection);
if (ok) {
copy(flex);
Expand Down Expand Up @@ -625,16 +610,12 @@ bool Image::copy(const Image& alt)
setQuantum(alt.getQuantum());
}
resize(alt.width(),alt.height());
setTopIsLowIndex(alt.topIsLowIndex());

int q1 = alt.getQuantum();
int q2 = getQuantum();
if (q1==0) { q1 = YARP_IMAGE_ALIGN; }
if (q2==0) { q2 = YARP_IMAGE_ALIGN; }

bool o1 = alt.topIsLowIndex();
bool o2 = topIsLowIndex();

yAssert(width()==alt.width());
yAssert(height()==alt.height());
if (getPixelCode()==alt.getPixelCode()) {
Expand All @@ -647,7 +628,7 @@ bool Image::copy(const Image& alt)
copyPixels(alt.getRawImage(),alt.getPixelCode(),
getRawImage(),getPixelCode(),
width(),height(),
getRawImageSize(),q1,q2,o1,o2);
getRawImageSize(),q1,q2,false,false);
}
return true;
}
Expand Down Expand Up @@ -700,7 +681,6 @@ bool Image::copy(const Image& alt, size_t w, size_t h) {
if (getPixelCode()==0) {
setPixelCode(alt.getPixelCode());
setQuantum(alt.getQuantum());
setTopIsLowIndex(alt.topIsLowIndex());
}
if (&alt==this) {
FlexImage img;
Expand All @@ -712,7 +692,6 @@ bool Image::copy(const Image& alt, size_t w, size_t h) {
FlexImage img;
img.setPixelCode(getPixelCode());
img.setQuantum(getQuantum());
img.setTopIsLowIndex(topIsLowIndex());
img.copy(alt);
return copy(img,w,h);
}
Expand Down
19 changes: 0 additions & 19 deletions src/libYARP_sig/src/yarp/sig/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,6 @@ class YARP_sig_API yarp::sig::Image : public yarp::os::Portable {

void setQuantum(size_t imgQuantum);

/**
* @return true if image has origin at top left (default); in other
* words when the y index is low, we are near the top of the image.
*/
bool topIsLowIndex() const {
return topIsLow;
}

/**
* control whether image has origin at top left (default) or bottom
* left.
*
* @param flag true if image has origin at top left (default),
* false if image has origin at bottom left.
*
*/
void setTopIsLowIndex(bool flag);


/**
* Get an array of pointers to the rows of the image.
* @return an array of pointers to the rows of the image.
Expand Down
2 changes: 1 addition & 1 deletion src/libYARP_sig/src/yarp/sig/ImageNetworkHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ImageNetworkHeader
depth = image.getPixelSize();
imgSize = image.getRawImageSize();
quantum = static_cast<yarp::os::NetInt16>(image.getQuantum());
topIsLow = image.topIsLowIndex() ? 0 : 1;
topIsLow = 1;
width = image.width();
height = image.height();
paramBlobLen = image.getRawImageSize();
Expand Down
6 changes: 3 additions & 3 deletions src/libYARP_sig/tests/ImageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,14 @@ TEST_CASE("sig::ImageTest", "[yarp::sig]")

ImageOf<PixelMono> img1;

img1.setTopIsLowIndex(false);
img1.setExternal(&buf[0][0],EXT_WIDTH,EXT_HEIGHT);

CHECK(img1.width() == EXT_WIDTH); // width check
CHECK(img1.height() == EXT_HEIGHT); // height check

int mismatch = 0;
/*
//not sure about what i'm checking here
for (size_t x=0; x<img1.width(); x++) {
for (size_t y=0; y<img1.height(); y++) {
img1.pixel(x,y) = 5;
Expand All @@ -627,12 +628,11 @@ TEST_CASE("sig::ImageTest", "[yarp::sig]")
}
}
CHECK(mismatch == 0); // delta check
*/

INFO("check origin with copy...");
ImageOf<PixelInt> img2;
ImageOf<PixelInt> img3;
img2.setTopIsLowIndex(false);
img2.setTopIsLowIndex(true);
img2.resize(50,50);
int ct = 1;
for (size_t x=0; x<img2.width(); x++) {
Expand Down
7 changes: 5 additions & 2 deletions src/yarpview/plugin/ImagePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ void InputCallback::onRead(yarp::sig::ImageOf<yarp::sig::PixelRgba> &img)
j+=4;
}*/

if (img.topIsLowIndex()) {
if (1)
{
memcpy(tmpBuf, rawImg, imgSize);
} else {
}
else
{ //flip the image along the y axis
for(int x = 0; x < s.height(); x++) {
memcpy(tmpBuf + x * img.getRowSize(),
rawImg + (s.height() - x - 1) * img.getRowSize(),
Expand Down

0 comments on commit 1e4c5ee

Please sign in to comment.