From e74f307f52e219f709bbf281303c6eaf21480652 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 3 Aug 2024 19:08:12 +0200 Subject: [PATCH 01/10] Remove unused function mapimg_get_format_list --- common/mapimg.cpp | 37 ------------------------------------- common/mapimg.h | 2 -- 2 files changed, 39 deletions(-) diff --git a/common/mapimg.cpp b/common/mapimg.cpp index d3c99a0606..c7c9ab7187 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -30,7 +30,6 @@ received a copy of the GNU General Public License along with Freeciv21. #include "rgbcolor.h" #include "terrain.h" #include "tile.h" -#include "version.h" #include "mapimg.h" @@ -55,8 +54,6 @@ received a copy of the GNU General Public License along with Freeciv21. #define magickwand_size_t unsigned long #endif -Q_GLOBAL_STATIC(QVector, format_list) - // == image colors == enum img_special { IMGCOLOR_ERROR, @@ -1100,40 +1097,6 @@ struct mapdef *mapimg_isvalid(int id) return pmapdef; } -/** - Return a list of all available tookits and formats for the client. - */ -const QVector *mapimg_get_format_list() -{ - if (format_list->isEmpty()) { - enum imagetool tool; - - for (tool = imagetool_begin(); tool != imagetool_end(); - tool = imagetool_next(tool)) { - enum imageformat format; - const struct toolkit *toolkit = img_toolkit_get(tool); - - if (!toolkit) { - continue; - } - - for (format = imageformat_begin(); format != imageformat_end(); - format = imageformat_next(format)) { - if (toolkit->formats & format) { - char str_format[64]; - - fc_snprintf(str_format, sizeof(str_format), "%s|%s", - imagetool_name(tool), imageformat_name(format)); - - format_list->append(str_format); - } - } - } - } - - return format_list; -} - /** Delete a map image definition. */ diff --git a/common/mapimg.h b/common/mapimg.h index 3d430c77f6..10d95ef43e 100644 --- a/common/mapimg.h +++ b/common/mapimg.h @@ -109,5 +109,3 @@ bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, bool mapimg_colortest(const char *savename, const char *path); struct mapdef *mapimg_isvalid(int id); - -const QVector *mapimg_get_format_list(); From e531fec94c09efeff296548b32ac315b34f37ba1 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 3 Aug 2024 19:14:04 +0200 Subject: [PATCH 02/10] Remove the server-side ImageMagick image format --- INSTALL | 1 - cmake/FreecivInstall.cmake | 1 - common/mapimg.cpp | 284 ----------------------------------- dist/licenses/MAGICKWAND.txt | 7 - docs/Getting/compile.rst | 1 - 5 files changed, 294 deletions(-) delete mode 100644 dist/licenses/MAGICKWAND.txt diff --git a/INSTALL b/INSTALL index 890dee4b6a..ea7b9d3adf 100644 --- a/INSTALL +++ b/INSTALL @@ -153,7 +153,6 @@ following commands. qt5-default \ libkf5archive-dev \ liblua5.3-dev \ - libmagickwand-dev \ libsdl2-mixer-dev \ libunwind-dev \ libdw-dev diff --git a/cmake/FreecivInstall.cmake b/cmake/FreecivInstall.cmake index 05486cbdb8..e2de189376 100644 --- a/cmake/FreecivInstall.cmake +++ b/cmake/FreecivInstall.cmake @@ -22,7 +22,6 @@ install( ${CMAKE_SOURCE_DIR}/dist/licenses/FTL.txt ${CMAKE_SOURCE_DIR}/dist/licenses/GPL2.txt ${CMAKE_SOURCE_DIR}/dist/licenses/GPL3.txt - ${CMAKE_SOURCE_DIR}/dist/licenses/IMAGEMAGICK.txt ${CMAKE_SOURCE_DIR}/dist/licenses/LGPL-2.0-ONLY.txt ${CMAKE_SOURCE_DIR}/dist/licenses/LGPL-2.0-OR-LATER.txt ${CMAKE_SOURCE_DIR}/dist/licenses/LGPL-3.0-ONLY.txt diff --git a/common/mapimg.cpp b/common/mapimg.cpp index c7c9ab7187..8c8357b52d 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -11,10 +11,6 @@ received a copy of the GNU General Public License along with Freeciv21. #include -#ifdef HAVE_MAPIMG_MAGICKWAND -#include -#endif // HAVE_MAPIMG_MAGICKWAND - // utility #include "bitvector.h" #include "fcintl.h" @@ -33,27 +29,6 @@ received a copy of the GNU General Public License along with Freeciv21. #include "mapimg.h" -/* Some magick for ImageMagick - the interface has changed: - ImageMagick-6.6.2-0: PixelGetNextIteratorRow(..., unsigned long *) - ImageMagick-6.6.2-1: PixelGetNextIteratorRow(..., size_t *) - Theoretically, "unsigned long" and "size_t" are pretty much the same but - in practice the compiler will complain bitterly. - (from Gem-0.93 ImageMAGICK plugin) */ -#ifndef MagickLibInterface -#define MagickLibInterface 0 -#endif -#ifndef MagickLibVersion -#define MagickLibVersion 0 -#endif - -/* This won't catch ImageMagick>=6.6.2-0. - Another workaround: compile with "-fpermissive" */ -#if (MagickLibInterface > 3) || (MagickLibVersion >= 0x662) -#define magickwand_size_t size_t -#else -#define magickwand_size_t unsigned long -#endif - // == image colors == enum img_special { IMGCOLOR_ERROR, @@ -212,8 +187,6 @@ BV_DEFINE(bv_mapdef_arg, MAPDEF_COUNT); #define SPECENUM_NAME imagetool #define SPECENUM_VALUE0 IMGTOOL_PPM #define SPECENUM_VALUE0NAME "ppm" -#define SPECENUM_VALUE1 IMGTOOL_MAGICKWAND -#define SPECENUM_VALUE1NAME "magick" #include "specenum_gen.h" // player definitions @@ -303,13 +276,6 @@ static void mapdef_destroy(struct mapdef *pmapdef); // == images == struct mapdef; -// Some lengths used for the images created by the magickwand toolkit. -#define IMG_BORDER_HEIGHT 5 -#define IMG_BORDER_WIDTH IMG_BORDER_HEIGHT -#define IMG_SPACER_HEIGHT 5 -#define IMG_LINE_HEIGHT 5 -#define IMG_TEXT_HEIGHT 12 - struct img { struct mapdef *def; // map definition int turn; // save turn @@ -351,10 +317,6 @@ static void img_plot_tile(struct img *pimg, const struct tile *ptile, static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path); static bool img_save_ppm(const struct img *pimg, const char *mapimgfile); -#ifdef HAVE_MAPIMG_MAGICKWAND -static bool img_save_magickwand(const struct img *pimg, - const char *mapimgfile); -#endif // HAVE_MAPIMG_MAGICKWAND static bool img_filename(const char *mapimgfile, enum imageformat format, char *filename, size_t filename_len); static void img_createmap(struct img *pimg); @@ -377,23 +339,12 @@ struct toolkit { static struct toolkit img_toolkits[] = { GEN_TOOLKIT(IMGTOOL_PPM, IMGFORMAT_PPM, IMGFORMAT_PPM, img_save_ppm, N_("Standard ppm files")) -#ifdef HAVE_MAPIMG_MAGICKWAND - GEN_TOOLKIT(IMGTOOL_MAGICKWAND, IMGFORMAT_GIF, - IMGFORMAT_GIF + IMGFORMAT_PNG + IMGFORMAT_PPM - + IMGFORMAT_JPG, - img_save_magickwand, N_("ImageMagick")) -#endif // HAVE_MAPIMG_MAGICKWAND }; static const int img_toolkits_count = ARRAY_SIZE(img_toolkits); -#ifdef HAVE_MAPIMG_MAGICKWAND -#define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_GIF -#define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_MAGICKWAND -#else #define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_PPM #define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_PPM -#endif // HAVE_MAPIMG_MAGICKWAND static const struct toolkit *img_toolkit_get(enum imagetool tool); @@ -1970,241 +1921,6 @@ static bool img_save(const struct img *pimg, const char *mapimgfile, return toolkit->img_save(pimg, tmpname); } -/** - Save an image using magickwand as toolkit. This allows different file - formats. - - Image structure: - - [ 0] - border - [+IMG_BORDER_HEIGHT] - title - [+ IMG_TEXT_HEIGHT] - space (only if count(displayed players) > 0) - [+IMG_SPACER_HEIGHT] - player line (only if count(displayed players) > 0) - [+ IMG_LINE_HEIGHT] - space - [+IMG_SPACER_HEIGHT] - map - [+ map_height] - border - [+IMG_BORDER_HEIGHT] - - */ -#ifdef HAVE_MAPIMG_MAGICKWAND -#define SET_COLOR(str, pcolor) \ - fc_snprintf(str, sizeof(str), "rgb(%d,%d,%d)", pcolor->r, pcolor->g, \ - pcolor->b); -static bool img_save_magickwand(const struct img *pimg, - const char *mapimgfile) -{ - const struct rgbcolor *pcolor = nullptr; - struct player *pplr_now = nullptr, *pplr_only = nullptr; - bool ret = true; - char imagefile[MAX_LEN_PATH]; - char str_color[32], comment[2048] = "", title[258]; - magickwand_size_t img_width, img_height, map_width, map_height; - int x, y, xxx, yyy, row, i, mindex, plrwidth, plroffset, textoffset; - bool withplr = BV_ISSET_ANY(pimg->def->player.checked_plrbv); - - if (!img_filename(mapimgfile, pimg->def->format, imagefile, - sizeof(imagefile))) { - MAPIMG_LOG(_("error generating the file name")); - return false; - } - - MagickWand *mw; - PixelIterator *imw; - PixelWand **pmw, *pw; - DrawingWand *dw; - - MagickWandGenesis(); - - mw = NewMagickWand(); - dw = NewDrawingWand(); - pw = NewPixelWand(); - - map_width = pimg->imgsize.x * pimg->def->zoom; - map_height = pimg->imgsize.y * pimg->def->zoom; - - img_width = map_width + 2 * IMG_BORDER_WIDTH; - img_height = map_height + 2 * IMG_BORDER_HEIGHT + IMG_TEXT_HEIGHT - + IMG_SPACER_HEIGHT + (withplr ? 2 * IMG_SPACER_HEIGHT : 0); - - fc_snprintf(title, sizeof(title), "%s (%s)", pimg->title, mapimgfile); - - SET_COLOR(str_color, imgcolor_special(IMGCOLOR_BACKGROUND)); - PixelSetColor(pw, str_color); - MagickNewImage(mw, img_width, img_height, pw); - - textoffset = 0; - if (withplr) { - if (bvplayers_count(pimg->def) == 1) { - // only one player - for (i = 0; i < player_slot_count(); i++) { - if (BV_ISSET(pimg->def->player.checked_plrbv, i)) { - pplr_only = player_by_number(i); - break; - } - } - } - - if (pplr_only) { - magickwand_size_t plr_color_square = IMG_TEXT_HEIGHT; - - textoffset += IMG_TEXT_HEIGHT + IMG_BORDER_HEIGHT; - - pcolor = imgcolor_player(player_index(pplr_only)); - SET_COLOR(str_color, pcolor); - - // Show the color of the selected player. - imw = NewPixelRegionIterator(mw, IMG_BORDER_WIDTH, IMG_BORDER_HEIGHT, - IMG_TEXT_HEIGHT, IMG_TEXT_HEIGHT); - // y coordinate - for (y = 0; y < IMG_TEXT_HEIGHT; y++) { - pmw = PixelGetNextIteratorRow(imw, &plr_color_square); - // x coordinate - for (x = 0; x < IMG_TEXT_HEIGHT; x++) { - PixelSetColor(pmw[x], str_color); - } - PixelSyncIterator(imw); - } - DestroyPixelIterator(imw); - } - - // Show a line displaying the colors of alive players - plrwidth = map_width / MIN(map_width, player_count()); - plroffset = (map_width - MIN(map_width, plrwidth * player_count())) / 2; - - imw = NewPixelRegionIterator(mw, IMG_BORDER_WIDTH, - IMG_BORDER_HEIGHT + IMG_TEXT_HEIGHT - + IMG_SPACER_HEIGHT, - map_width, IMG_LINE_HEIGHT); - // y coordinate - for (y = 0; y < IMG_LINE_HEIGHT; y++) { - pmw = PixelGetNextIteratorRow(imw, &map_width); - - // x coordinate - for (x = plroffset; x < map_width; x++) { - i = (x - plroffset) / plrwidth; - pplr_now = player_by_number(i); - - if (i > player_count() || pplr_now == nullptr - || !pplr_now->is_alive) { - continue; - } - - if (BV_ISSET(pimg->def->player.checked_plrbv, i)) { - // The selected player is alive - display it. - pcolor = imgcolor_player(i); - SET_COLOR(str_color, pcolor); - PixelSetColor(pmw[x], str_color); - } else if (pplr_only != nullptr) { - /* Display the state between pplr_only and pplr_now: - * - if allied: - * - show each second pixel - * - if pplr_now does shares map with pplr_onlyus: - * - show every other line of pixels - * This results in the following patterns (# = color): - * ###### # # # ###### - * # # # # # # - * ###### # # # ###### - * # # # # # # - * shared allied shared vision - * vision + allied */ - if ((pplayers_allied(pplr_now, pplr_only) && (x + y) % 2 == 0) - || (y % 2 == 0 && gives_shared_vision(pplr_now, pplr_only))) { - pcolor = imgcolor_player(i); - SET_COLOR(str_color, pcolor); - PixelSetColor(pmw[x], str_color); - } - } - } - PixelSyncIterator(imw); - } - DestroyPixelIterator(imw); - } - - // Display the image name. - SET_COLOR(str_color, imgcolor_special(IMGCOLOR_TEXT)); - PixelSetColor(pw, str_color); - DrawSetFillColor(dw, pw); - DrawSetFont(dw, "Times-New-Roman"); - DrawSetFontSize(dw, IMG_TEXT_HEIGHT); - DrawAnnotation(dw, IMG_BORDER_WIDTH + textoffset, - IMG_TEXT_HEIGHT + IMG_BORDER_HEIGHT, - (unsigned char *) title); - MagickDrawImage(mw, dw); - - // Display the map. - imw = NewPixelRegionIterator( - mw, IMG_BORDER_WIDTH, - IMG_BORDER_HEIGHT + IMG_TEXT_HEIGHT + IMG_SPACER_HEIGHT - + (withplr ? (IMG_LINE_HEIGHT + IMG_SPACER_HEIGHT) : 0), - map_width, map_height); - // y coordinate - for (y = 0; y < pimg->imgsize.y; y++) { - // zoom for y - for (yyy = 0; yyy < pimg->def->zoom; yyy++) { - pmw = PixelGetNextIteratorRow(imw, &map_width); - - // x coordinate - for (x = 0; x < pimg->imgsize.x; x++) { - mindex = img_index(x, y, pimg); - pcolor = pimg->map[mindex]; - - if (pcolor != nullptr) { - SET_COLOR(str_color, pcolor); - - // zoom for x - for (xxx = 0; xxx < pimg->def->zoom; xxx++) { - row = x * pimg->def->zoom + xxx; - PixelSetColor(pmw[row], str_color); - } - } - } - PixelSyncIterator(imw); - } - } - DestroyPixelIterator(imw); - - cat_snprintf(comment, sizeof(comment), "map definition: %s\n", - pimg->def->maparg); - if (BV_ISSET_ANY(pimg->def->player.checked_plrbv)) { - players_iterate(pplayer) - { - if (!BV_ISSET(pimg->def->player.checked_plrbv, - player_index(pplayer))) { - continue; - } - - pcolor = imgcolor_player(player_index(pplayer)); - cat_snprintf(comment, sizeof(comment), "%s\n", img_playerstr(pplayer)); - } - players_iterate_end; - } - MagickCommentImage(mw, comment); - - if (!MagickWriteImage(mw, imagefile)) { - MAPIMG_LOG(_("error saving map image '%s'"), imagefile); - ret = false; - } else { - qDebug("Map image saved as '%s'.", imagefile); - } - - DestroyDrawingWand(dw); - DestroyPixelWand(pw); - DestroyMagickWand(mw); - - MagickWandTerminus(); - - return ret; -} -#undef SET_COLOR -#endif // HAVE_MAPIMG_MAGICKWAND - /** Save an image as ppm file (toolkit: ppm). */ diff --git a/dist/licenses/MAGICKWAND.txt b/dist/licenses/MAGICKWAND.txt deleted file mode 100644 index 80f265a66c..0000000000 --- a/dist/licenses/MAGICKWAND.txt +++ /dev/null @@ -1,7 +0,0 @@ -Magickwand Library License -========================== - -Magickwand is made by Image Magick, a non-profit company. They use thier own license. Refer to similarly -named file for the full text. Alternately you can go to the ImageMagick license page at: - - http://www.imagemagick.org/script/license.php diff --git a/docs/Getting/compile.rst b/docs/Getting/compile.rst index dc716fc0d8..ea6759a6fe 100644 --- a/docs/Getting/compile.rst +++ b/docs/Getting/compile.rst @@ -171,7 +171,6 @@ following commands: liblua5.3-dev \ libsqlite3-dev \ libsdl2-mixer-dev \ - libmagickwand-dev \ libunwind-dev \ libdw-dev \ python3-sphinx \ From 04da79cf086dd2992641c50b1c85adc47d61723e Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 4 Aug 2024 00:31:31 +0200 Subject: [PATCH 03/10] Add a Qt backend for mapimg It will eventually replace the PPM backend, but for now produces PNG. --- common/CMakeLists.txt | 3 +- common/mapimg.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0d470a9e0f..9a269b4362 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -99,6 +99,7 @@ add_subdirectory(aicore) add_subdirectory(networking) add_subdirectory(scriptcore) -target_link_libraries(common PUBLIC Qt5::Core Qt5::Network) +# Qt5::Gui for map images -- could be made optional +target_link_libraries(common PUBLIC Qt5::Core Qt5::Gui Qt5::Network) target_link_libraries(common PRIVATE aicore networking) target_link_libraries(common PUBLIC common_gen scriptcore) diff --git a/common/mapimg.cpp b/common/mapimg.cpp index 8c8357b52d..87f767bed9 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -29,6 +29,10 @@ received a copy of the GNU General Public License along with Freeciv21. #include "mapimg.h" +// Qt +#include +#include + // == image colors == enum img_special { IMGCOLOR_ERROR, @@ -187,6 +191,8 @@ BV_DEFINE(bv_mapdef_arg, MAPDEF_COUNT); #define SPECENUM_NAME imagetool #define SPECENUM_VALUE0 IMGTOOL_PPM #define SPECENUM_VALUE0NAME "ppm" +#define SPECENUM_VALUE1 IMGTOOL_QT +#define SPECENUM_VALUE1NAME "qt" #include "specenum_gen.h" // player definitions @@ -317,6 +323,7 @@ static void img_plot_tile(struct img *pimg, const struct tile *ptile, static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path); static bool img_save_ppm(const struct img *pimg, const char *mapimgfile); +static bool img_save_qt(const struct img *pimg, const char *mapimgfile); static bool img_filename(const char *mapimgfile, enum imageformat format, char *filename, size_t filename_len); static void img_createmap(struct img *pimg); @@ -339,7 +346,8 @@ struct toolkit { static struct toolkit img_toolkits[] = { GEN_TOOLKIT(IMGTOOL_PPM, IMGFORMAT_PPM, IMGFORMAT_PPM, img_save_ppm, N_("Standard ppm files")) -}; + GEN_TOOLKIT(IMGTOOL_QT, IMGFORMAT_PNG, IMGFORMAT_PNG, img_save_qt, + N_("Qt"))}; static const int img_toolkits_count = ARRAY_SIZE(img_toolkits); @@ -1999,6 +2007,79 @@ static bool img_save_ppm(const struct img *pimg, const char *mapimgfile) return true; } +/** + * Save an image with Qt. + */ +static bool img_save_qt(const struct img *pimg, const char *mapimgfile) +{ + char pngname[MAX_LEN_PATH]; + + if (pimg->def->format != IMGFORMAT_PNG) { + MAPIMG_LOG(_("Qt can only create images in the png format")); + return false; + } + + if (!img_filename(mapimgfile, IMGFORMAT_PNG, pngname, sizeof(pngname))) { + MAPIMG_LOG(_("error generating the file name")); + return false; + } + + QImage image(pimg->imgsize.x * pimg->def->zoom, + pimg->imgsize.y * pimg->def->zoom, QImage::Format_ARGB32); + if (image.isNull()) { + MAPIMG_LOG(_("could not allocate memory for image")); + return false; + } + + if (pimg->def->colortest) { + image.setText(QStringLiteral("Description"), + QStringLiteral("color test")); + } else if (BV_ISSET_ANY(pimg->def->player.checked_plrbv)) { + players_iterate(pplayer) + { + if (!BV_ISSET(pimg->def->player.checked_plrbv, + player_index(pplayer))) { + continue; + } + + const auto pcolor = imgcolor_player(player_index(pplayer)); + + image.setText( + QStringLiteral("Player %1 color").arg(player_number(pplayer)), + QStringLiteral("(%1, %2, %3)") + .arg(pcolor->r) + .arg(pcolor->g) + .arg(pcolor->b)); + image.setText( + QStringLiteral("Player %1 name").arg(player_number(pplayer)), + player_name(pplayer)); + } + players_iterate_end; + } + + image.setDevicePixelRatio(pimg->def->zoom); + image.fill(Qt::transparent); + + QPainter p; + p.begin(&image); + + // Iterate over tiles + for (int y = 0; y < pimg->imgsize.y; y++) { + for (int x = 0; x < pimg->imgsize.x; x++) { + if (const auto pcolor = pimg->map[img_index(x, y, pimg)]; pcolor) { + p.fillRect(x, y, 1, 1, QColor(pcolor->r, pcolor->g, pcolor->b)); + } + } + } + + p.end(); + + image.save(pngname); + qDebug("Map image saved as '%s'.", pngname); + + return true; +} + /** Generate the final filename. */ From a12477a0a577dc0c3f02c51cb5223c89d6bdacee Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 4 Aug 2024 00:42:29 +0200 Subject: [PATCH 04/10] Remove the built-in PPM writer PNG is just a better default. --- common/mapimg.cpp | 112 ++++--------------------------- docs/Manuals/Server/commands.rst | 15 ++--- 2 files changed, 19 insertions(+), 108 deletions(-) diff --git a/common/mapimg.cpp b/common/mapimg.cpp index 87f767bed9..0270901a67 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -189,10 +189,8 @@ BV_DEFINE(bv_mapdef_arg, MAPDEF_COUNT); // image format #define SPECENUM_NAME imagetool -#define SPECENUM_VALUE0 IMGTOOL_PPM -#define SPECENUM_VALUE0NAME "ppm" -#define SPECENUM_VALUE1 IMGTOOL_QT -#define SPECENUM_VALUE1NAME "qt" +#define SPECENUM_VALUE0 IMGTOOL_QT +#define SPECENUM_VALUE0NAME "qt" #include "specenum_gen.h" // player definitions @@ -322,7 +320,6 @@ static void img_plot_tile(struct img *pimg, const struct tile *ptile, const bv_pixel pixel); static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path); -static bool img_save_ppm(const struct img *pimg, const char *mapimgfile); static bool img_save_qt(const struct img *pimg, const char *mapimgfile); static bool img_filename(const char *mapimgfile, enum imageformat format, char *filename, size_t filename_len); @@ -343,16 +340,13 @@ struct toolkit { #define GEN_TOOLKIT(_tool, _format_default, _formats, _save_func, _help) \ {_tool, _format_default, _formats, _save_func, _help}, -static struct toolkit img_toolkits[] = { - GEN_TOOLKIT(IMGTOOL_PPM, IMGFORMAT_PPM, IMGFORMAT_PPM, img_save_ppm, - N_("Standard ppm files")) - GEN_TOOLKIT(IMGTOOL_QT, IMGFORMAT_PNG, IMGFORMAT_PNG, img_save_qt, - N_("Qt"))}; +static struct toolkit img_toolkits[] = {GEN_TOOLKIT( + IMGTOOL_QT, IMGFORMAT_PNG, IMGFORMAT_PNG, img_save_qt, N_("Qt"))}; static const int img_toolkits_count = ARRAY_SIZE(img_toolkits); -#define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_PPM -#define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_PPM +#define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_PNG +#define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_QT static const struct toolkit *img_toolkit_get(enum imagetool tool); @@ -539,7 +533,7 @@ char *mapimg_help(const char *cmdname) continue; } - str_format += QStringLiteral(" - '%1': ").arg(tool); + str_format += QStringLiteral(" - "); const char *separator = ""; for (format = imageformat_begin(); format != imageformat_end(); @@ -615,7 +609,7 @@ char *mapimg_help(const char *cmdname) "\n" "option (default) description\n" "\n" - "format=<[tool|]format> %1 file format\n" + "format= %1 file format\n" "show= %2 which players to show\n" " plrname= player name\n" " plrid= numeric player id\n" @@ -628,11 +622,9 @@ char *mapimg_help(const char *cmdname) "zoom= %4 magnification factor (1-5)\n" "map= %5 which map layers to draw\n" "\n" - "<[tool|]format> = use image format , optionally " - "specifying " - "toolkit . The following toolkits and formats are " - "compiled " - "in:\n" + " = use image format . The following formats " + "are " + "compiled in:\n" "%6\n" "\n" " determines which players are represented and how many " @@ -649,11 +641,11 @@ char *mapimg_help(const char *cmdname) " - 'u' show units of specified players\n" "\n" "Examples of :\n" - " 'zoom=1:map=tcub:show=all:format=ppm|ppm'\n" + " 'zoom=1:map=tcub:show=all:format=png'\n" " 'zoom=2:map=tcub:show=each:format=png'\n" " 'zoom=1:map=tcub:show=plrname:plrname=Otto:format=gif'\n" " 'zoom=3:map=cu:show=plrbv:plrbv=010011:format=jpg'\n" - " 'zoom=1:map=t:show=none:format=magick|jpg'")) + " 'zoom=1:map=t:show=none:format=jpg'")) .arg(defaults[MAPDEF_FORMAT], -10) .arg(defaults[MAPDEF_SHOW], -10) .arg(defaults[MAPDEF_TURNS], -10) @@ -1929,84 +1921,6 @@ static bool img_save(const struct img *pimg, const char *mapimgfile, return toolkit->img_save(pimg, tmpname); } -/** - Save an image as ppm file (toolkit: ppm). - */ -static bool img_save_ppm(const struct img *pimg, const char *mapimgfile) -{ - char ppmname[MAX_LEN_PATH]; - FILE *fp; - int x, y, xxx, yyy, mindex; - const struct rgbcolor *pcolor; - - if (pimg->def->format != IMGFORMAT_PPM) { - MAPIMG_LOG(_("the ppm toolkit can only create images in the ppm " - "format")); - return false; - } - - if (!img_filename(mapimgfile, IMGFORMAT_PPM, ppmname, sizeof(ppmname))) { - MAPIMG_LOG(_("error generating the file name")); - return false; - } - - fp = fopen(ppmname, "w"); - if (!fp) { - MAPIMG_LOG(_("could not open file: %s"), ppmname); - return false; - } - - fprintf(fp, "P3\n"); - fprintf(fp, "# version:2\n"); - fprintf(fp, "# map definition: %s\n", pimg->def->maparg); - - if (pimg->def->colortest) { - fprintf(fp, "# color test\n"); - } else if (BV_ISSET_ANY(pimg->def->player.checked_plrbv)) { - players_iterate(pplayer) - { - if (!BV_ISSET(pimg->def->player.checked_plrbv, - player_index(pplayer))) { - continue; - } - - fprintf(fp, "# %s\n", img_playerstr(pplayer)); - } - players_iterate_end; - } else { - fprintf(fp, "# no players\n"); - } - - fprintf(fp, "%d %d\n", pimg->imgsize.x * pimg->def->zoom, - pimg->imgsize.y * pimg->def->zoom); - fprintf(fp, "255\n"); - - // y coordinate - for (y = 0; y < pimg->imgsize.y; y++) { - // zoom for y - for (yyy = 0; yyy < pimg->def->zoom; yyy++) { - // x coordinate - for (x = 0; x < pimg->imgsize.x; x++) { - mindex = img_index(x, y, pimg); - pcolor = pimg->map[mindex]; - - // zoom for x - for (xxx = 0; xxx < pimg->def->zoom; xxx++) { - if (pcolor == nullptr) { - pcolor = imgcolor_special(IMGCOLOR_BACKGROUND); - } - fprintf(fp, "%d %d %d\n", pcolor->r, pcolor->g, pcolor->b); - } - } - } - } - - qDebug("Map image saved as '%s'.", ppmname); - fclose(fp); - - return true; -} - /** * Save an image with Qt. */ diff --git a/docs/Manuals/Server/commands.rst b/docs/Manuals/Server/commands.rst index 832b3ff120..13fc548db6 100644 --- a/docs/Manuals/Server/commands.rst +++ b/docs/Manuals/Server/commands.rst @@ -492,7 +492,7 @@ server's own command-line. This server command-line is separate from the OS term :widths: auto :align: left - "format=<[tool|]format>", "(ppm|ppm)", "file format" + "format=", "(png)", "file format" "show=", "(all)", "which players to show" "plrname=", "", "player name" "plrid=", "", "numeric player id" @@ -505,10 +505,7 @@ server's own command-line. This server command-line is separate from the OS term

 

