171 ImageOf<PixelRgb> *inputImage = inputPort.read();
172 yarp::os::Stamp stamp;
173 inputPort.getEnvelope(stamp);
175 ImageOf<PixelRgb> &outLeftImage = outLeftPort.prepare();
176 ImageOf<PixelRgb> &outRightImage = outRightPort.prepare();
178 inWidth = inputImage->width();
179 inHeight = inputImage->height();
183 outWidth = inWidth/2;
184 outHeight = inHeight;
189 outHeight = inHeight/2;
192 outLeftImage.setQuantum(inputImage->getQuantum());
193 outRightImage.setQuantum(inputImage->getQuantum());
194 outLeftImage.resize(outWidth, outHeight);
195 outRightImage.resize(outWidth, outHeight);
199 unsigned char *pixelLeft, *pixelRight;
200 unsigned char *pixelInputL, *pixelInputR;
201 unsigned char *pixelInput = inputImage->getRawImage();
202 int dualImage_rowSizeByte = inputImage->getRowSize();
203 int singleImage_rowSizeByte = outLeftImage.getRowSize();
204 int singleImage_wholeSizeByte = outWidth * outHeight * outLeftImage.getPixelSize();
206 static int counter = 0;
207 static double start = 0;
208 start = yarp::os::Time::now();
216 for(
int h=0;
h<outHeight;
h++)
218 for(
int w1=0; w1<outWidth; w1++)
221 pixelLeft = outLeftImage.getPixelAddress(w1,
h);
222 pixelLeft[0] = *(inputImage->getPixelAddress(w1,
h)+0);
223 pixelLeft[1] = *(inputImage->getPixelAddress(w1,
h)+1);
224 pixelLeft[2] = *(inputImage->getPixelAddress(w1,
h)+2);
226 pixelRight = outRightImage.getPixelAddress(w1,
h);
227 pixelRight[0] = *(inputImage->getPixelAddress(w2,
h)+0);
228 pixelRight[1] = *(inputImage->getPixelAddress(w2,
h)+1);
229 pixelRight[2] = *(inputImage->getPixelAddress(w2,
h)+2);
235 for(
int h1=0; h1<outHeight; h1++)
237 for(
int w=0; w<outWidth; w++)
240 pixelLeft = outLeftImage.getPixelAddress(w, h1);
241 pixelLeft[0] = *(inputImage->getPixelAddress(w, h1)+0);
242 pixelLeft[1] = *(inputImage->getPixelAddress(w, h1)+1);
243 pixelLeft[2] = *(inputImage->getPixelAddress(w, h1)+2);
245 pixelRight = outRightImage.getPixelAddress(w, h1);
246 pixelRight[0] = *(inputImage->getPixelAddress(w, h2)+0);
247 pixelRight[1] = *(inputImage->getPixelAddress(w, h2)+1);
248 pixelRight[2] = *(inputImage->getPixelAddress(w, h2)+2);
258 pixelLeft = outLeftImage.getRawImage();
259 pixelRight = outRightImage.getRawImage();
261 pixelInputL = pixelInput;
262 pixelInputR = pixelInput+singleImage_rowSizeByte;
263 for(
int h=0,
idx=0, idx2=0;
h<outHeight;
h++)
265 for(
int w=0; w<outWidth; w++)
267 pixelLeft[
idx++] = *(pixelInputL++);
268 pixelLeft[
idx++] = *(pixelInputL++);
269 pixelLeft[
idx++] = *(pixelInputL++);
271 pixelRight[idx2++] = *(pixelInputR++);
272 pixelRight[idx2++] = *(pixelInputR++);
273 pixelRight[idx2++] = *(pixelInputR++);
275 pixelInputL += singleImage_rowSizeByte;
276 pixelInputR += singleImage_rowSizeByte;
289 pixelLeft = outLeftImage.getRawImage();
290 pixelRight = outRightImage.getRawImage();
292 for(
int h=0;
h<inHeight;
h++)
294 memcpy(pixelLeft +
h*singleImage_rowSizeByte, pixelInput, singleImage_rowSizeByte);
295 memcpy(pixelRight +
h*singleImage_rowSizeByte, pixelInput+=singleImage_rowSizeByte, singleImage_rowSizeByte);
296 pixelInput+= dualImage_rowSizeByte/2;
301 pixelLeft = outLeftImage.getRawImage();
302 pixelRight = outRightImage.getRawImage();
303 pixelInputL = pixelInput;
304 pixelInputR = pixelInput+singleImage_wholeSizeByte;
306 for(
int h=0;
h<outHeight;
h++)
308 memcpy(pixelLeft +
h*singleImage_rowSizeByte, pixelInputL, singleImage_rowSizeByte);
309 memcpy(pixelRight +
h*singleImage_rowSizeByte, pixelInputR, singleImage_rowSizeByte);
310 pixelInputL+= singleImage_rowSizeByte;
311 pixelInputR+= singleImage_rowSizeByte;
320 yError() <<
"Cannot use this copy method with horizontally aligned source image.";
324 pixelLeft = outLeftImage.getRawImage();
325 pixelRight = outRightImage.getRawImage();
327 memcpy(pixelLeft, pixelInput, singleImage_wholeSizeByte);
328 memcpy(pixelRight, pixelInput+ singleImage_wholeSizeByte, singleImage_wholeSizeByte);
334 yError() <<
" @line " << __LINE__ <<
"unhandled switch case, we should not be here!";
338 static double end = 0;
339 static double elapsed = 0;
340 end = yarp::os::Time::now();
341 elapsed += (end-start);
344 if((counter % 100) == 0)
346 yInfo() <<
"Elapsed time: " << elapsed;
350 outLeftPort.setEnvelope(stamp);
351 outRightPort.setEnvelope(stamp);
354 outRightPort.write();