| 159 | |
| 160 | template<typename SrcT, typename DstT, typename Convertor = SimpleConversion> |
| 161 | void writePixels(const SrcT *srcPtr, |
| 162 | const GfVec2i &srcSize, |
| 163 | const int srcChannelCount, |
| 164 | DstT *dstPtr, |
| 165 | const GfVec2i &dstSize, |
| 166 | const int dstChannelCount, |
| 167 | const Convertor &convertor = {}) |
| 168 | { |
| 169 | const auto writeSize = GfVec2i(GfMin(srcSize[0], dstSize[0]), GfMin(srcSize[1], dstSize[1])); |
| 170 | const auto writeChannelCount = GfMin(srcChannelCount, dstChannelCount); |
| 171 | |
| 172 | for (int y = 0; y < writeSize[1]; ++y) { |
| 173 | for (int x = 0; x < writeSize[0]; ++x) { |
| 174 | for (int c = 0; c < writeChannelCount; ++c) { |
| 175 | dstPtr[x * dstChannelCount + c] = convertor.convert(srcPtr[x * srcChannelCount + c]); |
| 176 | } |
| 177 | } |
| 178 | srcPtr += srcSize[0] * srcChannelCount; |
| 179 | dstPtr += dstSize[0] * dstChannelCount; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | } // namespace |
| 184 | |