- ``<[tool|]format> =`` use image format ````, optionally specifying toolkit ````. The following - toolkits and formats are compiled in: - - * ``0``: ``ppm`` + `` =`` use image format ````. The ``png`` format is always supported. ```` determines which players are represented and how many images are saved by this definition: @@ -532,11 +529,11 @@ server's own command-line. This server command-line is separate from the OS term Examples of ````: - * ``zoom=1:map=tcub:show=all:format=ppm|ppm`` + * ``zoom=1:map=tcub:show=all:format=png`` * ``zoom=2:map=tcub:show=each:format=png`` - * ``zoom=1:map=tcub:show=plrname:plrname=Otto:format=gif`` - * ``zoom=3:map=cu:show=plrbv:plrbv=010011:format=jpg`` - * ``zoom=1:map=t:show=none:format=magick|jpg`` + * ``zoom=1:map=tcub:show=plrname:plrname=Otto:format=png`` + * ``zoom=3:map=cu:show=plrbv:plrbv=010011:format=png`` + * ``zoom=1:map=t:show=none:format=png`` ``/rfcstyle`` Switch server output between 'RFC-style' and normal style. From 7ebe4e5e3ec8dc02a2f75052fe9f30f6e96f09a6 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 4 Aug 2024 00:53:34 +0200 Subject: [PATCH 05/10] Remove the notion of separate image toolkits from mapimg We will always use Qt since it supports everything we need. --- common/mapimg.cpp | 145 ++++++++-------------------------------------- 1 file changed, 23 insertions(+), 122 deletions(-) diff --git a/common/mapimg.cpp b/common/mapimg.cpp index 0270901a67..f691881d42 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -187,12 +187,6 @@ BV_DEFINE(bv_mapdef_arg, MAPDEF_COUNT); #define SPECENUM_VALUE3NAME "jpg" #include "specenum_gen.h" -// image format -#define SPECENUM_NAME imagetool -#define SPECENUM_VALUE0 IMGTOOL_QT -#define SPECENUM_VALUE0NAME "qt" -#include "specenum_gen.h" - // player definitions #define SPECENUM_NAME show_player #define SPECENUM_VALUE0 SHOW_NONE @@ -246,7 +240,6 @@ struct mapdef { char error[MAX_LEN_MAPDEF]; enum mapimg_status status; enum imageformat format; - enum imagetool tool; int zoom; int turns; bool layers[MAPIMG_LAYER_COUNT]; @@ -330,35 +323,21 @@ typedef bool (*img_save_func)(const struct img *pimg, const char *mapimgfile); struct toolkit { - enum imagetool tool; enum imageformat format_default; int formats; - const img_save_func img_save; - const char *help; }; -#define GEN_TOOLKIT(_tool, _format_default, _formats, _save_func, _help) \ - {_tool, _format_default, _formats, _save_func, _help}, +#define GEN_TOOLKIT(_format_default, _formats) {_format_default, _formats}, -static struct toolkit img_toolkits[] = {GEN_TOOLKIT( - IMGTOOL_QT, IMGFORMAT_PNG, IMGFORMAT_PNG, img_save_qt, N_("Qt"))}; +static struct toolkit img_toolkits[] = { + GEN_TOOLKIT(IMGFORMAT_PNG, IMGFORMAT_PNG)}; static const int img_toolkits_count = ARRAY_SIZE(img_toolkits); #define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_PNG #define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_QT -static const struct toolkit *img_toolkit_get(enum imagetool tool); - -#define img_toolkit_iterate(_toolkit) \ - { \ - int _i; \ - for (_i = 0; _i < img_toolkits_count; _i++) { \ - const struct toolkit *_toolkit = &img_toolkits[_i]; - -#define img_toolkit_iterate_end \ - } \ - } +static const struct toolkit *img_toolkit_get(); // == logging == #define MAX_LEN_ERRORBUF 1024 @@ -511,7 +490,6 @@ static const char *showname_help(enum show_player showplr) char *mapimg_help(const char *cmdname) { Q_UNUSED(cmdname) - enum imagetool tool; enum show_player showplr; enum mapimg_layer layer; QString defaults[MAPDEF_COUNT]; @@ -523,15 +501,10 @@ char *mapimg_help(const char *cmdname) return fc_strdup(qUtf8Printable(help)); } pmapdef = mapdef_new(false); - // Possible 'format' settings (toolkit + format). - for (tool = imagetool_begin(); tool != imagetool_end(); - tool = imagetool_next(tool)) { - enum imageformat format; - const struct toolkit *toolkit = img_toolkit_get(tool); - if (!toolkit) { - continue; - } + { + enum imageformat format; + const struct toolkit *toolkit = img_toolkit_get(); str_format += QStringLiteral(" - "); @@ -544,10 +517,6 @@ char *mapimg_help(const char *cmdname) separator = ", "; } } - - if (tool != imagetool_max()) { - str_format += QStringLiteral("\n"); - } } // Possible 'show' settings. @@ -569,8 +538,8 @@ char *mapimg_help(const char *cmdname) } // Default values. - defaults[MAPDEF_FORMAT] = QStringLiteral("(%1|%2)").arg( - imagetool_name(pmapdef->tool), imageformat_name(pmapdef->format)); + defaults[MAPDEF_FORMAT] = + QStringLiteral("(%2)").arg(imageformat_name(pmapdef->format)); defaults[MAPDEF_SHOW] = QStringLiteral("(%1)").arg(show_player_name(pmapdef->player.show)); defaults[MAPDEF_TURNS] = @@ -805,64 +774,29 @@ static bool mapimg_define_arg(struct mapdef *pmapdef, enum mapdef_arg arg, { QStringList formatargs; enum imageformat format; - enum imagetool tool; - bool error = true; // get format options - formatargs = QString(val).split(QStringLiteral("|")); - if (formatargs.count() == 2) { - tool = imagetool_by_name(qUtf8Printable(formatargs.at(0)), strcmp); format = imageformat_by_name(qUtf8Printable(formatargs.at(1)), strcmp); - if (imageformat_is_valid(format) && imagetool_is_valid(tool)) { - const struct toolkit *toolkit = img_toolkit_get(tool); + if (imageformat_is_valid(format)) { + const struct toolkit *toolkit = img_toolkit_get(); if (toolkit && (toolkit->formats & format)) { - pmapdef->tool = tool; pmapdef->format = format; - - error = false; } } } else { // Only one argument to format. - tool = imagetool_by_name(qUtf8Printable(formatargs.at(0)), strcmp); - if (imagetool_is_valid(tool)) { - // toolkit defined - const struct toolkit *toolkit = img_toolkit_get(tool); - - if (toolkit) { - pmapdef->tool = toolkit->tool; - pmapdef->format = toolkit->format_default; + // toolkit defined + const struct toolkit *toolkit = img_toolkit_get(); - error = false; - } - } else { - format = - imageformat_by_name(qUtf8Printable(formatargs.at(0)), strcmp); - if (imageformat_is_valid(format)) { - // format defined - img_toolkit_iterate(toolkit) - { - if ((toolkit->formats & format)) { - pmapdef->tool = toolkit->tool; - pmapdef->format = toolkit->format_default; - - error = false; - break; - } - } - img_toolkit_iterate_end; - } + if (toolkit) { + pmapdef->format = toolkit->format_default; } } - - if (error) { - goto INVALID; - } } break; @@ -1100,8 +1034,6 @@ bool mapimg_show(int id, char *str, size_t str_len, bool detail) } cat_snprintf(str, str_len, _(" - file name string: %s\n"), mapimg_generate_name(pmapdef)); - cat_snprintf(str, str_len, _(" - image toolkit: %s\n"), - imagetool_name(pmapdef->tool)); cat_snprintf(str, str_len, _(" - image format: %s\n"), imageformat_name(pmapdef->format)); cat_snprintf(str, str_len, _(" - zoom factor: %d\n"), @@ -1303,7 +1235,6 @@ bool mapimg_colortest(const char *savename, const char *path) int max_playercolor = mapimg.mapimg_plrcolor_count(); int max_terraincolor = terrain_count(); bool ret = true; - enum imagetool tool; #define SIZE_X 16 #define SIZE_Y 5 @@ -1356,32 +1287,18 @@ bool mapimg_colortest(const char *savename, const char *path) #undef SIZE_X #undef SIZE_Y - for (tool = imagetool_begin(); tool != imagetool_end(); - tool = imagetool_next(tool)) { enum imageformat format; - const struct toolkit *toolkit = img_toolkit_get(tool); - - if (!toolkit) { - continue; - } - - // Set the toolkit. - pmapdef->tool = tool; + const struct toolkit *toolkit = img_toolkit_get(); for (format = imageformat_begin(); format != imageformat_end(); format = imageformat_next(format)) { if (toolkit->formats & format) { char buf[128]; - const char *tname = imagetool_name(tool); // Set the image format. pmapdef->format = format; - if (tname != nullptr) { - fc_snprintf(buf, sizeof(buf), "colortest-%s", tname); - } else { - fc_snprintf(buf, sizeof(buf), "colortest"); - } + fc_snprintf(buf, sizeof(buf), "colortest"); // filename for color test generate_save_name(savename, mapimgfile, sizeof(mapimgfile), buf); @@ -1392,7 +1309,6 @@ bool mapimg_colortest(const char *savename, const char *path) } } } - } img_destroy(pimg); mapdef_destroy(pmapdef); @@ -1443,8 +1359,8 @@ static bool mapimg_def2str(struct mapdef *pmapdef, char *str, size_t str_len) } str[0] = '\0'; - cat_snprintf(str, str_len, "format=%s|%s:", imagetool_name(pmapdef->tool), - imageformat_name(pmapdef->format)); + cat_snprintf(str, str_len, + "format=%s:", imageformat_name(pmapdef->format)); cat_snprintf(str, str_len, "turns=%d:", pmapdef->turns); i = 0; @@ -1666,7 +1582,6 @@ static struct mapdef *mapdef_new(bool colortest) pmapdef->error[0] = '\0'; pmapdef->status = MAPIMG_STATUS_UNKNOWN; pmapdef->format = MAPIMG_DEFAULT_IMGFORMAT; - pmapdef->tool = MAPIMG_DEFAULT_IMGTOOL; pmapdef->zoom = 2; pmapdef->turns = 1; pmapdef->layers[MAPIMG_LAYER_TERRAIN] = false; @@ -1707,18 +1622,7 @@ static void mapdef_destroy(struct mapdef *pmapdef) /** Return the definition of the requested toolkit (or nullptr). */ -static const struct toolkit *img_toolkit_get(enum imagetool tool) -{ - img_toolkit_iterate(toolkit) - { - if (toolkit->tool == tool) { - return toolkit; - } - } - img_toolkit_iterate_end; - - return nullptr; -} +static const struct toolkit *img_toolkit_get() { return img_toolkits; } /** Create a new image. @@ -1889,13 +1793,12 @@ static void img_plot_tile(struct img *pimg, const struct tile *ptile, } /** - Save an image as ppm file. + Save an image. */ static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path) { - enum imagetool tool = pimg->def->tool; - const struct toolkit *toolkit = img_toolkit_get(tool); + const struct toolkit *toolkit = img_toolkit_get(); char tmpname[600]; if (!toolkit) { @@ -1916,9 +1819,7 @@ static bool img_save(const struct img *pimg, const char *mapimgfile, sz_strlcat(tmpname, mapimgfile); - MAPIMG_ASSERT_RET_VAL(toolkit->img_save, false); - - return toolkit->img_save(pimg, tmpname); + return img_save_qt(pimg, tmpname); } /** From 23f31e9bbbbfc31a64e48f4282bbe367f47131c6 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 4 Aug 2024 01:19:35 +0200 Subject: [PATCH 06/10] Remove built-in file format definitions Let the user set any image format supported by Qt. --- common/mapimg.cpp | 154 ++++++++++------------------------------------ 1 file changed, 33 insertions(+), 121 deletions(-) diff --git a/common/mapimg.cpp b/common/mapimg.cpp index f691881d42..bf3849d6a2 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -31,6 +31,7 @@ received a copy of the GNU General Public License along with Freeciv21. // Qt #include +#include #include // == image colors == @@ -174,19 +175,6 @@ static void base_coor_isohexa(struct img *pimg, int *base_x, int *base_y, BV_DEFINE(bv_mapdef_arg, MAPDEF_COUNT); -// image format -#define SPECENUM_NAME imageformat -#define SPECENUM_BITWISE -#define SPECENUM_VALUE0 IMGFORMAT_GIF -#define SPECENUM_VALUE0NAME "gif" -#define SPECENUM_VALUE1 IMGFORMAT_PNG -#define SPECENUM_VALUE1NAME "png" -#define SPECENUM_VALUE2 IMGFORMAT_PPM -#define SPECENUM_VALUE2NAME "ppm" -#define SPECENUM_VALUE3 IMGFORMAT_JPG -#define SPECENUM_VALUE3NAME "jpg" -#include "specenum_gen.h" - // player definitions #define SPECENUM_NAME show_player #define SPECENUM_VALUE0 SHOW_NONE @@ -225,6 +213,8 @@ BV_DEFINE(bv_mapdef_arg, MAPDEF_COUNT); #define MAX_LEN_MAPARG MAX_LEN_MAPDEF #define MAX_NUM_MAPIMG 10 +const static auto MAPIMG_DEFAULT_IMGFORMAT = QByteArrayLiteral("png"); + static inline bool mapimg_initialised(); static bool mapimg_test(int id); static bool mapimg_define_arg(struct mapdef *pmapdef, enum mapdef_arg arg, @@ -239,7 +229,7 @@ struct mapdef { char maparg[MAX_LEN_MAPARG]; char error[MAX_LEN_MAPDEF]; enum mapimg_status status; - enum imageformat format; + QByteArray format; int zoom; int turns; bool layers[MAPIMG_LAYER_COUNT]; @@ -314,7 +304,7 @@ static void img_plot_tile(struct img *pimg, const struct tile *ptile, static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path); static bool img_save_qt(const struct img *pimg, const char *mapimgfile); -static bool img_filename(const char *mapimgfile, enum imageformat format, +static bool img_filename(const char *mapimgfile, const QByteArray &format, char *filename, size_t filename_len); static void img_createmap(struct img *pimg); @@ -322,23 +312,6 @@ static void img_createmap(struct img *pimg); typedef bool (*img_save_func)(const struct img *pimg, const char *mapimgfile); -struct toolkit { - enum imageformat format_default; - int formats; -}; - -#define GEN_TOOLKIT(_format_default, _formats) {_format_default, _formats}, - -static struct toolkit img_toolkits[] = { - GEN_TOOLKIT(IMGFORMAT_PNG, IMGFORMAT_PNG)}; - -static const int img_toolkits_count = ARRAY_SIZE(img_toolkits); - -#define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_PNG -#define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_QT - -static const struct toolkit *img_toolkit_get(); - // == logging == #define MAX_LEN_ERRORBUF 1024 @@ -493,7 +466,7 @@ char *mapimg_help(const char *cmdname) enum show_player showplr; enum mapimg_layer layer; QString defaults[MAPDEF_COUNT]; - QString str_format, str_showplr, help; + QString str_showplr, help; struct mapdef *pmapdef; if (help.length() > 0) { @@ -502,22 +475,8 @@ char *mapimg_help(const char *cmdname) } pmapdef = mapdef_new(false); - { - enum imageformat format; - const struct toolkit *toolkit = img_toolkit_get(); - - str_format += QStringLiteral(" - "); - - const char *separator = ""; - for (format = imageformat_begin(); format != imageformat_end(); - format = imageformat_next(format)) { - if (toolkit->formats & format) { - str_format += QStringLiteral("%1'%2'").arg(separator, - imageformat_name(format)); - separator = ", "; - } - } - } + auto str_format = + QImageWriter::supportedImageFormats().join(QByteArrayLiteral(", ")); // Possible 'show' settings. for (showplr = show_player_begin(); showplr != show_player_end(); @@ -539,7 +498,7 @@ char *mapimg_help(const char *cmdname) // Default values. defaults[MAPDEF_FORMAT] = - QStringLiteral("(%2)").arg(imageformat_name(pmapdef->format)); + QStringLiteral("(%2)").arg(QString(MAPIMG_DEFAULT_IMGFORMAT)); defaults[MAPDEF_SHOW] = QStringLiteral("(%1)").arg(show_player_name(pmapdef->player.show)); defaults[MAPDEF_TURNS] = @@ -592,8 +551,7 @@ char *mapimg_help(const char *cmdname) "map= %5 which map layers to draw\n" "\n" " = use image format . The following formats " - "are " - "compiled in:\n" + "are available:\n" "%6\n" "\n" " determines which players are represented and how many " @@ -612,7 +570,7 @@ char *mapimg_help(const char *cmdname) "Examples of :\n" " 'zoom=1:map=tcub:show=all:format=png'\n" " 'zoom=2:map=tcub:show=each:format=png'\n" - " 'zoom=1:map=tcub:show=plrname:plrname=Otto:format=gif'\n" + " 'zoom=1:map=tcub:show=plrname:plrname=Otto:format=bmp'\n" " 'zoom=3:map=cu:show=plrbv:plrbv=010011:format=jpg'\n" " 'zoom=1:map=t:show=none:format=jpg'")) .arg(defaults[MAPDEF_FORMAT], -10) @@ -771,32 +729,10 @@ static bool mapimg_define_arg(struct mapdef *pmapdef, enum mapdef_arg arg, switch (arg) { case MAPDEF_FORMAT: // file format - { - QStringList formatargs; - enum imageformat format; - - // get format options - formatargs = QString(val).split(QStringLiteral("|")); - if (formatargs.count() == 2) { - format = - imageformat_by_name(qUtf8Printable(formatargs.at(1)), strcmp); - - if (imageformat_is_valid(format)) { - const struct toolkit *toolkit = img_toolkit_get(); - - if (toolkit && (toolkit->formats & format)) { - pmapdef->format = format; - } - } - } else { - // Only one argument to format. - // toolkit defined - const struct toolkit *toolkit = img_toolkit_get(); - - if (toolkit) { - pmapdef->format = toolkit->format_default; - } - } + if (QImageWriter::supportedImageFormats().contains(val)) { + pmapdef->format = val; + } else { + pmapdef->format = MAPIMG_DEFAULT_IMGFORMAT; } break; @@ -1035,7 +971,7 @@ bool mapimg_show(int id, char *str, size_t str_len, bool detail) cat_snprintf(str, str_len, _(" - file name string: %s\n"), mapimg_generate_name(pmapdef)); cat_snprintf(str, str_len, _(" - image format: %s\n"), - imageformat_name(pmapdef->format)); + MAPIMG_DEFAULT_IMGFORMAT.data()); cat_snprintf(str, str_len, _(" - zoom factor: %d\n"), pmapdef->zoom); cat_snprintf(str, str_len, _(" - show area within borders: %s\n"), @@ -1287,28 +1223,22 @@ bool mapimg_colortest(const char *savename, const char *path) #undef SIZE_X #undef SIZE_Y - enum imageformat format; - const struct toolkit *toolkit = img_toolkit_get(); - - for (format = imageformat_begin(); format != imageformat_end(); - format = imageformat_next(format)) { - if (toolkit->formats & format) { - char buf[128]; + for (const auto &format : QImageWriter::supportedImageFormats()) { + char buf[128]; - // Set the image format. - pmapdef->format = format; + // Set the image format. + pmapdef->format = format; - fc_snprintf(buf, sizeof(buf), "colortest"); - // filename for color test - generate_save_name(savename, mapimgfile, sizeof(mapimgfile), buf); + fc_snprintf(buf, sizeof(buf), "colortest"); + // filename for color test + generate_save_name(savename, mapimgfile, sizeof(mapimgfile), buf); - if (!img_save(pimg, mapimgfile, path)) { - /* If one of the mapimg format/toolkit combination fail, return - * FALSE, i.e. an error occurred. */ - ret = false; - } - } + if (!img_save(pimg, mapimgfile, path)) { + /* If one of the mapimg format/toolkit combination fail, return + * FALSE, i.e. an error occurred. */ + ret = false; } + } img_destroy(pimg); mapdef_destroy(pmapdef); @@ -1359,8 +1289,7 @@ static bool mapimg_def2str(struct mapdef *pmapdef, char *str, size_t str_len) } str[0] = '\0'; - cat_snprintf(str, str_len, - "format=%s:", imageformat_name(pmapdef->format)); + cat_snprintf(str, str_len, "format=%s:", pmapdef->format.data()); cat_snprintf(str, str_len, "turns=%d:", pmapdef->turns); i = 0; @@ -1619,11 +1548,6 @@ static void mapdef_destroy(struct mapdef *pmapdef) * ============================================== */ -/** - Return the definition of the requested toolkit (or nullptr). - */ -static const struct toolkit *img_toolkit_get() { return img_toolkits; } - /** Create a new image. */ @@ -1798,14 +1722,8 @@ static void img_plot_tile(struct img *pimg, const struct tile *ptile, static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path) { - const struct toolkit *toolkit = img_toolkit_get(); char tmpname[600]; - if (!toolkit) { - MAPIMG_LOG(_("toolkit not defined")); - return false; - } - if (!QFileInfo(mapimgfile).isAbsolute() && path != nullptr) { make_dir(path); @@ -1829,12 +1747,8 @@ static bool img_save_qt(const struct img *pimg, const char *mapimgfile) { char pngname[MAX_LEN_PATH]; - if (pimg->def->format != IMGFORMAT_PNG) { - MAPIMG_LOG(_("Qt can only create images in the png format")); - return false; - } - - if (!img_filename(mapimgfile, IMGFORMAT_PNG, pngname, sizeof(pngname))) { + if (!img_filename(mapimgfile, pimg->def->format, pngname, + sizeof(pngname))) { MAPIMG_LOG(_("error generating the file name")); return false; } @@ -1898,13 +1812,11 @@ static bool img_save_qt(const struct img *pimg, const char *mapimgfile) /** Generate the final filename. */ -static bool img_filename(const char *mapimgfile, enum imageformat format, +static bool img_filename(const char *mapimgfile, const QByteArray &format, char *filename, size_t filename_len) { - fc_assert_ret_val(imageformat_is_valid(format), false); - fc_snprintf(filename, filename_len, "%s.map.%s", mapimgfile, - imageformat_name(format)); + format.data()); return true; } From e8aa9a7b0e1674ce056f11dcededcb3aa7581a36 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 4 Aug 2024 01:26:13 +0200 Subject: [PATCH 07/10] Fold img_save_qt in to img_save --- common/mapimg.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/common/mapimg.cpp b/common/mapimg.cpp index bf3849d6a2..e7caf63a8f 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -303,15 +303,10 @@ static void img_plot_tile(struct img *pimg, const struct tile *ptile, const bv_pixel pixel); static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path); -static bool img_save_qt(const struct img *pimg, const char *mapimgfile); static bool img_filename(const char *mapimgfile, const QByteArray &format, char *filename, size_t filename_len); static void img_createmap(struct img *pimg); -// == image toolkits == -typedef bool (*img_save_func)(const struct img *pimg, - const char *mapimgfile); - // == logging == #define MAX_LEN_ERRORBUF 1024 @@ -1737,14 +1732,6 @@ static bool img_save(const struct img *pimg, const char *mapimgfile, sz_strlcat(tmpname, mapimgfile); - return img_save_qt(pimg, tmpname); -} - -/** - * Save an image with Qt. - */ -static bool img_save_qt(const struct img *pimg, const char *mapimgfile) -{ char pngname[MAX_LEN_PATH]; if (!img_filename(mapimgfile, pimg->def->format, pngname, From 924eeea11c647db083eb4d5503be37eb2c53035f Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 4 Aug 2024 01:28:45 +0200 Subject: [PATCH 08/10] Remove unused function img_playerstr --- common/mapimg.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/common/mapimg.cpp b/common/mapimg.cpp index e7caf63a8f..37da5df2e8 100644 --- a/common/mapimg.cpp +++ b/common/mapimg.cpp @@ -295,7 +295,6 @@ static inline void img_set_pixel(struct img *pimg, const int mindex, const struct rgbcolor *pcolor); static inline int img_index(const int x, const int y, const struct img *pimg); -static const char *img_playerstr(const struct player *pplayer); static void img_plot(struct img *pimg, int x, int y, const struct rgbcolor *pcolor, const bv_pixel pixel); static void img_plot_tile(struct img *pimg, const struct tile *ptile, @@ -1808,22 +1807,6 @@ static bool img_filename(const char *mapimgfile, const QByteArray &format, return true; } -/** - Return a definition string for the player. - */ -static const char *img_playerstr(const struct player *pplayer) -{ - static char buf[512]; - const struct rgbcolor *pcolor = imgcolor_player(player_index(pplayer)); - - fc_snprintf(buf, sizeof(buf), - "playerno:%d:color:(%3d, %3d, %3d):name:\"%s\"", - player_number(pplayer), pcolor->r, pcolor->g, pcolor->b, - player_name(pplayer)); - - return buf; -} - /** Create the map considering the options (terrain, player(s), cities, units, borders, known, fogofwar, ...). From 853b39998cc3b6664d0a99e8c3d93d210c63165a Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Tue, 6 Aug 2024 18:52:58 +0200 Subject: [PATCH 09/10] Don't try to install the MAGICKWAND licence --- cmake/FreecivInstall.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/FreecivInstall.cmake b/cmake/FreecivInstall.cmake index e2de189376..7a6d9176b8 100644 --- a/cmake/FreecivInstall.cmake +++ b/cmake/FreecivInstall.cmake @@ -26,7 +26,6 @@ install( ${CMAKE_SOURCE_DIR}/dist/licenses/LGPL-2.0-OR-LATER.txt ${CMAKE_SOURCE_DIR}/dist/licenses/LGPL-3.0-ONLY.txt ${CMAKE_SOURCE_DIR}/dist/licenses/LICENSEREF-KDE-ACCEPTED-LGPL.txt - ${CMAKE_SOURCE_DIR}/dist/licenses/MAGICKWAND.txt ${CMAKE_SOURCE_DIR}/dist/licenses/MIT.txt ${CMAKE_SOURCE_DIR}/dist/licenses/OPENSSL.txt ${CMAKE_SOURCE_DIR}/dist/licenses/PNG.txt From ff80c31337dd5664cc0722fab2e94a6a669f657c Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 10 Aug 2024 15:36:24 +0200 Subject: [PATCH 10/10] Delete the IMAGEMAGICK license --- dist/licenses/IMAGEMAGICK.txt | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 dist/licenses/IMAGEMAGICK.txt diff --git a/dist/licenses/IMAGEMAGICK.txt b/dist/licenses/IMAGEMAGICK.txt deleted file mode 100644 index 6881f8964f..0000000000 --- a/dist/licenses/IMAGEMAGICK.txt +++ /dev/null @@ -1,16 +0,0 @@ -ImageMagick License -=================== - -Copyright [yyyy] [name of copyright owner] - -Licensed under the ImageMagick License (the "License"); you may not use -this file except in compliance with the License. You may obtain a copy -of the License at - - https://imagemagick.org/script/license.php - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations -under the License.