Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions winml/test/image/imageTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ namespace ImageTestHelper {
wf::IMemoryBufferReference reference = spBitmapBuffer.CreateReference();
auto spByteAccess = reference.as<::Windows::Foundation::IMemoryBufferByteAccess>();
spByteAccess->GetBuffer(&pData, &size);

uint32_t height = softwareBitmap.PixelHeight();
uint32_t width = softwareBitmap.PixelWidth();

Expand All @@ -53,14 +52,15 @@ namespace ImageTestHelper {
com_ptr<ITensorNative> itn = tf.as<ITensorNative>();
itn->GetBuffer(reinterpret_cast<BYTE**>(&pCPUTensor), &uCapacity);
if (BitmapPixelFormat::Bgra8 == GetPixelFormat(modelPixelFormat)) {
for (UINT32 i = 0; i < size; i += 4) {
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
for (UINT32 i = 0; i < size - 2; i += 4) {
Comment thread
martinb35 marked this conversation as resolved.
UINT32 pixelInd = i / 4;
pCPUTensor[pixelInd] = (float)pData[i];
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
pCPUTensor[(height * width * 2) + pixelInd] = (float)pData[i + 2];
}
} else if (BitmapPixelFormat::Rgba8 == GetPixelFormat(modelPixelFormat)) {
for (UINT32 i = 0; i < size; i += 4) {
for (UINT32 i = 0; i < size - 2; i += 4) {
UINT32 pixelInd = i / 4;
pCPUTensor[pixelInd] = (float)pData[i + 2];
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
Expand Down Expand Up @@ -99,14 +99,15 @@ namespace ImageTestHelper {
uint32_t height = softwareBitmap.PixelHeight();
uint32_t width = softwareBitmap.PixelWidth();
if (BitmapPixelFormat::Bgra8 == GetPixelFormat(modelPixelFormat)) {
for (UINT32 i = 0; i < size; i += 4) {
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
for (UINT32 i = 0; i < size - 2; i += 4) {
UINT32 pixelInd = i / 4;
pCPUTensor[pixelInd] = (float)pData[i];
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
pCPUTensor[(height * width * 2) + pixelInd] = (float)pData[i + 2];
}
} else if (BitmapPixelFormat::Rgba8 == GetPixelFormat(modelPixelFormat)) {
for (UINT32 i = 0; i < size; i += 4) {
for (UINT32 i = 0; i < size - 2; i += 4) {
UINT32 pixelInd = i / 4;
pCPUTensor[pixelInd] = (float)pData[i + 2];
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
Expand Down
9 changes: 6 additions & 3 deletions winml/test/scenario/cppwinrt/scenariotestscppwinrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ static void Scenario22ImageBindingAsCPUTensor() {

uint32_t height = softwareBitmap.PixelHeight();
uint32_t width = softwareBitmap.PixelWidth();
for (UINT32 i = 0; i < size; i += 4) {
for (UINT32 i = 0; i < size - 2; i += 4) {
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
UINT32 pixelInd = i / 4;
pCPUTensor[pixelInd] = (float)pData[i];
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
Expand Down Expand Up @@ -887,7 +888,8 @@ static void Scenario22ImageBindingAsGPUTensor() {

uint32_t height = softwareBitmap.PixelHeight();
uint32_t width = softwareBitmap.PixelWidth();
for (UINT32 i = 0; i < size; i += 4) {
for (UINT32 i = 0; i < size - 2; i += 4) {
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
UINT32 pixelInd = i / 4;
pCPUTensor[pixelInd] = (FLOAT)pData[i];
pCPUTensor[(height * width) + pixelInd] = (FLOAT)pData[i + 1];
Expand Down Expand Up @@ -1494,7 +1496,8 @@ static void BindMultipleCPUBuffersAsInputs(LearningModelDeviceKind kind) {
green_byteaccess->GetBuffer(reinterpret_cast<BYTE**>(&green_data), &frame_size);
blue_byteaccess->GetBuffer(reinterpret_cast<BYTE**>(&blue_data), &frame_size);

for (UINT32 i = 0; i < size; i += 4) {
for (UINT32 i = 0; i < size - 2 && i / 4 < frame_size; i += 4) {
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
UINT32 pixelInd = i / 4;
red_data[pixelInd] = (float)data[i];
green_data[pixelInd] = (float)data[i + 1];
Expand Down