Skip to content

Commit

Permalink
Resolve Issue #36 and #37
Browse files Browse the repository at this point in the history
Thanks to D-Vindy for finding these issues, and the solutions for resolving them.
  • Loading branch information
brandonmpetty committed Dec 30, 2023
1 parent 3139c99 commit c407d6e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

81 changes: 52 additions & 29 deletions Doxa.Test/PNMTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,71 @@ namespace Doxa::UnitTests
input.data[4] = 125;
input.data[5] = 200;

// Execute - Write
std::ostringstream stream;
writeFunc(stream, input);

// Execute - Read
PNMTestharness pnm;
Image output;
std::istringstream iss(stream.str());
pnm.ReadPNM(iss, output);

// Assert
EXPECT_EQ(3, output.width);
EXPECT_EQ(2, output.height);
TestUtilities::AssertImages(input, output);
// Test
TestWriteAndRead(input, writeFunc);
}

void TestWriteAndReadBinary(std::function<void(std::ostream& outputStream, const Image& image)> writeFunc)
{
// Setup
Image input(3, 2);

input.data[0] = 255;
input.data[1] = 0;
input.data[2] = 255;
input.data[3] = 0;
input.data[4] = 255;
input.data[5] = 255;
// Setup - Image will require padding
Image input1(3, 2);

// Row 1
input1.data[0] = 255;
input1.data[1] = 0;
input1.data[2] = 255;

// Row 2
input1.data[3] = 0;
input1.data[4] = 255;
input1.data[5] = 255;

// Test Padded Image
TestWriteAndRead(input1, writeFunc);

// Setup - Image will NOT require padding
Image input2(8, 2);

// Row 1
input2.data[0] = 255;
input2.data[1] = 0;
input2.data[2] = 255;
input2.data[3] = 0;
input2.data[4] = 255;
input2.data[5] = 255;
input2.data[6] = 255;
input2.data[7] = 255;

// Row 2
input2.data[8] = 0;
input2.data[9] = 0;
input2.data[10] = 0;
input2.data[11] = 0;
input2.data[12] = 255;
input2.data[13] = 0;
input2.data[14] = 0;
input2.data[15] = 0;

// Test Padded Image
TestWriteAndRead(input2, writeFunc);
}

void TestWriteAndRead(const Image& inputImage, std::function<void(std::ostream& outputStream, const Image& image)> writeFunc)
{
// Execute - Write
std::ostringstream stream;
writeFunc(stream, input);
writeFunc(stream, inputImage);

// Execute - Read
PNMTestharness pnm;
Image output;
Image outputImage;
std::istringstream iss(stream.str());
pnm.ReadPNM(iss, output);
pnm.ReadPNM(iss, outputImage);

// Assert
EXPECT_EQ(3, output.width);
EXPECT_EQ(2, output.height);
TestUtilities::AssertImages(input, output);
EXPECT_EQ(inputImage.width, outputImage.width);
EXPECT_EQ(inputImage.height, outputImage.height);
TestUtilities::AssertImages(inputImage, outputImage);
}
};

Expand Down
6 changes: 4 additions & 2 deletions Doxa/PNM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ namespace Doxa

void Read1BitBinary(std::istream& inputStream, Image& image)
{
const int paddedWidth = image.width + 8 - (image.width % 8);
const int delta = image.width % 8;
const int paddedWidth = delta == 0 ? image.width : image.width + 8 - delta;

for (int y = 0; y < image.height; ++y)
{
Expand Down Expand Up @@ -283,7 +284,8 @@ namespace Doxa
<< "P4" << std::endl
<< image.width << " " << image.height << std::endl;

const int paddedWidth = image.width + 8 - (image.width % 8);
const int delta = image.width % 8;
const int paddedWidth = delta == 0 ? image.width : image.width + 8 - delta;

for (int y = 0; y < image.height; ++y)
{
Expand Down
1 change: 1 addition & 0 deletions Doxa/Wan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Algorithm.hpp"
#include "LocalWindow.hpp"
#include "ChanMeanVarianceCalc.hpp"
#include "Morphology.hpp"


namespace Doxa
Expand Down

0 comments on commit c407d6e

Please sign in to comment.