MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / from_float_packed

Function from_float_packed

Engine/Lut.cpp:920–981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

918}
919
920void
921from_float_packed(float *to,
922 const float *from,
923 const RectI &conversionRect,
924 const RectI &srcBounds,
925 const RectI &dstBounds,
926 PixelPackingEnum inputPacking,
927 PixelPackingEnum outputPacking,
928 bool invertY)
929{
930 if ( ( inputPacking == ePixelPackingPLANAR) || ( outputPacking == ePixelPackingPLANAR) ) {
931 throw std::runtime_error("This function is not meant for planar buffers.");
932 }
933
934
935 ///clip the conversion rect to srcBounds and dstBounds
936 RectI rect = conversionRect;
937 if ( !clip(&rect, srcBounds) || !clip(&rect, dstBounds) ) {
938 return;
939 }
940
941
942 if ( ( inputPacking == ePixelPackingPLANAR) || ( outputPacking == ePixelPackingPLANAR) ) {
943 throw std::runtime_error("Invalid pixel format.");
944 }
945
946 bool inputHasAlpha = inputPacking == ePixelPackingBGRA || inputPacking == ePixelPackingRGBA;
947 bool outputHasAlpha = outputPacking == ePixelPackingBGRA || outputPacking == ePixelPackingRGBA;
948 int inROffset, inGOffset, inBOffset, inAOffset;
949 int outROffset, outGOffset, outBOffset, outAOffset;
950 getOffsetsForPacking(inputPacking, &inROffset, &inGOffset, &inBOffset, &inAOffset);
951 getOffsetsForPacking(outputPacking, &outROffset, &outGOffset, &outBOffset, &outAOffset);
952
953 int inPackingSize, outPackingSize;
954 inPackingSize = inputHasAlpha ? 4 : 3;
955 outPackingSize = outputHasAlpha ? 4 : 3;
956
957 for (int y = rect.y1; y < rect.y2; ++y) {
958 int srcY = y;
959 if (invertY) {
960 srcY = srcBounds.y2 - y - 1;
961 }
962 const float *src_pixels = from + (srcY * (srcBounds.x2 - srcBounds.x1) * inPackingSize);
963 float *dst_pixels = to + (y * (dstBounds.x2 - dstBounds.x1) * outPackingSize);
964 if (inputPacking == outputPacking) {
965 std::memcpy( dst_pixels, src_pixels, (rect.x2 - rect.x1) * sizeof(float) );
966 } else {
967 for (int x = rect.x1; x < rect.x2; ++x) {
968 int inCol = x * inPackingSize;
969 int outCol = x * outPackingSize;
970 float a = inputHasAlpha ? src_pixels[inCol + inAOffset] : 1.f;
971 dst_pixels[outCol + outROffset] = src_pixels[inCol + inROffset];
972 dst_pixels[outCol + outGOffset] = src_pixels[inCol + inGOffset];
973 dst_pixels[outCol + outBOffset] = src_pixels[inCol + inBOffset];
974 if (outputHasAlpha) {
975 // alpha is linear
976 dst_pixels[outCol + outAOffset] = a;
977 }

Callers

nothing calls this directly

Calls 2

clipFunction · 0.85
getOffsetsForPackingFunction · 0.85

Tested by

no test coverage detected