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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Color.cpp

Issue 1530723004: Use clampTo instead of chaining std::max(std::min(...)) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handling that minimumThumbLength > trackLen. Created 5 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const RGBA32 Color::gray; 44 const RGBA32 Color::gray;
45 const RGBA32 Color::lightGray; 45 const RGBA32 Color::lightGray;
46 const RGBA32 Color::transparent; 46 const RGBA32 Color::transparent;
47 #endif 47 #endif
48 48
49 static const RGBA32 lightenedBlack = 0xFF545454; 49 static const RGBA32 lightenedBlack = 0xFF545454;
50 static const RGBA32 darkenedWhite = 0xFFABABAB; 50 static const RGBA32 darkenedWhite = 0xFFABABAB;
51 51
52 RGBA32 makeRGB(int r, int g, int b) 52 RGBA32 makeRGB(int r, int g, int b)
53 { 53 {
54 return 0xFF000000 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::m in(g, 255)) << 8 | std::max(0, std::min(b, 255)); 54 return 0xFF000000 | clampTo(r, 0, 255) << 16 | clampTo(g, 0, 255) << 8 | cla mpTo(b, 0, 255);
55 } 55 }
56 56
57 RGBA32 makeRGBA(int r, int g, int b, int a) 57 RGBA32 makeRGBA(int r, int g, int b, int a)
58 { 58 {
59 return std::max(0, std::min(a, 255)) << 24 | std::max(0, std::min(r, 255)) < < 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255)); 59 return clampTo(a, 0, 255) << 24 | clampTo(r, 0, 255) << 16 | clampTo(g, 0, 2 55) << 8 | clampTo(b, 0, 255);
60 } 60 }
61 61
62 static int colorFloatToRGBAByte(float f) 62 static int colorFloatToRGBAByte(float f)
63 { 63 {
64 return std::max(0, std::min(static_cast<int>(lroundf(255.0f * f)), 255)); 64 return clampTo(static_cast<int>(lroundf(255.0f * f)), 0, 255);
65 } 65 }
66 66
67 RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a) 67 RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a)
68 { 68 {
69 return colorFloatToRGBAByte(a) << 24 | colorFloatToRGBAByte(r) << 16 | color FloatToRGBAByte(g) << 8 | colorFloatToRGBAByte(b); 69 return colorFloatToRGBAByte(a) << 24 | colorFloatToRGBAByte(r) << 16 | color FloatToRGBAByte(g) << 8 | colorFloatToRGBAByte(b);
70 } 70 }
71 71
72 static double calcHue(double temp1, double temp2, double hueVal) 72 static double calcHue(double temp1, double temp2, double hueVal)
73 { 73 {
74 if (hueVal < 0.0) 74 if (hueVal < 0.0)
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 (color.green() * alpha + 254) / 255, 449 (color.green() * alpha + 254) / 255,
450 (color.blue() * alpha + 254) / 255, 450 (color.blue() * alpha + 254) / 255,
451 alpha).rgb(); 451 alpha).rgb();
452 } else 452 } else
453 pixelColor = color.rgb(); 453 pixelColor = color.rgb();
454 454
455 return pixelColor; 455 return pixelColor;
456 } 456 }
457 457
458 } // namespace blink 458 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698