Skip to content

Commit 5f2355e

Browse files
committed
refactor: replace C-style casts with static_cast and simplify cpplint config
modernizes casting throughout the codebase and removes unused lint filters while preserving existing behavior.
1 parent 540236d commit 5f2355e

4 files changed

Lines changed: 54 additions & 58 deletions

File tree

CPPLINT.cfg

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# Disable readability checks
2-
filter=-readability/casting
3-
4-
# Disable build checks
5-
filter=-build/include_subdir,-build/include
1+
filter=-build/include
62

73
# allow longer lines
84
linelength=128

ColorCop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ BOOL CColorCopApp::GetShellFolderPath(LPCTSTR pShellFolder, LPTSTR pShellPath) {
107107

108108
if (rc == ERROR_SUCCESS) {
109109
rc = RegQueryValueEx(hkey, pShellFolder, NULL, &type,
110-
(BYTE *) pShellPath, &length);
110+
reinterpret_cast<BYTE*>(pShellPath), &length);
111111
RegCloseKey(hkey);
112112
}
113113

ColorCopDlg.cpp

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,9 @@ void CColorCopDlg::OnconvertRGB() {
735735
} else if (m_Appflags & RGBINT) {
736736
m_Hexcolor.Format(_T("%d,%d,%d"), m_Reddec, m_Greendec, m_Bluedec);
737737
} else if (m_Appflags & RGBFLOAT) {
738-
r = (float)m_Reddec / 255.0f;
739-
g = (float)m_Greendec / 255.0f;
740-
b = (float)m_Bluedec / 255.0f;
738+
r = static_cast<float>(m_Reddec) / 255.0f;
739+
g = static_cast<float>(m_Greendec) / 255.0f;
740+
b = static_cast<float>(m_Bluedec) / 255.0f;
741741
m_Hexcolor.Format(_T("%0.*f,%0.*f,%0.*f"), m_FloatPrecision, r, m_FloatPrecision, g, m_FloatPrecision, b);
742742
} else if (m_Appflags & ModeVisualC) {
743743
m_Hexcolor.Format(_T("0x00%.2x%.2x%.2x"), m_Bluedec, m_Greendec, m_Reddec);
@@ -895,7 +895,7 @@ void CColorCopDlg::setSeedColor() {
895895
OrigSwatch.C = m_Bluedec;
896896

897897
// convert the color to HSL
898-
RGBtoHSL((int) OrigSwatch.A, (int) OrigSwatch.B, (int) OrigSwatch.C);
898+
RGBtoHSL(static_cast<int>(OrigSwatch.A), static_cast<int>(OrigSwatch.B), static_cast<int>(OrigSwatch.C));
899899

900900
// set the swatch to the HSL values
901901
OrigSwatch.A = Hue;
@@ -907,54 +907,54 @@ void CColorCopDlg::HSLtoRGB(double H, double S, double L) {
907907
if (S == 0) {
908908
r = g = b = S * 255.0;
909909
} else {
910-
double h = (H - int(H)) * 6.0;
911-
int caseH = (int) int(h);
910+
double h = (H - static_cast<int>(H)) * 6.0;
911+
int caseH = static_cast<int>(h);
912912

913-
double f = h - int(h);
913+
double f = h - static_cast<int>(h);
914914
double p = L * (1.0 - S);
915915
double q = L * (1.0 - S * f);
916916
double t = L * (1.0 - (S * (1.0 - f)));
917917

918918
switch (caseH) {
919919
case 0:
920-
r = (int) (L * 255.0);
921-
g = (int) (t * 255.0);
922-
b = (int) (p * 255.0);
920+
r = static_cast<int>((L) * 255.0);
921+
g = static_cast<int>((t) * 255.0);
922+
b = static_cast<int>((p) * 255.0);
923923
break;
924924
case 1:
925-
r = (int) (q * 255.0);
926-
g = (int) (L * 255.0);
927-
b = (int) (p * 255.0);
925+
r = static_cast<int>((q) * 255.0);
926+
g = static_cast<int>((L) * 255.0);
927+
b = static_cast<int>((p) * 255.0);
928928
break;
929929
case 2:
930-
r = (int) (p * 255.0);
931-
g = (int) (L * 255.0);
932-
b = (int) (t * 255.0);
930+
r = static_cast<int>((p) * 255.0);
931+
g = static_cast<int>((L) * 255.0);
932+
b = static_cast<int>((t) * 255.0);
933933
break;
934934
case 3:
935-
r = (int) (p * 255.0);
936-
g = (int) (q * 255.0);
937-
b = (int) (L * 255.0);
935+
r = static_cast<int>((p) * 255.0);
936+
g = static_cast<int>((q) * 255.0);
937+
b = static_cast<int>((L) * 255.0);
938938
break;
939939
case 4:
940-
r = (int) (t * 255.0);
941-
g = (int) (p * 255.0);
942-
b = (int) (L * 255.0);
940+
r = static_cast<int>((t) * 255.0);
941+
g = static_cast<int>((p) * 255.0);
942+
b = static_cast<int>((L) * 255.0);
943943
break;
944944
case 5:
945-
r = (int) (L * 255.0);
946-
g = (int) (p * 255.0);
947-
b = (int) (q * 255.0);
945+
r = static_cast<int>((L) * 255.0);
946+
g = static_cast<int>((p) * 255.0);
947+
b = static_cast<int>((q) * 255.0);
948948
break;
949949
}
950950
}
951951
}
952952

953953
void CColorCopDlg::UpdateCMYKFromRGB(int red, int green, int blue) {
954954
double r, g, b;
955-
r = (double)red / 255.0;
956-
g = (double)green / 255.0;
957-
b = (double)blue / 255.0;
955+
r = static_cast<double>(red) / 255.0;
956+
g = static_cast<double>(green) / 255.0;
957+
b = static_cast<double>(blue) / 255.0;
958958
m_Cyan = static_cast<int>(std::pow(1.0 - r, 45));
959959
m_Magenta = static_cast<int>(std::pow(1.0 - g, 45));
960960
m_Yellow = static_cast<int>(std::pow(1.0 - b, 45));
@@ -992,14 +992,14 @@ void CColorCopDlg::RGBtoHSL(double R, double G, double B) {
992992
}
993993

994994
if (MaxNum != 0) {
995-
Sat = ((double) Diff) / ((double) MaxNum);
995+
Sat = (static_cast<double>(Diff)) / (static_cast<double>(MaxNum));
996996
}
997997

998998

999999
// find the Hue
1000-
R_Dist = (double) (MaxNum - R) / (double) (Diff);
1001-
G_Dist = (double) (MaxNum - G) / (double) (Diff);
1002-
B_Dist = (double) (MaxNum - B) / (double) (Diff);
1000+
R_Dist = static_cast<double>((MaxNum) - R) / static_cast<double>((Diff));
1001+
G_Dist = static_cast<double>((MaxNum) - G) / static_cast<double>((Diff));
1002+
B_Dist = static_cast<double>((MaxNum) - B) / static_cast<double>((Diff));
10031003

10041004
if (R == MaxNum) {
10051005
Hue = B_Dist - G_Dist;
@@ -1054,8 +1054,8 @@ void CColorCopDlg::DisplayColor() {
10541054
int palWidth = (colorpalrect.right - colorpalrect.left);
10551055
int palHeight = (colorpalrect.bottom - colorpalrect.top);
10561056

1057-
m_nwide = (int) (palWidth / 6.0);
1058-
m_ntall = (int) (palHeight / 7.0);
1057+
m_nwide = static_cast<int>((palWidth) / 6.0);
1058+
m_ntall = static_cast<int>((palHeight) / 7.0);
10591059

10601060
CRect insiderect = colorpalrect;
10611061
insiderect.right = insiderect.left + m_nwide;
@@ -1593,8 +1593,8 @@ void CColorCopDlg::OnMouseMove(UINT nFlags, CPoint point) {
15931593
int iHeight = (point.y - RelativePoint.y);
15941594

15951595
// we need to add one since they are zero based
1596-
double dWidth = (double)iWidth+1;
1597-
double dHeight = (double)iHeight+1;
1596+
double dWidth = static_cast<double>(iWidth+1);
1597+
double dHeight = static_cast<double>(iHeight+1);
15981598

15991599
double dLength = std::sqrt(dWidth*dWidth + dHeight * dHeight);
16001600
double dAngle = std::atan2(dHeight, dWidth) * (180.0 / kPi);
@@ -2056,7 +2056,7 @@ BOOL CColorCopDlg::GetShellFolderPath(LPCTSTR pShellFolder, LPTSTR pShellPath) {
20562056

20572057
if (rc == ERROR_SUCCESS) {
20582058
rc = RegQueryValueEx(hkey, pShellFolder, NULL, &type,
2059-
(BYTE *) pShellPath, &length);
2059+
reinterpret_cast<BYTE*>(pShellPath), &length);
20602060
RegCloseKey(hkey);
20612061
}
20622062

@@ -2228,7 +2228,7 @@ void CColorCopDlg::OnPopupColorConverttograyscale() {
22282228

22292229
Min = __min(m_Reddec, m_Greendec);
22302230
Min = __min(Min, m_Bluedec);
2231-
L = (int) (Min + Max) / 2;
2231+
L = static_cast<int>((Min) + Max) / 2;
22322232

22332233
m_Reddec = L;
22342234
m_Greendec = L;
@@ -2558,9 +2558,9 @@ bool CColorCopDlg::AveragePixelArea(HDC hdc, int* m_R, int* m_G, int* m_B, CPoin
25582558
bluedec += GetBValue(crefxy);
25592559
}
25602560
}
2561-
reddec = (int) reddec / elements; // average
2562-
greendec = (int) greendec / elements; // average
2563-
bluedec = (int) bluedec / elements; // average
2561+
reddec = static_cast<int>(reddec) / elements; // average
2562+
greendec = static_cast<int>(greendec) / elements; // average
2563+
bluedec = static_cast<int>(bluedec) / elements; // average
25642564

25652565
if (RGB(reddec, greendec, bluedec) != RGB(m_Reddec, m_Greendec, m_Bluedec)) {
25662566
*m_R = reddec;
@@ -3163,7 +3163,7 @@ void CColorCopDlg::CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, HBI
31633163
// Create the .BMP file.
31643164
hf = CreateFile(pszFile,
31653165
GENERIC_READ | GENERIC_WRITE,
3166-
(DWORD) 0,
3166+
static_cast<DWORD>(0),
31673167
NULL,
31683168
CREATE_ALWAYS,
31693169
FILE_ATTRIBUTE_NORMAL,
@@ -3176,14 +3176,14 @@ void CColorCopDlg::CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, HBI
31763176
hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
31773177

31783178
// Compute the size of the entire file.
3179-
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
3179+
hdr.bfSize = static_cast<DWORD>((sizeof(BITMAPFILEHEADER)) +
31803180
pbih->biSize + pbih->biClrUsed
31813181
* sizeof(RGBQUAD) + pbih->biSizeImage);
31823182
hdr.bfReserved1 = 0;
31833183
hdr.bfReserved2 = 0;
31843184

31853185
// Compute the offset to the array of color indices.
3186-
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
3186+
hdr.bfOffBits = static_cast<DWORD>(sizeof(BITMAPFILEHEADER)) +
31873187
pbih->biSize + pbih->biClrUsed
31883188
* sizeof (RGBQUAD);
31893189

@@ -3205,7 +3205,7 @@ void CColorCopDlg::CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, HBI
32053205
// Copy the array of color indices into the .BMP file.
32063206
dwTotal = cb = pbih->biSizeImage;
32073207
hp = lpBits;
3208-
if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp, NULL)) {
3208+
if (!WriteFile(hf, (LPSTR) hp, static_cast<int>(cb), (LPDWORD) &dwTmp, NULL)) {
32093209
AfxMessageBox(_T("WriteFile failed"));
32103210
}
32113211
// Close the .BMP file.

colorspace.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class colorspace {
7171
// RGB2CMYK
7272
void RGB2CMYK(BYTE r, BYTE g, BYTE b, BYTE& c, BYTE& m, BYTE& y, BYTE& k) {
7373
double R, G, B;
74-
R = (double) r;
75-
G = (double) g;
76-
B = (double) b;
74+
R = static_cast<double>(r);
75+
G = static_cast<double>(g);
76+
B = static_cast<double>(b);
7777

7878
R = 1.0 - (R / 255.0);
7979
G = 1.0 - (G / 255.0);
@@ -111,10 +111,10 @@ COLORREF CMYK2RGB(BYTE c, BYTE m, BYTE y, BYTE k) {
111111
double R, G, B;
112112
double C, M, Y, K;
113113

114-
C = (double) c;
115-
M = (double) m;
116-
Y = (double) y;
117-
K = (double) k;
114+
C = static_cast<double>(c);
115+
M = static_cast<double>(m);
116+
Y = static_cast<double>(y);
117+
K = static_cast<double>(k);
118118

119119
C = C / 255.0;
120120
M = M / 255.0;

0 commit comments

Comments
 (0)