// can't seem to do ipl/opencv/yarp style end-of-row padding void setDcImage(yarp::sig::Image& yimg, dc1394video_frame_t *dc, int filter) { if (!dc) return; dc->image = (unsigned char *) yimg.getRawImage(); dc->size[0] = (uint32_t) yimg.width(); dc->size[1] = (uint32_t) yimg.height(); dc->position[0] = 0; dc->position[1] = 0; dc->color_coding = (yimg.getPixelCode()==VOCAB_PIXEL_MONO)?DC1394_COLOR_CODING_RAW8:DC1394_COLOR_CODING_RGB8; dc->color_filter = (dc1394color_filter_t)filter; dc->yuv_byte_order = 0; dc->data_depth = 8; dc->stride = (uint32_t) yimg.getRowSize(); dc->video_mode = DC1394_VIDEO_MODE_640x480_RGB8; // we are bluffing dc->image_bytes = (uint32_t)yimg.getRawImageSize(); dc->padding_bytes = 0; dc->total_bytes = dc->image_bytes; dc->timestamp = 0; dc->frames_behind = 0; dc->camera = nullptr; dc->id = 0; dc->allocated_image_bytes = dc->image_bytes; #ifdef YARP_LITTLE_ENDIAN dc->little_endian = DC1394_TRUE; #else dc->little_endian = DC1394_FALSE; #endif dc->data_in_padding = DC1394_FALSE; }
bool deBayer_GRBG8_TO_RGB(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize) { yAssert(((pixelSize == 3) && (dest.getPixelCode() == VOCAB_PIXEL_RGB)) || ((pixelSize == 4 && dest.getPixelCode() == VOCAB_PIXEL_RGBA))) dest.resize(source.width(), source.height()); // perform conversion, skip borders for (int r = 0; r < source.height() - 2; r += 2) { unsigned char *destRow = dest.getRow(r); unsigned char *sourceRowCurrent = source.getRow(r); unsigned char *sourceRowNext = source.getRow(r + 1); //row i GRGRGR... for (int c = 0; c < source.width() - 2; c += 2) { //source is on G pixel destRow[0] = sourceRowCurrent[1]; //red destRow[1] = sourceRowCurrent[0]; //green destRow[2] = sourceRowNext[0];; //blue //jump a pixel in destination destRow += pixelSize; sourceRowCurrent++; sourceRowNext++; //source is now on R pixel destRow[0] = sourceRowCurrent[0]; //red destRow[1] = sourceRowCurrent[1]; //green destRow[2] = sourceRowNext[0]; //red destRow += pixelSize; sourceRowCurrent++; sourceRowNext++; } destRow = dest.getRow(r + 1); sourceRowCurrent = source.getRow(r + 1); sourceRowNext = source.getRow(r + 2); //row is now BGBGBG... for (int c = 0; c < dest.width() - 2; c += 2) { //source is on B pixel destRow[0] = sourceRowNext[1]; //red destRow[1] = sourceRowCurrent[1]; //green destRow[2] = sourceRowCurrent[0]; //blue //jump a pixel in destination destRow += pixelSize; sourceRowCurrent++; sourceRowNext++; //source is now on G pixel destRow[0] = sourceRowNext[0]; //red destRow[1] = sourceRowCurrent[0]; //green destRow[2] = sourceRowCurrent[1]; //blue destRow += pixelSize; sourceRowCurrent++; sourceRowNext++; } } return true; }