From 2ebf7fd7102c451b5a4de177afbea7f130ce6718 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 29 Feb 2024 00:52:46 -0700 Subject: [PATCH] find_special_colors is not platform specific --- CMakeLists.txt | 3 ++ common/calcfrac.cpp | 1 + common/editpal.cpp | 1 + common/find_special_colors.cpp | 79 ++++++++++++++++++++++++++++++++++ common/framain2.cpp | 1 + common/loadfile.cpp | 1 + common/realdos.cpp | 1 + common/stereo.cpp | 1 + headers/find_special_colors.h | 7 +++ headers/prototyp.h | 1 - unix/video.cpp | 75 -------------------------------- win32/os_win32.cpp | 75 -------------------------------- 12 files changed, 95 insertions(+), 151 deletions(-) create mode 100644 common/find_special_colors.cpp create mode 100644 headers/find_special_colors.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f3cba2a1..7695e8842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,6 +133,7 @@ add_library(libid common/find_file.cpp headers/find_file.h common/find_path.cpp headers/find_path.h + common/find_special_colors.cpp headers/find_special_colors.h common/fractint.cpp common/framain2.cpp headers/framain2.h headers/get_ifs_token.h @@ -288,6 +289,7 @@ source_group("Source Files/common/plumbing" FILES source_group("Header Files/common/ui" FILES headers/find_file.h headers/find_path.h + headers/find_special_colors.h headers/fractint.h headers/framain2.h headers/get_ifs_token.h @@ -311,6 +313,7 @@ source_group("Header Files/common/ui" FILES source_group("Source Files/common/ui" FILES common/find_file.cpp common/find_path.cpp + common/find_special_colors.cpp common/fractint.cpp common/framain2.cpp common/get_key_no_help.cpp diff --git a/common/calcfrac.cpp b/common/calcfrac.cpp index 31e81a35e..9d7ce3226 100644 --- a/common/calcfrac.cpp +++ b/common/calcfrac.cpp @@ -22,6 +22,7 @@ #include "cmplx.h" #include "diskvid.h" #include "drivers.h" +#include "find_special_colors.h" #include "fpu087.h" #include "fracsubr.h" #include "fractalp.h" diff --git a/common/editpal.cpp b/common/editpal.cpp index d3839f01e..aec6fb6f5 100644 --- a/common/editpal.cpp +++ b/common/editpal.cpp @@ -10,6 +10,7 @@ #include "calcfrac.h" #include "cmdfiles.h" #include "drivers.h" +#include "find_special_colors.h" #include "get_key_no_help.h" #include "id_data.h" #include "memory.h" diff --git a/common/find_special_colors.cpp b/common/find_special_colors.cpp new file mode 100644 index 000000000..91a8248cb --- /dev/null +++ b/common/find_special_colors.cpp @@ -0,0 +1,79 @@ +#include "find_special_colors.h" + +#include "port.h" + +#include "id_data.h" +#include "rotate.h" + +int g_color_dark = 0; // darkest color in palette +int g_color_bright = 0; // brightest color in palette +int g_color_medium = 0; /* nearest to medbright grey in palette + Zoom-Box values (2K x 2K screens max) */ + +//*************** Function find_special_colors ******************** +// +// Find the darkest and brightest colors in palette, and a medium +// color which is reasonably bright and reasonably grey. +// +void find_special_colors() +{ + int maxb = 0; + int minb = 9999; + int med = 0; + int maxgun, mingun; + + g_color_dark = 0; + g_color_medium = 7; + g_color_bright = 15; + + if (g_colors == 2) + { + g_color_medium = 1; + g_color_bright = 1; + return; + } + + if (!g_got_real_dac) + return; + + for (int i = 0; i < g_colors; i++) + { + const int brt = (int) g_dac_box[i][0] + (int) g_dac_box[i][1] + (int) g_dac_box[i][2]; + if (brt > maxb) + { + maxb = brt; + g_color_bright = i; + } + if (brt < minb) + { + minb = brt; + g_color_dark = i; + } + if (brt < 150 && brt > 80) + { + mingun = (int) g_dac_box[i][0]; + maxgun = mingun; + if ((int) g_dac_box[i][1] > (int) g_dac_box[i][0]) + { + maxgun = (int) g_dac_box[i][1]; + } + else + { + mingun = (int) g_dac_box[i][1]; + } + if ((int) g_dac_box[i][2] > maxgun) + { + maxgun = (int) g_dac_box[i][2]; + } + if ((int) g_dac_box[i][2] < mingun) + { + mingun = (int) g_dac_box[i][2]; + } + if (brt - (maxgun - mingun) / 2 > med) + { + g_color_medium = i; + med = brt - (maxgun - mingun) / 2; + } + } + } +} diff --git a/common/framain2.cpp b/common/framain2.cpp index 397b17742..68549a748 100644 --- a/common/framain2.cpp +++ b/common/framain2.cpp @@ -10,6 +10,7 @@ #include "editpal.h" #include "encoder.h" #include "evolve.h" +#include "find_special_colors.h" #include "fracsubr.h" #include "fractalp.h" #include "fractype.h" diff --git a/common/loadfile.cpp b/common/loadfile.cpp index 981ee47b3..50f6057fb 100644 --- a/common/loadfile.cpp +++ b/common/loadfile.cpp @@ -11,6 +11,7 @@ #include "encoder.h" #include "evolve.h" #include "find_file.h" +#include "find_special_colors.h" #include "fracsubr.h" #include "fractalp.h" #include "fractype.h" diff --git a/common/realdos.cpp b/common/realdos.cpp index c291d54a1..69ba44c17 100644 --- a/common/realdos.cpp +++ b/common/realdos.cpp @@ -6,6 +6,7 @@ #include "drivers.h" #include "editpal.h" #include "find_path.h" +#include "find_special_colors.h" #include "fractalp.h" #include "fractype.h" #include "get_key_no_help.h" diff --git a/common/stereo.cpp b/common/stereo.cpp index e5093335d..8f8e24a33 100644 --- a/common/stereo.cpp +++ b/common/stereo.cpp @@ -11,6 +11,7 @@ #include "decoder.h" #include "drivers.h" #include "encoder.h" +#include "find_special_colors.h" #include "gifview.h" #include "helpdefs.h" #include "id_data.h" diff --git a/headers/find_special_colors.h b/headers/find_special_colors.h new file mode 100644 index 000000000..106442ee9 --- /dev/null +++ b/headers/find_special_colors.h @@ -0,0 +1,7 @@ +#pragma once + +extern int g_color_dark; // darkest color in palette +extern int g_color_bright; // brightest color in palette +extern int g_color_medium; // nearest to medbright grey in palette Zoom-Box values (2K x 2K screens max) + +void find_special_colors(); diff --git a/headers/prototyp.h b/headers/prototyp.h index 98a1c2034..0e3005c16 100644 --- a/headers/prototyp.h +++ b/headers/prototyp.h @@ -12,7 +12,6 @@ extern void spindac(int dir, int inc); extern void put_line(int row, int startcol, int stopcol, BYTE const *pixels); extern void get_line(int row, int startcol, int stopcol, BYTE *pixels); -extern void find_special_colors(); extern long readticker(); extern int get_sound_params(); extern void setnullvideo(); diff --git a/unix/video.cpp b/unix/video.cpp index 64521f3ed..097c8f5a4 100644 --- a/unix/video.cpp +++ b/unix/video.cpp @@ -36,10 +36,6 @@ void (*lineread)(int y, int x, int lastx, BYTE *pixels); // read-a-line int videoflag = 0; // special "your-own-video" flag void (*swapsetup)() = nullptr; // setfortext/graphics setup routine -int g_color_dark = 0; // darkest color in palette -int g_color_bright = 0; // brightest color in palette -int g_color_medium = 0; /* nearest to medbright grey in palette - Zoom-Box values (2K x 2K screens max) */ int g_row_count = 0; // row-counter for decoder and out_line int video_type = 0; /* actual video adapter type: 0 = type not yet determined @@ -538,77 +534,6 @@ SetupShadowVideo() return 0; } -/* -; *************** Function find_special_colors ******************** - -; Find the darkest and brightest colors in palette, and a medium -; color which is reasonably bright and reasonably grey. -*/ -void -find_special_colors() -{ - int maxb = 0; - int minb = 9999; - int med = 0; - int maxgun, mingun; - int brt; - - g_color_dark = 0; - g_color_medium = 7; - g_color_bright = 15; - - if (g_colors == 2) - { - g_color_medium = 1; - g_color_bright = 1; - return; - } - - if (!(g_got_real_dac || g_fake_lut)) - return; - - for (int i = 0; i < g_colors; i++) - { - brt = (int) g_dac_box[i][0] + (int) g_dac_box[i][1] + (int) g_dac_box[i][2]; - if (brt > maxb) - { - maxb = brt; - g_color_bright = i; - } - if (brt < minb) - { - minb = brt; - g_color_dark = i; - } - if (brt < 150 && brt > 80) - { - mingun = (int) g_dac_box[i][0]; - maxgun = mingun; - if ((int) g_dac_box[i][1] > (int) g_dac_box[i][0]) - { - maxgun = (int) g_dac_box[i][1]; - } - else - { - mingun = (int) g_dac_box[i][1]; - } - if ((int) g_dac_box[i][2] > maxgun) - { - maxgun = (int) g_dac_box[i][2]; - } - if ((int) g_dac_box[i][2] < mingun) - { - mingun = (int) g_dac_box[i][2]; - } - if (brt - (maxgun - mingun) / 2 > med) - { - g_color_medium = i; - med = brt - (maxgun - mingun) / 2; - } - } - } -} - /* ; *************** Functions get_a_char, put_a_char ******************** diff --git a/win32/os_win32.cpp b/win32/os_win32.cpp index a1e8ae1d4..b48ba8852 100644 --- a/win32/os_win32.cpp +++ b/win32/os_win32.cpp @@ -118,13 +118,8 @@ enum fractint_event }; // Global variables (yuck!) -int g_color_dark = 0; // darkest color in palette -int g_color_bright = 0; // brightest color in palette -int g_color_medium = 0; /* nearest to medbright grey in palette - Zoom-Box values (2K x 2K screens max) */ int dacnorm = 0; int g_dac_count = 0; -bool fake_lut = false; int g_fm_attack = 0; int g_fm_decay = 0; int g_fm_release = 0; @@ -171,76 +166,6 @@ long stackavail() return WIN32_STACK_SIZE - (long)(((char *) g_tos) - &junk); } -/* -; *************** Function find_special_colors ******************** - -; Find the darkest and brightest colors in palette, and a medium -; color which is reasonably bright and reasonably grey. -*/ -void -find_special_colors() -{ - int maxb = 0; - int minb = 9999; - int med = 0; - int maxgun, mingun; - - g_color_dark = 0; - g_color_medium = 7; - g_color_bright = 15; - - if (g_colors == 2) - { - g_color_medium = 1; - g_color_bright = 1; - return; - } - - if (!(g_got_real_dac || fake_lut)) - return; - - for (int i = 0; i < g_colors; i++) - { - const int brt = (int) g_dac_box[i][0] + (int) g_dac_box[i][1] + (int) g_dac_box[i][2]; - if (brt > maxb) - { - maxb = brt; - g_color_bright = i; - } - if (brt < minb) - { - minb = brt; - g_color_dark = i; - } - if (brt < 150 && brt > 80) - { - mingun = (int) g_dac_box[i][0]; - maxgun = mingun; - if ((int) g_dac_box[i][1] > (int) g_dac_box[i][0]) - { - maxgun = (int) g_dac_box[i][1]; - } - else - { - mingun = (int) g_dac_box[i][1]; - } - if ((int) g_dac_box[i][2] > maxgun) - { - maxgun = (int) g_dac_box[i][2]; - } - if ((int) g_dac_box[i][2] < mingun) - { - mingun = (int) g_dac_box[i][2]; - } - if (brt - (maxgun - mingun) / 2 > med) - { - g_color_medium = i; - med = brt - (maxgun - mingun) / 2; - } - } - } -} - int get_sound_params() { // TODO