Skip to content

Commit

Permalink
use floor instead of trunc
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Oct 7, 2024
1 parent 4481c81 commit fca68d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Tests/test_image_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"1": (256, 16384, 0, 10994, b"zk4Al^)(jtioYSyJT@emR4<LAz}yHLJ6>*b*%R1K"),
"CMYK": (1024, 65536, 0, 16384, b"zqm8<<;r>h42v|$3xNIR#fG2=P&z(awe2&{GK(8o"),
"F": (256, 16384, 0, 662, b"*EIrB8n_NEx9e()#ao<>L)@gEjm|N%I8B)YhA8V~"),
"HSV": (768, 49152, 0, 1696, b"j%?cE2k-B?O6^F|tr1#8hhv$YoM{j;4co)RxZt#w"),
"HSV": (768, 49152, 0, 1696, b"pQV&1wHrT`AI}V<d!`6uVnfXZ6PVG|S#zOVn}m!;"),
"I": (256, 16384, 0, 662, b"*EIrB8n_NEx9e()#ao<>L)@gEjm|N%I8B)YhA8V~"),
"I;16": (256, 16384, 0, 8192, b"S+c=3i+Fs3wK2>Q<8rq@PgsAg=nE1VLdMtHZ2K8$"),
"I;16B": (256, 16384, 0, 8192, b"S+c=3i+Fs3wK2>Q<8rq@PgsAg=nE1VLdMtHZ2K8$"),
Expand Down Expand Up @@ -44,5 +44,5 @@ def deterministic_hash(data: list[int]) -> bytes:
def test_histogram(mode: str) -> None:
h = hopper(mode).histogram()
data = (len(h), sum(h), min(h), max(h), deterministic_hash(h))
print(h)
if mode == "HSV": print(h)
assert data == expected_data[mode]
3 changes: 1 addition & 2 deletions src/libImaging/Convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ rgb2hsv_row(UINT8 *out, const UINT8 *in) {
// https://stackoverflow.com/a/3883019/3878168
// "h = (h/6.0) % 1.0" in Python can be computed as:
h = h / 6.0;
h = (h - trunc(h)) + 1.0;
h = h - trunc(h);
h = h - floor(h);

uh = (UINT8)(255.0 * h);
us = 255 * color_range / maxc;
Expand Down

0 comments on commit fca68d4

Please sign in to comment.