Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Mar 14, 2024
1 parent 48dfcff commit ab08a62
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion application/F3DColorMapTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ std::vector<double> Read(const std::string& path)

for (int i = 0; i < w; i++)
{
std::vector<double> pixel = img[{ i, 0 }];
std::vector<double> pixel = img.getNormalizedPixel({ i, 0 });
cm[4 * i + 0] = static_cast<double>(i) / (w - 1);
cm[4 * i + 1] = pixel[0];
cm[4 * i + 2] = pixel[1];
Expand Down
7 changes: 4 additions & 3 deletions library/public/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ class F3D_EXPORT image
///@}

/**
* Read one specific pixel and return all channel values.
* Read one specific pixel and return all channel normalized values.
* If the channel type is BYTE or SHORT, the values are normalized to [0, 1] range.
* \warning This function is slow, prefer getContent when possible.
* \warning Because of the normalization, this function can be slow, prefer getContent when
* reading several pixels and normalization is not needed.
*/
std::vector<double> operator[](const std::pair<int, int>& pixel) const;
std::vector<double> getNormalizedPixel(const std::pair<int, int>& xy) const;

/**
* Get the list of supported image format when opening a file.
Expand Down
16 changes: 8 additions & 8 deletions library/src/image.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -354,30 +354,30 @@ bool image::operator!=(const image& reference) const
}

//----------------------------------------------------------------------------
std::vector<double> image::operator[](const std::pair<int, int>& pixel) const
std::vector<double> image::getNormalizedPixel(const std::pair<int, int>& xy) const
{
std::vector<double> p(this->getChannelCount());
std::vector<double> pixel(this->getChannelCount());

for (size_t i = 0; i < p.size(); i++)
for (size_t i = 0; i < pixel.size(); i++)
{
double v = this->Internals->Image->GetScalarComponentAsDouble(
pixel.first, pixel.second, 0, static_cast<int>(i));
xy.first, xy.second, 0, static_cast<int>(i));

switch (this->getChannelType())
{
case ChannelType::BYTE:
p[i] = v / 255.0;
pixel[i] = v / 255.0;
break;
case ChannelType::SHORT:
p[i] = v / 65535.0;
pixel[i] = v / 65535.0;
break;
default:
p[i] = v;
pixel[i] = v;
break;
}
}

return p;
return pixel;
}

Check warning on line 381 in library/src/image.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/image.cxx#L381

Added line #L381 was not covered by tests

//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion python/F3DPythonBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ PYBIND11_MODULE(pyf3d, module)
}
})
.def("all_metadata", &f3d::image::allMetadata)
.def("__getitem__", &f3d::image::operator[]);
.def("normalized_pixel", &f3d::image::getNormalizedPixel);

// f3d::options
py::class_<f3d::options> options(module, "Options");
Expand Down
5 changes: 2 additions & 3 deletions python/testing/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ def test_formats(f3d_engine):
assert ".png" in formats


def test_get_item(f3d_engine):
def test_normalized_pixel(f3d_engine):
img = f3d_engine.window.render_to_image()
assert img[0, 0] == [0.2, 0.2, 0.2]
assert img[(0, 0)] == [0.2, 0.2, 0.2]
assert img.normalized_pixel((0, 0)) == [0.2, 0.2, 0.2]


@pytest.mark.parametrize(
Expand Down
11 changes: 11 additions & 0 deletions resources/colormaps/licenses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
|Name |Author |License |
|----------|----------------------------------------------------|------------|
|cividis |Jamie Nunez |BSD-3-Clause|
|cubehelix | |BSD-2-Clause|
|gist_earth|David Munro |BSD-3-Clause|
|hot | |PSF |
|inferno |Nathaniel J. Smith, Stefan van der Walt |CC0 |
|magma |Nathaniel J. Smith, Stefan van der Walt |CC0 |
|plasma |Nathaniel J. Smith, Stefan van der Walt |CC0 |
|seismic | |PSF |
|viridis |Nathaniel J. Smith, Stefan van der Walt, Eric Firing|CC0 |

0 comments on commit ab08a62

Please sign in to comment.