Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: core/fxcodec/codec/fx_codec_icc.cpp

Issue 2096723003: Double AdobeCMYK_to_sRGB speed with faster rounding (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Comment and ASSERT tweaks Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxcodec/codec/codec_int.h" 7 #include "core/fxcodec/codec/codec_int.h"
8 #include "core/fxcodec/include/fx_codec.h" 8 #include "core/fxcodec/include/fx_codec.h"
9 #include "third_party/lcms2-2.6/include/lcms2.h" 9 #include "third_party/lcms2-2.6/include/lcms2.h"
10 10
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 G = fix_g >> 8; 1970 G = fix_g >> 8;
1971 B = fix_b >> 8; 1971 B = fix_b >> 8;
1972 } 1972 }
1973 void AdobeCMYK_to_sRGB(FX_FLOAT c, 1973 void AdobeCMYK_to_sRGB(FX_FLOAT c,
1974 FX_FLOAT m, 1974 FX_FLOAT m,
1975 FX_FLOAT y, 1975 FX_FLOAT y,
1976 FX_FLOAT k, 1976 FX_FLOAT k,
1977 FX_FLOAT& R, 1977 FX_FLOAT& R,
1978 FX_FLOAT& G, 1978 FX_FLOAT& G,
1979 FX_FLOAT& B) { 1979 FX_FLOAT& B) {
1980 uint8_t c1 = FXSYS_round(c * 255); 1980 // Convert to uint8_t with round-to-nearest. Avoid using FXSYS_round because
1981 uint8_t m1 = FXSYS_round(m * 255); 1981 // it is incredibly expensive with VC++ (tested on VC++ 2015) because round()
1982 uint8_t y1 = FXSYS_round(y * 255); 1982 // is very expensive.
1983 uint8_t k1 = FXSYS_round(k * 255); 1983 // Adding 0.5f and truncating can round the wrong direction in some edge
1984 // cases but these do not matter in this context. For instance, the float that
1985 // is one ULP (unit in the last place) before 0.5 should round to zero but
1986 // this will round it to one. These edge cases are never hit in this function
1987 // due to the very limited precision of the input integers.
1988 // This method also doesn't handle negative or extremely large numbers, but
1989 // those are not needed here.
1990 uint8_t c1 = int(c * 255.f + 0.5f);
1991 uint8_t m1 = int(m * 255.f + 0.5f);
1992 uint8_t y1 = int(y * 255.f + 0.5f);
1993 uint8_t k1 = int(k * 255.f + 0.5f);
1994
1995 ASSERT(c1 == FXSYS_round(c * 255));
1996 ASSERT(m1 == FXSYS_round(m * 255));
1997 ASSERT(y1 == FXSYS_round(y * 255));
1998 ASSERT(k1 == FXSYS_round(k * 255));
1999
1984 uint8_t r, g, b; 2000 uint8_t r, g, b;
1985 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); 2001 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b);
1986 R = 1.0f * r / 255; 2002 // Multiply by a constant rather than dividing because division is much
1987 G = 1.0f * g / 255; 2003 // more expensive.
1988 B = 1.0f * b / 255; 2004 R = r * (1.0f / 255);
2005 G = g * (1.0f / 255);
2006 B = b * (1.0f / 255);
1989 } 2007 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698