-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix usage of IntCachedColorMap in Indexed PNG encoding #2075
Fix usage of IntCachedColorMap in Indexed PNG encoding #2075
Conversation
@metasim This is the bug you ran into. |
Right, I recall this not being subject to the |
@echeipesh I believe so. Glad there was actually something behind it. |
val r = createTile(arr) | ||
val h = r.histogram | ||
val colorMap = colorMap1.withNoDataColor(0).withBoundaryType(LessThanOrEqualTo).asInstanceOf[IntColorMap].cache(h) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid somehow this runtime cast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, except these two comments.
h.foreachValue(z => ch.setItem(z, map(z))) | ||
new IntCachedColorMap(colors, ch, options) | ||
val cachedColors = h.values() | ||
cfor(0)( _ < cachedColors.length, _ + 1) { i => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is h.totalCount
would be values count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h.totalCount
would give me the total number of times any value was seen bytes histogram across all buckets. Not sure if thats useful here. What are you thinking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, nothing smart, that's why i approved it. I tried to avoid somehow calculating length for the second time (as it's already known in fact) and trying to avoid distinct function usage. But no; it's fine as it is.
IntCachedColorMap
implementation was not covered by unit tests and turned out to be incorrect.This PR adds unit tests for its usage and changes the behavior to something that works.
It looks like this class fell through some cracks in the refactors. In reality it leans on implementation of
FastMapHistogram
to convert pixels directly to colors, which uses a hash table lookup.In effect we get
eC
color encoding instead ofLog
which is provided byIntColorMap