color-profile https://www.e-learn.cn/tag/color-profile zh-hans Change the color profile of a page in CSS https://www.e-learn.cn/topic/4061011 <span>Change the color profile of a page in CSS</span> <span><span lang="" about="/user/192" typeof="schema:Person" property="schema:name" datatype="">谁都会走</span></span> <span>2021-02-06 23:02:00</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am working on a late-2019 Macbook Pro, which supports the <strong>P3 color gamut</strong> (wide color).</p> <p>I'm building a website that includes large blocks of vivid color, where I just want the colors to be as bright as possible.</p> <p><strong>Most of the intended audience will also have P3-capable monitors.</strong></p> <p><strong>I discovered that my website looks amazing in Firefox</strong> -- much better than it does in Safari. It turns out that Firefox doesn't do any color management so the full P3 gamut is applied.</p> <p>Safari converts (or preserves) my colors in the sRGB space, which makes them dull. Firefox, not using any color management, uses the full P3 gamut.</p> <p>To see an example of the difference, run the snipped below (only works on Safari on a computer with wide color):</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;&lt;head&gt;&lt;style&gt; #box1 { background-color: color(display-p3 0 1 0); height:50px; } #box2 { background-color: rgb(0, 255, 0); height:50px; } &lt;/style&gt;&lt;/head&gt;&lt;body&gt; &lt;div id="box1"&gt;P3 Color&lt;/div&gt; &lt;div id="box2"&gt;sRGB Color&lt;/div&gt;</code></pre> </div> </div> <p>You will see that <strong>the green is much more vivid</strong> when the color is defined in the P3 space.</p> <p><strong>Alternatively, you can open this code in Chrome and Firefox.</strong> Side by side, you can easily see that the green is much richer in Firefox.</p> <p>What I am looking for is a way to tell Safari: <strong>don't limit the colors to sRGB, use the full brightness of P3.</strong></p> <p>I would like to rewrite my css, but only have to do it once. Something like adding at the top:</p> <pre><code>@media color-gamut: p3{ @color-profile{ name: p3; src: url(/files/P3.icc); } } </code></pre> <p>I am working in an automated environment, and any solution where I have to manually specify the color space for each image is a non-starter.</p> <p>What I can modify is the <strong>basic document template</strong>, including base CSS, which will be the same for all pages.</p> <p>Any solution is welcome. It's a bummer that I have this great computer with an amazing display and it's intentionally making all my colors more faded than necessary.</p> <br /><h3>回答1:</h3><br /><p>I've tested this and had a different experience altogether.</p> <p>Running your snippet in Safari, Chrome, Firefox -- left to right:</p> <p></p> <p>It's probably not visible in this screenshot (link) because of imgur downsampling but the P3 box in Safari was much more vivid. Chrome did not seem to support P3 at all while FF seemed to not support P3, yet rendered sRGB as as brightly as safari's P3... Yikes.</p> <hr /><p>@color-profile had been proposed but dropped so you cannot use it. What you <strong>can</strong> do, however, is a bit of <code>@supports</code> queries at the top of your CSS:</p> <pre><code>/* sRGB color. */ :root { --bright-green: rgb(0, 255, 0); } /* Display-P3 color, when supported. */ @supports (color: color(display-p3 0 1 0)) { :root { --bright-green: color(display-p3 0 1 0); } } #box1 { background-color: var(--bright-green); height:50px; } #box2 { background-color: rgb(0, 255, 0); height:50px; } </code></pre> <p>After the fallbacks, both Safari &amp; FF render properly but Chrome still reverts to sRGB...</p> <p></p> <p>Screenshot link is here.</p> <p>Summing up, you can (and should) specify P3 whenever possible but also add fallbacks.</p> <hr /><p>Finally, I don't understand what you meant by</p> <blockquote> <p>any solution where I have to manually specify the color space for each image is a non-starter.</p> </blockquote> <p>Are we then talking about images or definable (bg) colors?</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/61851331/change-the-color-profile-of-a-page-in-css</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/css" hreflang="zh-hans">css</a></div> <div class="field--item"><a href="/tag/safari" hreflang="zh-hans">safari</a></div> <div class="field--item"><a href="/tag/default-value" hreflang="zh-hans">default-value</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> <div class="field--item"><a href="/tag/color-management" hreflang="zh-hans">color-management</a></div> </div> </div> Sat, 06 Feb 2021 15:02:00 +0000 谁都会走 4061011 at https://www.e-learn.cn Change the color profile of a page in CSS https://www.e-learn.cn/topic/4061007 <span>Change the color profile of a page in CSS</span> <span><span lang="" about="/user/229" typeof="schema:Person" property="schema:name" datatype="">喜欢而已</span></span> <span>2021-02-06 22:46:45</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am working on a late-2019 Macbook Pro, which supports the <strong>P3 color gamut</strong> (wide color).</p> <p>I'm building a website that includes large blocks of vivid color, where I just want the colors to be as bright as possible.</p> <p><strong>Most of the intended audience will also have P3-capable monitors.</strong></p> <p><strong>I discovered that my website looks amazing in Firefox</strong> -- much better than it does in Safari. It turns out that Firefox doesn't do any color management so the full P3 gamut is applied.</p> <p>Safari converts (or preserves) my colors in the sRGB space, which makes them dull. Firefox, not using any color management, uses the full P3 gamut.</p> <p>To see an example of the difference, run the snipped below (only works on Safari on a computer with wide color):</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;&lt;head&gt;&lt;style&gt; #box1 { background-color: color(display-p3 0 1 0); height:50px; } #box2 { background-color: rgb(0, 255, 0); height:50px; } &lt;/style&gt;&lt;/head&gt;&lt;body&gt; &lt;div id="box1"&gt;P3 Color&lt;/div&gt; &lt;div id="box2"&gt;sRGB Color&lt;/div&gt;</code></pre> </div> </div> <p>You will see that <strong>the green is much more vivid</strong> when the color is defined in the P3 space.</p> <p><strong>Alternatively, you can open this code in Chrome and Firefox.</strong> Side by side, you can easily see that the green is much richer in Firefox.</p> <p>What I am looking for is a way to tell Safari: <strong>don't limit the colors to sRGB, use the full brightness of P3.</strong></p> <p>I would like to rewrite my css, but only have to do it once. Something like adding at the top:</p> <pre><code>@media color-gamut: p3{ @color-profile{ name: p3; src: url(/files/P3.icc); } } </code></pre> <p>I am working in an automated environment, and any solution where I have to manually specify the color space for each image is a non-starter.</p> <p>What I can modify is the <strong>basic document template</strong>, including base CSS, which will be the same for all pages.</p> <p>Any solution is welcome. It's a bummer that I have this great computer with an amazing display and it's intentionally making all my colors more faded than necessary.</p> <br /><h3>回答1:</h3><br /><p>I've tested this and had a different experience altogether.</p> <p>Running your snippet in Safari, Chrome, Firefox -- left to right:</p> <p></p> <p>It's probably not visible in this screenshot (link) because of imgur downsampling but the P3 box in Safari was much more vivid. Chrome did not seem to support P3 at all while FF seemed to not support P3, yet rendered sRGB as as brightly as safari's P3... Yikes.</p> <hr /><p>@color-profile had been proposed but dropped so you cannot use it. What you <strong>can</strong> do, however, is a bit of <code>@supports</code> queries at the top of your CSS:</p> <pre><code>/* sRGB color. */ :root { --bright-green: rgb(0, 255, 0); } /* Display-P3 color, when supported. */ @supports (color: color(display-p3 0 1 0)) { :root { --bright-green: color(display-p3 0 1 0); } } #box1 { background-color: var(--bright-green); height:50px; } #box2 { background-color: rgb(0, 255, 0); height:50px; } </code></pre> <p>After the fallbacks, both Safari &amp; FF render properly but Chrome still reverts to sRGB...</p> <p></p> <p>Screenshot link is here.</p> <p>Summing up, you can (and should) specify P3 whenever possible but also add fallbacks.</p> <hr /><p>Finally, I don't understand what you meant by</p> <blockquote> <p>any solution where I have to manually specify the color space for each image is a non-starter.</p> </blockquote> <p>Are we then talking about images or definable (bg) colors?</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/61851331/change-the-color-profile-of-a-page-in-css</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/css" hreflang="zh-hans">css</a></div> <div class="field--item"><a href="/tag/safari" hreflang="zh-hans">safari</a></div> <div class="field--item"><a href="/tag/default-value" hreflang="zh-hans">default-value</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> <div class="field--item"><a href="/tag/color-management" hreflang="zh-hans">color-management</a></div> </div> </div> Sat, 06 Feb 2021 14:46:45 +0000 喜欢而已 4061007 at https://www.e-learn.cn Change the color profile of a page in CSS https://www.e-learn.cn/topic/4061006 <span>Change the color profile of a page in CSS</span> <span><span lang="" about="/user/122" typeof="schema:Person" property="schema:name" datatype="">[亡魂溺海]</span></span> <span>2021-02-06 22:42:28</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am working on a late-2019 Macbook Pro, which supports the <strong>P3 color gamut</strong> (wide color).</p> <p>I'm building a website that includes large blocks of vivid color, where I just want the colors to be as bright as possible.</p> <p><strong>Most of the intended audience will also have P3-capable monitors.</strong></p> <p><strong>I discovered that my website looks amazing in Firefox</strong> -- much better than it does in Safari. It turns out that Firefox doesn't do any color management so the full P3 gamut is applied.</p> <p>Safari converts (or preserves) my colors in the sRGB space, which makes them dull. Firefox, not using any color management, uses the full P3 gamut.</p> <p>To see an example of the difference, run the snipped below (only works on Safari on a computer with wide color):</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;&lt;head&gt;&lt;style&gt; #box1 { background-color: color(display-p3 0 1 0); height:50px; } #box2 { background-color: rgb(0, 255, 0); height:50px; } &lt;/style&gt;&lt;/head&gt;&lt;body&gt; &lt;div id="box1"&gt;P3 Color&lt;/div&gt; &lt;div id="box2"&gt;sRGB Color&lt;/div&gt;</code></pre> </div> </div> <p>You will see that <strong>the green is much more vivid</strong> when the color is defined in the P3 space.</p> <p><strong>Alternatively, you can open this code in Chrome and Firefox.</strong> Side by side, you can easily see that the green is much richer in Firefox.</p> <p>What I am looking for is a way to tell Safari: <strong>don't limit the colors to sRGB, use the full brightness of P3.</strong></p> <p>I would like to rewrite my css, but only have to do it once. Something like adding at the top:</p> <pre><code>@media color-gamut: p3{ @color-profile{ name: p3; src: url(/files/P3.icc); } } </code></pre> <p>I am working in an automated environment, and any solution where I have to manually specify the color space for each image is a non-starter.</p> <p>What I can modify is the <strong>basic document template</strong>, including base CSS, which will be the same for all pages.</p> <p>Any solution is welcome. It's a bummer that I have this great computer with an amazing display and it's intentionally making all my colors more faded than necessary.</p> <br /><h3>回答1:</h3><br /><p>I've tested this and had a different experience altogether.</p> <p>Running your snippet in Safari, Chrome, Firefox -- left to right:</p> <p></p> <p>It's probably not visible in this screenshot (link) because of imgur downsampling but the P3 box in Safari was much more vivid. Chrome did not seem to support P3 at all while FF seemed to not support P3, yet rendered sRGB as as brightly as safari's P3... Yikes.</p> <hr /><p>@color-profile had been proposed but dropped so you cannot use it. What you <strong>can</strong> do, however, is a bit of <code>@supports</code> queries at the top of your CSS:</p> <pre><code>/* sRGB color. */ :root { --bright-green: rgb(0, 255, 0); } /* Display-P3 color, when supported. */ @supports (color: color(display-p3 0 1 0)) { :root { --bright-green: color(display-p3 0 1 0); } } #box1 { background-color: var(--bright-green); height:50px; } #box2 { background-color: rgb(0, 255, 0); height:50px; } </code></pre> <p>After the fallbacks, both Safari &amp; FF render properly but Chrome still reverts to sRGB...</p> <p></p> <p>Screenshot link is here.</p> <p>Summing up, you can (and should) specify P3 whenever possible but also add fallbacks.</p> <hr /><p>Finally, I don't understand what you meant by</p> <blockquote> <p>any solution where I have to manually specify the color space for each image is a non-starter.</p> </blockquote> <p>Are we then talking about images or definable (bg) colors?</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/61851331/change-the-color-profile-of-a-page-in-css</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/css" hreflang="zh-hans">css</a></div> <div class="field--item"><a href="/tag/safari" hreflang="zh-hans">safari</a></div> <div class="field--item"><a href="/tag/default-value" hreflang="zh-hans">default-value</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> <div class="field--item"><a href="/tag/color-management" hreflang="zh-hans">color-management</a></div> </div> </div> Sat, 06 Feb 2021 14:42:28 +0000 [亡魂溺海] 4061006 at https://www.e-learn.cn PIL/Pillow decode icc profile information https://www.e-learn.cn/topic/3861404 <span>PIL/Pillow decode icc profile information</span> <span><span lang="" about="/user/19" typeof="schema:Person" property="schema:name" datatype="">天大地大妈咪最大</span></span> <span>2020-10-15 20:08:48</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>来源:<code>https://stackoverflow.com/questions/31865743/pil-pillow-decode-icc-profile-information</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/encoding" hreflang="zh-hans">encoding</a></div> <div class="field--item"><a href="/tag/python-imaging-library" hreflang="zh-hans">python-imaging-library</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> </div> </div> Thu, 15 Oct 2020 12:08:48 +0000 天大地大妈咪最大 3861404 at https://www.e-learn.cn PIL/Pillow decode icc profile information https://www.e-learn.cn/topic/3861403 <span>PIL/Pillow decode icc profile information</span> <span><span lang="" about="/user/219" typeof="schema:Person" property="schema:name" datatype="">偶尔善良</span></span> <span>2020-10-15 20:07:57</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>来源:<code>https://stackoverflow.com/questions/31865743/pil-pillow-decode-icc-profile-information</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/encoding" hreflang="zh-hans">encoding</a></div> <div class="field--item"><a href="/tag/python-imaging-library" hreflang="zh-hans">python-imaging-library</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> </div> </div> Thu, 15 Oct 2020 12:07:57 +0000 偶尔善良 3861403 at https://www.e-learn.cn PIL/Pillow decode icc profile information https://www.e-learn.cn/topic/3861382 <span>PIL/Pillow decode icc profile information</span> <span><span lang="" about="/user/177" typeof="schema:Person" property="schema:name" datatype="">天涯浪子</span></span> <span>2020-10-15 19:59:56</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>来源:<code>https://stackoverflow.com/questions/31865743/pil-pillow-decode-icc-profile-information</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/encoding" hreflang="zh-hans">encoding</a></div> <div class="field--item"><a href="/tag/python-imaging-library" hreflang="zh-hans">python-imaging-library</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> </div> </div> Thu, 15 Oct 2020 11:59:56 +0000 天涯浪子 3861382 at https://www.e-learn.cn In Java converting an image to sRGB makes the image too bright https://www.e-learn.cn/topic/3047385 <span>In Java converting an image to sRGB makes the image too bright</span> <span><span lang="" about="/user/117" typeof="schema:Person" property="schema:name" datatype="">℡╲_俬逩灬.</span></span> <span>2020-01-01 17:03:21</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have multiple images with a custom profile embedded in them and want to convert the image to sRGB in order to serve it up to a browser. I have seen code like the following:</p> <pre><code>BufferedImage image = ImageIO.read(fileIn); ColorSpace ics = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorConvertOp cco = new ColorConvertOp(ics, null); BufferedImage result = cco.filter(image, null); ImageIO.write(result, "PNG", fileOut); </code></pre> <p>where <code>fileIn</code> and <code>fileOut</code> are File objects representing the input file and output file respectively. This works to an extent. The problem is that the resulting image is lighter than the original. If I was to convert the color space in photoshop the colors would appear the same. In fact if I pull up both images with photoshop and take a screen shot and sample the colors, they are the same. What is photoshop doing that the code above isn't and what can I do to correct the problem?</p> <p>There are various types of images being converted, including JPEG, PNG, and TIFF. I have tried using TwelveMonkeys to read in JPEG and TIFF images and I still get the same effect, where the image is too light. The conversion process seems worst when applied to an image that didn't have an embedded profile in the first place.</p> <p><strong>Edit:</strong></p> <p></p><p></p><img class="b-lazy" data-src="https://i0.wp.com/i.stack.imgur.com/QPADjt.png" data-original="https://i0.wp.com/i.stack.imgur.com/QPADjt.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <p></p><img class="b-lazy" data-src="https://i0.wp.com/i.stack.imgur.com/bmJIEt.png" data-original="https://i0.wp.com/i.stack.imgur.com/bmJIEt.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <p></p><img class="b-lazy" data-src="https://i0.wp.com/i.stack.imgur.com/bs7H5t.png" data-original="https://i0.wp.com/i.stack.imgur.com/bs7H5t.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <p>I've added some sample images to help explain the problem.</p> <ol><li>This image is the one with the color profile embedded in it. Viewed on some browsers there won't be a noticeable difference between this one and the next but viewed in Chrome on Mac OSX and Windows it currently appears darker than it should. This is where my problem originates in the first place. I need to convert the image to something that will show up correctly in Chrome.</li> <li>This is an image converted with ImageMagick to the Adobe RGB 1998 color profile, which Chrome appears to be able to display correctly.</li> <li>This is the image that I converted using the code above and it appears lighter than it should.</li> </ol><p>(Note that the images above are on imgur so to make them larger, simply remove the "t" from the end of the filename, before the file extension.)</p> <br /><h3>回答1:</h3><br /><p><strong>This was my initial solution which worked but I didn't like having to use ImageMagick. I have created another answer based off of the solution I ended up sticking with.</strong></p> <p>I gave in and ended up using im4java, which is a wrapper around the command line tool of image magick. When I use the following code to get a BufferedImage, it works really well.</p> <pre><code>IMOperation op = new IMOperation(); op.addImage(fileIn.getAbsolutePath()); op.profile(colorFileIn.getAbsolutePath()); op.addImage("png:-"); ConvertCmd cmd = new ConvertCmd(); Stream2BufferedImage s2b = new Stream2BufferedImage(); cmd.setOutputConsumer(s2b); cmd.run(op); BufferedImage image = s2b.getImage(); </code></pre> <p>I can also use the library to apply a CMYK profile for print when needed. It would be nice if ColorConvertOp did the conversion correctly but for now, at least, this is my solution. In order to reach parity with my question the im4java code to achieve the same effect in the question is:</p> <pre><code>ConvertCmd cmd = new ConvertCmd(); IMOperation op = new IMOperation(); op.addImage(fileIn.getAbsolutePath()); op.profile(colorFileIn.getAbsolutePath()); op.addImage(fileOut.getAbsolutePath()); cmd.run(op); </code></pre> <p>where <code>colorFileIn.getAboslutePath()</code> is the location of the sRGB color profile on the machine. Since im4java is using the command line it's not as straight forward how to perform operations but the library is explained in detail here. I originally had issues with image magick not working on my Mac as explained in the question. I installed it using brew but it turns out on a Mac you have to install it like <code>brew install imagemagick --with-little-cms</code>. After that image magick worked fine for me.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>I found a solution that doesn't require ImageMagick. Basically Java doesn't respect the profile when loading the image so if there is one it needs to get loaded. Here is a code snippet of what I did to accomplish this:</p> <pre><code>private BufferedImage loadBufferedImage(InputStream inputStream) throws IOException, BadElementException { byte[] imageBytes = IOUtils.toByteArray(inputStream); BufferedImage incorrectImage = ImageIO.read(new ByteArrayInputStream(imageBytes)); if (incorrectImage.getColorModel() instanceof ComponentColorModel) { // Java does not respect the color profile embedded in a component based image, so if there is a color // profile, detected using iText, then create a buffered image with the correct profile. Image iTextImage = Image.getInstance(imageBytes); com.itextpdf.text.pdf.ICC_Profile iTextProfile = iTextImage.getICCProfile(); if (iTextProfile == null) { // If no profile is present than the image should be processed as is. return incorrectImage; } else { // If there is a profile present then create a buffered image with the profile embedded. byte[] profileData = iTextProfile.getData(); ICC_Profile profile = ICC_Profile.getInstance(profileData); ICC_ColorSpace ics = new ICC_ColorSpace(profile); boolean hasAlpha = incorrectImage.getColorModel().hasAlpha(); boolean isAlphaPremultiplied = incorrectImage.isAlphaPremultiplied(); int transparency = incorrectImage.getTransparency(); int transferType = DataBuffer.TYPE_BYTE; ComponentColorModel ccm = new ComponentColorModel(ics, hasAlpha, isAlphaPremultiplied, transparency, transferType); return new BufferedImage(ccm, incorrectImage.copyData(null), isAlphaPremultiplied, null); } } else if (incorrectImage.getColorModel() instanceof IndexColorModel) { return incorrectImage; } else { throw new UnsupportedEncodingException("Unsupported color model type."); } } </code></pre> <p>This answer does use iText, which is generally used for PDF creation and manipulation, but it happens to process the ICC profiles correctly and I'm already depending on it for my project so it happens to be a much better choice than ImageMagick.</p> <p>The code in the question then ends up as follows:</p> <pre><code>BufferedImage image = loadBufferedImage(new FileInputStream(fileIn)); ColorSpace ics = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorConvertOp cco = new ColorConvertOp(ics, null); BufferedImage result = cco.filter(image, null); ImageIO.write(result, "PNG", fileOut); </code></pre> <p>which works great.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/28593941/in-java-converting-an-image-to-srgb-makes-the-image-too-bright</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/image" hreflang="zh-hans">image</a></div> <div class="field--item"><a href="/tag/bufferedimage" hreflang="zh-hans">bufferedimage</a></div> <div class="field--item"><a href="/tag/color-space" hreflang="zh-hans">color-space</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> </div> </div> Wed, 01 Jan 2020 09:03:21 +0000 ℡╲_俬逩灬. 3047385 at https://www.e-learn.cn Converting colors (not images) with ImageMagick https://www.e-learn.cn/topic/3021322 <span>Converting colors (not images) with ImageMagick</span> <span><span lang="" about="/user/132" typeof="schema:Person" property="schema:name" datatype="">时光总嘲笑我的痴心妄想</span></span> <span>2019-12-31 05:30:14</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>More specifically, I'd like to accurately convert a CMYK value (probably from the <code>ISO Coated v2</code> space) to an RGB value (probably from the <code>sRGB</code> space) on the Ruby platform (probably using ICC profiles).</p> <p>ImageMagick seemed like a good place to start, but I've also heard that LittleCMS might have been ported/wrapped to work with <code>Ruby</code>.</p> <p>Once again, I'm looking to convert single colors, NOT image files. Any ideas?</p> <br /><h3>回答1:</h3><br /><p>In ImageMagick, you can do the following:</p> <pre><code>convert xc:"cmyk(0,255,255,0)" -colorspace sRGB -format "%[pixel:u.p{0,0}]\n" info: red convert xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info: srgb(93%,11%,14%) </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><blockquote> <p>Is there anything you can tweak in format to ensure more significant digits in the srgb(X%,X%,X%)</p> </blockquote> <p>Likely due to different IM versions. IM 7.0.7.8 shows srgb(93.0648%,11.1254%,14.1741%). IM 6.9.9.20 shows integers. I tried adding -precision 4 to IM 6 command line, but still get integers. To get more precision, one has to parse the txt: output format.</p> <p>For example without parsing:</p> <pre><code>convert xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc txt: # ImageMagick pixel enumeration: 1,1,65535,srgb 0,0: (60990,7291,9289) #EE3E1C7B2449 srgb(93%,11%,14%) </code></pre> <p>So you need to parse the 16-bit values (for IM Q16) in parenthesis, namely, (60990,7291,9289)</p> <pre><code>vals=`convert xc:"cmyk(0,255,255,0)" \ -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \ -profile /Users/fred/images/profiles/sRGB.icc txt: |\ tail -n +2 | sed -n 's/^.*[(]\(.*\)[)][ ]*\#.*$/\1/p'` red=`echo $vals | cut -d, -f1` green=`echo $vals | cut -d, -f2` blue=`echo $vals | cut -d, -f3` red=`convert -precision 4 xc: -format "%[fx:100*$red/quantumrange]" info:` green=`convert -precision 4 xc: -format "%[fx:100*$green/quantumrange]" info:` blue=`convert -precision 4 xc: -format "%[fx:100*$blue/quantumrange]" info:` color="srgb($red%,$green%,$blue%)" echo "$color" srgb(93.06%,11.13%,14.17%) </code></pre> <p>Adjust -precision, for the number of significant digits you want.</p> <p>NOTE: In IM 7, -precision does work.</p> <pre><code>magick xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info: srgb(93.0648%,11.1254%,14.1741%) magick -precision 4 xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info: srgb(93.06%,11.13%,14.17%) magick -precision 2 xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info: srgb(93%,11%,14%) </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/47022566/converting-colors-not-images-with-imagemagick</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/ruby-rails" hreflang="zh-hans">ruby-on-rails</a></div> <div class="field--item"><a href="/tag/ruby" hreflang="zh-hans">ruby</a></div> <div class="field--item"><a href="/tag/colors" hreflang="zh-hans">colors</a></div> <div class="field--item"><a href="/tag/imagemagick" hreflang="zh-hans">ImageMagick</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> </div> </div> Mon, 30 Dec 2019 21:30:14 +0000 时光总嘲笑我的痴心妄想 3021322 at https://www.e-learn.cn Is there an equivalent to WinAPI GetColorDirectory in .NET? https://www.e-learn.cn/topic/2841982 <span>Is there an equivalent to WinAPI GetColorDirectory in .NET?</span> <span><span lang="" about="/user/185" typeof="schema:Person" property="schema:name" datatype="">泪湿孤枕</span></span> <span>2019-12-24 01:37:20</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Is there an analogue of the function GetColorDirectory?</p> <p>Or should I just call through a DLL?</p> <p>The purpose is to get the path to the system directory with color profiles</p> <br /><h3>回答1:</h3><br /><p>As per MSDN you call it using the API:</p> <pre><code>[DllImport(DllImport.Mscms, CharSet = CharSet.Auto, BestFitMapping = false)] internal static extern bool GetColorDirectory(IntPtr pMachineName, StringBuilder pBuffer, ref uint pdwSize); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/14792764/is-there-an-equivalent-to-winapi-getcolordirectory-in-net</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/net" hreflang="zh-hans">.net</a></div> <div class="field--item"><a href="/tag/icc" hreflang="zh-hans">icc</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> </div> </div> Mon, 23 Dec 2019 17:37:20 +0000 泪湿孤枕 2841982 at https://www.e-learn.cn Convert RGB PNG to CMYK JPEG (using ICC Color Profiles) https://www.e-learn.cn/topic/2757177 <span>Convert RGB PNG to CMYK JPEG (using ICC Color Profiles)</span> <span><span lang="" about="/user/118" typeof="schema:Person" property="schema:name" datatype="">不打扰是莪最后的温柔</span></span> <span>2019-12-22 08:34:20</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I need to convert a PNG-File into a CMYK JPEG.</p> <p>During my research i've found multiple articles on SO decribing that problem. I've copied this answer using <code>BufferedImage</code> and <code>ColorConvertOp</code>.</p> <p>I came up with this little example:</p> <pre><code>public static void main(final String[] args) throws IOException { final String imageFile = "/tmp/page0.png"; final BufferedImage pngImage = ImageIO.read(new File(imageFile)); // convert PNG to JPEG // http://www.mkyong.com/java/convert-png-to-jpeg-image-file-in-java/ final BufferedImage rgbImage = new BufferedImage(pngImage.getWidth(), pngImage.getHeight(), BufferedImage.TYPE_INT_RGB); rgbImage.createGraphics().drawImage(pngImage, 0, 0, Color.WHITE, null); // RGB to CMYK using ColorConvertOp // https://stackoverflow.com/questions/380678/how-to-set-icc-color-profile-in-java-and-change-colorspace/2804370#2804370 final ICC_Profile ip = ICC_Profile.getInstance("icc/ISOcoated_v2_300_eci.icc"); // final ICC_Profile ip = ICC_Profile.getInstance("icc/CoatedFOGRA27.icc"); // final ICC_Profile ip = ICC_Profile.getInstance("icc/USWebUncoated.icc"); final ColorConvertOp cco = new ColorConvertOp(new ICC_ColorSpace(ip), null); final BufferedImage cmykImage = cco.filter(rgbImage, null); // Write the result into an bytearray final ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(cmykImage, "jpg", baos); baos.flush(); final byte[] imageInByte = baos.toByteArray(); } </code></pre> <p>The problem is, that it leads me into this exception:</p> <pre><code>Exception in thread "main" javax.imageio.IIOException: Invalid argument to native writeImage at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(Native Method) at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeOnThread(JPEGImageWriter.java:1058) at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:360) at javax.imageio.ImageWriter.write(ImageWriter.java:615) at javax.imageio.ImageIO.doWrite(ImageIO.java:1612) at javax.imageio.ImageIO.write(ImageIO.java:1578) at ... .pdf.ReportGeneratorPublicContentTest.main(ReportGeneratorPublicContentTest.java:69) </code></pre> <p>The message of the Exception doesn't help me. On this thread they say that sun jdk or JAI will fix the problem.</p> <p>I tried <code>apt-get install libjai-core-java</code> and the oracle JDK <code>jdk1.7.0_51</code>. The error still persists.</p> <br /><h3>回答1:</h3><br /><p>@Christian Schneider : After i download your image file with link of CMYK JPEG, i open file's property. I see color space of image is still RGB. This picture isn't converted to CMYK color. Please see the below link :</p> <p>how can I convert an RGB image to CMYK and vice versa in Java?</p> <p>lovelywib 's answer solved this.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>The problem was solved by using <code>TYPE_3BYTE_BGR</code> instead of <code>TYPE_INT_RGB</code>.</p> <pre><code>public static void main(String[] args) throws Exception { final String imageFile = "/tmp/page0.png"; final BufferedImage pngImage = ImageIO.read(new File(imageFile)); // convert PNG to JPEG // http://www.mkyong.com/java/convert-png-to-jpeg-image-file-in-java/ final BufferedImage rgbImage = new BufferedImage(pngImage.getWidth(), pngImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR); rgbImage.createGraphics().drawImage(pngImage, 0, 0, Color.WHITE, null); // RGB to CMYK using ColorConvertOp // http://stackoverflow.com/questions/380678/how-to-set-icc-color-profile-in-java-and-change-colorspace/2804370#2804370 final ICC_Profile ip = ICC_Profile.getInstance("icc/USWebUncoated.icc"); final ColorConvertOp cco = new ColorConvertOp(rgbImage.getColorModel().getColorSpace(), new ICC_ColorSpace(ip), null); final BufferedImage cmykImage = new BufferedImage(pngImage.getWidth(), pngImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR); cco.filter(rgbImage, cmykImage); // Write the result into an bytearray final ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(cmykImage, "JPEG", baos); baos.flush(); } </code></pre> <ul><li><p>RGB PNG: https://raw.github.com/d0x/questions/master/stackoverflowPlayground/src/main/resources/so22298328/page0.png</p></li> <li><p>CMYK JPEG: https://raw.github.com/d0x/questions/master/stackoverflowPlayground/src/main/resources/so22298328/page0.cmyk.jpg</p></li> <li><p>Maven Code at GitHub: https://github.com/d0x/questions/blob/master/stackoverflowPlayground/src/main/java/so22298328/Main.java</p></li> </ul><br /><br /><p>来源:<code>https://stackoverflow.com/questions/22298328/convert-rgb-png-to-cmyk-jpeg-using-icc-color-profiles</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/jai" hreflang="zh-hans">jai</a></div> <div class="field--item"><a href="/tag/color-profile" hreflang="zh-hans">color-profile</a></div> <div class="field--item"><a href="/tag/jmagick" hreflang="zh-hans">jmagick</a></div> <div class="field--item"><a href="/tag/color-management" hreflang="zh-hans">color-management</a></div> </div> </div> Sun, 22 Dec 2019 00:34:20 +0000 不打扰是莪最后的温柔 2757177 at https://www.e-learn.cn