| 112 | |
| 113 | |
| 114 | void pcl::io::IRImage::fillRaw (unsigned width, unsigned height, unsigned short* ir_buffer, unsigned line_step) const |
| 115 | { |
| 116 | if (width > wrapper_->getWidth () || height > wrapper_->getHeight ()) |
| 117 | THROW_IO_EXCEPTION ("upsampling not supported: %d x %d -> %d x %d", wrapper_->getWidth (), wrapper_->getHeight (), width, height); |
| 118 | |
| 119 | if (wrapper_->getWidth () % width != 0 || wrapper_->getHeight () % height != 0) |
| 120 | THROW_IO_EXCEPTION ("downsampling only supported for integer scale: %d x %d -> %d x %d", wrapper_->getWidth (), wrapper_->getHeight (), width, height); |
| 121 | |
| 122 | if (line_step == 0) |
| 123 | line_step = width * static_cast<unsigned> (sizeof (unsigned short)); |
| 124 | |
| 125 | // special case no sclaing, no padding => memcopy! |
| 126 | if (width == wrapper_->getWidth () && height == wrapper_->getHeight () && (line_step == width * sizeof (unsigned short))) |
| 127 | { |
| 128 | memcpy (ir_buffer, wrapper_->getData (), wrapper_->getDataSize ()); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | // padding skip for destination image |
| 133 | unsigned bufferSkip = line_step - width * static_cast<unsigned> (sizeof (unsigned short)); |
| 134 | |
| 135 | // step and padding skip for source image |
| 136 | unsigned xStep = wrapper_->getWidth () / width; |
| 137 | unsigned ySkip = (wrapper_->getHeight () / height - 1) * wrapper_->getWidth (); |
| 138 | |
| 139 | unsigned irIdx = 0; |
| 140 | |
| 141 | const auto* inputBuffer = static_cast<const unsigned short*> (wrapper_->getData ()); |
| 142 | |
| 143 | for (unsigned yIdx = 0; yIdx < height; ++yIdx, irIdx += ySkip) |
| 144 | { |
| 145 | for (unsigned xIdx = 0; xIdx < width; ++xIdx, irIdx += xStep, ++ir_buffer) |
| 146 | *ir_buffer = inputBuffer[irIdx]; |
| 147 | |
| 148 | // if we have padding |
| 149 | if (bufferSkip > 0) |
| 150 | { |
| 151 | char* cBuffer = reinterpret_cast<char*> (ir_buffer); |
| 152 | ir_buffer = reinterpret_cast<unsigned short*> (cBuffer + bufferSkip); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 |
no test coverage detected