Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Mastodon
Commits
328d3a87
Unverified
Commit
328d3a87
authored
9 months ago
by
Claire
Committed by
GitHub
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix libvips color extraction when multiple maxima differ only on blue component (#30632)
parent
f48f39a7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/paperclip/color_extractor.rb
+14
-12
14 additions, 12 deletions
lib/paperclip/color_extractor.rb
with
14 additions
and
12 deletions
lib/paperclip/color_extractor.rb
+
14
−
12
View file @
328d3a87
...
...
@@ -122,26 +122,28 @@ module Paperclip
colors
[
'out_array'
].
zip
(
colors
[
'x_array'
],
colors
[
'y_array'
]).
map
do
|
v
,
x
,
y
|
rgb_from_xyv
(
histogram
,
x
,
y
,
v
)
end
.
reverse
end
.
flatten
.
reverse
.
uniq
end
# rubocop:disable Naming/MethodParameterName
def
rgb_from_xyv
(
image
,
x
,
y
,
v
)
pixel
=
image
.
getpoint
(
x
,
y
)
# Unfortunately, we only have the first 2 dimensions, so try to
# guess the third one by looking up the value
# As we only have the first 2 dimensions for this maximum, we
# can't distinguish with different maxima with the same `r` and `g`
# values but different `b` values.
#
# Therefore, we return an array of maxima, which is always non-empty,
# but may contain multiple colors with the same values.
# NOTE: this means that if multiple bins with the same `r` and `g`
# components have the same number of occurrences, we will always return
# the one with the lowest `b` value. This means that in case of a tie,
# we will return the same color twice and skip the ones it tied with.
z
=
pixel
.
find_index
(
v
)
pixel
.
filter_map
.
with_index
do
|
pv
,
z
|
next
if
pv
!=
v
r
=
(
x
+
0.5
)
*
256
/
BINS
g
=
(
y
+
0.5
)
*
256
/
BINS
b
=
(
z
+
0.5
)
*
256
/
BINS
ColorDiff
::
Color
::
RGB
.
new
(
r
,
g
,
b
)
r
=
(
x
+
0.5
)
*
256
/
BINS
g
=
(
y
+
0.5
)
*
256
/
BINS
b
=
(
z
+
0.5
)
*
256
/
BINS
ColorDiff
::
Color
::
RGB
.
new
(
r
,
g
,
b
)
end
end
def
w3c_contrast
(
color1
,
color2
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment