WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
23462
Add RGB -> CMYK conversion algorithm
https://bugs.webkit.org/show_bug.cgi?id=23462
Summary
Add RGB -> CMYK conversion algorithm
Scott Violet
Reported
2009-01-21 14:32:59 PST
CanvasStyle currently only handles RGB -> CMYK conversion for CG and QT. We should add a fallback algorithm for use on other platforms.
Attachments
Patch for RGB -> CMYK converter
(3.79 KB, patch)
2009-01-21 14:44 PST
,
Scott Violet
no flags
Details
Formatted Diff
Diff
Patch for RGB -> CMYK converter
(2.90 KB, patch)
2009-01-27 12:20 PST
,
Scott Violet
no flags
Details
Formatted Diff
Diff
Patch for RGB -> CMYK converter
(2.96 KB, patch)
2009-01-28 08:05 PST
,
Scott Violet
sam
: review-
Details
Formatted Diff
Diff
Adds Color(CMYKA) constructor
(3.73 KB, patch)
2009-01-29 11:09 PST
,
Scott Violet
sam
: review+
Details
Formatted Diff
Diff
Last patch had a bug, it used setFillColor when it should have used setStrokeColor
(1.23 KB, patch)
2009-02-05 13:14 PST
,
Scott Violet
no flags
Details
Formatted Diff
Diff
Show Obsolete
(4)
View All
Add attachment
proposed patch, testcase, etc.
Scott Violet
Comment 1
2009-01-21 14:44:37 PST
Created
attachment 26907
[details]
Patch for RGB -> CMYK converter As this converter gives different results than the CG one, at least one layout test produces different results. I was tempted to modify shouldBe in fast/js/resources/js-test-pre.js to accept another parameter that gives another possible accepted value, but wanted to make sure you want that before writing it. Let me know if you want me to.
mitz
Comment 2
2009-01-21 14:52:13 PST
Comment on
attachment 26907
[details]
Patch for RGB -> CMYK converter
> + int r = static_cast<int>(255 * (colors * (1 - m_cyan)));
This is suspicious, as it maps only one value to 255. Shouldn't nextafterf(256, 0) be used instead of 255?
Scott Violet
Comment 3
2009-01-21 15:10:13 PST
I must be missing something. colors is only 0-1 so that I believe we want 255 here.
mitz
Comment 4
2009-01-21 15:18:56 PST
(In reply to
comment #3
)
> I must be missing something. colors is only 0-1 so that I believe we want 255 > here.
I think you want to divide the interval [0,1] into 255 equal intervals, and map the interval [254/255, 1] to 255. However, static_cast<int>(255 * (colors * (1 - m_cyan))) will map [254/255, 1) to 254 and only the value 1 will map to 255.
mitz
Comment 5
2009-01-21 15:20:53 PST
(In reply to
comment #4
)
> (In reply to
comment #3
) > > I must be missing something. colors is only 0-1 so that I believe we want 255 > > here. > > I think you want to divide the interval [0,1] into 255 equal intervals, and map > the interval [254/255, 1] to 255. However, static_cast<int>(255 * (colors * (1 > - m_cyan))) will map [254/255, 1) to 254 and only the value 1 will map to 255.
Sorry, I meant to write: You want to divide the interval [0, 1] into 256 equal intervals, and map the interval [255/256, 1] to 255.
Scott Violet
Comment 6
2009-01-21 16:14:45 PST
I'm still confused. If I have a value x in the range [0-1] and need to map that to the range [0-n], then I multiply x by n. Perhaps I'm not understanding your syntax though. Could you post what you think the code should look like?
mitz
Comment 7
2009-01-21 21:59:17 PST
(In reply to
comment #6
)
> I'm still confused. > > If I have a value x in the range [0-1] and need to map that to the range [0-n], > then I multiply x by n. Perhaps I'm not understanding your syntax though. Could > you post what you think the code should look like?
Multiplication by n is correct if you are mapping floating point numbers to floating point numbers, but your mapping is to the set of integers {0, 1, ..., n}. static_cast<int>(n * x) truncates the result of the multiplication, meaning the only x value mapping to n is 1. I think static_cast<int>(nextafter(n, 0) * x) would map intervals of equal length to each integer in the set.
Scott Violet
Comment 8
2009-01-27 12:20:38 PST
Created
attachment 27080
[details]
Patch for RGB -> CMYK converter macdome showed me the error of my ways. New patch is attached. I went with nextafter instead of nextafterf as nextafterf doesn't give the behavior you mentioned.
Eric Seidel (no email)
Comment 9
2009-01-27 23:19:16 PST
Comment on
attachment 27080
[details]
Patch for RGB -> CMYK converter The cmykToRGB function should at least ASSERT that m_type is CMYK. Another way would be to make it a free function which took the 4 arguments, but this is probably less error-prone as is (if you add the ASSERT. I'll mark your first patch as obsolete since this one supersedes it.
Eric Seidel (no email)
Comment 10
2009-01-27 23:20:16 PST
Comment on
attachment 27080
[details]
Patch for RGB -> CMYK converter Oh, you also can leave the "Reviewed by nobody (OOPS!). line in when posting for review.
Scott Violet
Comment 11
2009-01-28 08:05:36 PST
Created
attachment 27105
[details]
Patch for RGB -> CMYK converter Updated patch adding ASSERT and reviewd by nobody. Thanks!
Eric Seidel (no email)
Comment 12
2009-01-28 16:41:02 PST
Comment on
attachment 27105
[details]
Patch for RGB -> CMYK converter Yeah, mitz should probably complete the review here. I'm unsure if the alpha conversion is correct either. I think that needs to use nextafter(256,0) as well. If that's true, that's simple and can be corrected when landing. Thanks for the update!
Sam Weinig
Comment 13
2009-01-28 18:13:07 PST
Comment on
attachment 27105
[details]
Patch for RGB -> CMYK converter
> Index: WebCore/ChangeLog > =================================================================== > --- WebCore/ChangeLog (revision 40097) > +++ WebCore/ChangeLog (working copy) > @@ -1,3 +1,19 @@ > +2009-01-21 Scott Violet <
sky@google.com
> > + > + Reviewed by nobody (OOPS!) > + > +
Bug 23462
: Add RGB -> CMYK conversion algorithm > + <
https://bugs.webkit.org/show_bug.cgi?id=23462
> > + > + Adds an RGB -> CMYK converter. This isn't perfect, but better than > + nothing.
Please remove tabs. Doesn't this actually add a cmyk -> rgb conversion?
> > +Color CanvasStyle::cmykToRGB() const > +{ > + ASSERT(m_type == CMYKA); > + double colors = 1 - m_black; > + int r = static_cast<int>(nextafter(256, 0) * (colors * (1 - m_cyan))); > + int g = static_cast<int>(nextafter(256, 0) * (colors * (1 - m_magenta))); > + int b = static_cast<int>(nextafter(256, 0) * (colors * (1 - m_yellow))); > + return Color(r, g, b, static_cast<int>(m_alpha * 255)); > +}
This seems much more suited to be a Color constructor. r-. Please make the function a color constructor.
Scott Violet
Comment 14
2009-01-29 08:34:16 PST
Just to be sure I understand what you're after. You're asking for a Color(float c, float m, float y, float k, float a) constructor, right? And this would have the code that I currently have in CanvasStyle::cmykToRGB, right? The CMYK color conversion seems platform specific though, are you sure you want to hoist this into Color?
Sam Weinig
Comment 15
2009-01-29 10:17:57 PST
Even if it is unused on some platforms at the moment I see no reason not to do in Color.
Scott Violet
Comment 16
2009-01-29 11:09:24 PST
Created
attachment 27152
[details]
Adds Color(CMYKA) constructor
Darin Fisher (:fishd, Google)
Comment 17
2009-02-05 12:14:42 PST
http://trac.webkit.org/changeset/40673
Scott Violet
Comment 18
2009-02-05 13:14:03 PST
Created
attachment 27360
[details]
Last patch had a bug, it used setFillColor when it should have used setStrokeColor
Dimitri Glazkov (Google)
Comment 19
2009-02-05 15:25:49 PST
Extra fix landed as
http://trac.webkit.org/changeset/40688
.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug