mirror of
https://github.com/minetest/minetestmapper.git
synced 2025-07-04 17:40:22 +02:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
de259280b6 | |||
75009ad49c |
@ -10,7 +10,7 @@ addons:
|
|||||||
- ubuntu-toolchain-r-test
|
- ubuntu-toolchain-r-test
|
||||||
packages:
|
packages:
|
||||||
- cmake
|
- cmake
|
||||||
- libgd2-noxpm-dev
|
- libfreeimage-dev
|
||||||
- libsqlite3-dev
|
- libsqlite3-dev
|
||||||
- p7zip
|
- p7zip
|
||||||
- g++-6
|
- g++-6
|
||||||
|
@ -45,15 +45,15 @@ if(NOT CUSTOM_DOCDIR STREQUAL "")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Libraries: gd
|
# Libraries: freeimage
|
||||||
|
|
||||||
find_library(LIBGD_LIBRARY gd)
|
find_library(FREEIMAGE_LIBRARY freeimage)
|
||||||
find_path(LIBGD_INCLUDE_DIR gd.h)
|
find_path(FREEIMAGE_INCLUDE_DIR FreeImage.h)
|
||||||
message (STATUS "libgd library: ${LIBGD_LIBRARY}")
|
message (STATUS "FreeImage library: ${FREEIMAGE_LIBRARY}")
|
||||||
message (STATUS "libgd headers: ${LIBGD_INCLUDE_DIR}")
|
message (STATUS "FreeImage headers: ${FREEIMAGE_INCLUDE_DIR}")
|
||||||
if(NOT LIBGD_LIBRARY OR NOT LIBGD_INCLUDE_DIR)
|
if(NOT FREEIMAGE_LIBRARY OR NOT FREEIMAGE_INCLUDE_DIR)
|
||||||
message(FATAL_ERROR "libgd not found!")
|
message(FATAL_ERROR "FreeImage not found!")
|
||||||
endif(NOT LIBGD_LIBRARY OR NOT LIBGD_INCLUDE_DIR)
|
endif(NOT FREEIMAGE_LIBRARY OR NOT FREEIMAGE_INCLUDE_DIR)
|
||||||
|
|
||||||
# Libraries: zlib
|
# Libraries: zlib
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ include_directories(
|
|||||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
${SQLITE3_INCLUDE_DIR}
|
${SQLITE3_INCLUDE_DIR}
|
||||||
${LIBGD_INCLUDE_DIR}
|
${FREEIMAGE_INCLUDE_DIR}
|
||||||
${ZLIB_INCLUDE_DIR}
|
${ZLIB_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ target_link_libraries(
|
|||||||
${SQLITE3_LIBRARY}
|
${SQLITE3_LIBRARY}
|
||||||
${LEVELDB_LIBRARY}
|
${LEVELDB_LIBRARY}
|
||||||
${REDIS_LIBRARY}
|
${REDIS_LIBRARY}
|
||||||
${LIBGD_LIBRARY}
|
${FREEIMAGE_LIBRARY}
|
||||||
${ZLIB_LIBRARY}
|
${ZLIB_LIBRARY}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
57
Image.cpp
57
Image.cpp
@ -4,8 +4,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <gd.h>
|
|
||||||
#include <gdfontmb.h>
|
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
@ -22,40 +20,41 @@
|
|||||||
|
|
||||||
// ARGB but with inverted alpha
|
// ARGB but with inverted alpha
|
||||||
|
|
||||||
static inline int color2int(Color c)
|
static inline RGBQUAD color2rgbquad(Color c)
|
||||||
{
|
{
|
||||||
u8 a = 255 - c.a;
|
RGBQUAD c2;
|
||||||
return (a << 24) | (c.r << 16) | (c.g << 8) | c.b;
|
c2.rgbRed = c.r;
|
||||||
|
c2.rgbGreen = c.g;
|
||||||
|
c2.rgbBlue = c.b;
|
||||||
|
return c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Color int2color(int c)
|
static inline Color rgbquad2color(RGBQUAD c)
|
||||||
{
|
{
|
||||||
Color c2;
|
return Color(c.rgbRed, c.rgbGreen, c.rgbBlue);
|
||||||
u8 a;
|
|
||||||
c2.b = c & 0xff;
|
|
||||||
c2.g = (c >> 8) & 0xff;
|
|
||||||
c2.r = (c >> 16) & 0xff;
|
|
||||||
a = (c >> 24) & 0xff;
|
|
||||||
c2.a = 255 - a;
|
|
||||||
return c2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Image::Image(int width, int height) :
|
Image::Image(int width, int height) :
|
||||||
m_width(width), m_height(height), m_image(NULL)
|
m_width(width), m_height(height), m_image(NULL)
|
||||||
{
|
{
|
||||||
m_image = gdImageCreateTrueColor(m_width, m_height);
|
// FIXME: This works because minetestmapper only creates one image
|
||||||
|
FreeImage_Initialise();
|
||||||
|
printf("Using FreeImage v%s\n", FreeImage_GetVersion());
|
||||||
|
|
||||||
|
m_image = FreeImage_Allocate(width, height, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::~Image()
|
Image::~Image()
|
||||||
{
|
{
|
||||||
gdImageDestroy(m_image);
|
FreeImage_Unload(m_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::setPixel(int x, int y, const Color &c)
|
void Image::setPixel(int x, int y, const Color &c)
|
||||||
{
|
{
|
||||||
SIZECHECK(x, y);
|
SIZECHECK(x, y);
|
||||||
m_image->tpixels[y][x] = color2int(c);
|
RGBQUAD col = color2rgbquad(c);
|
||||||
|
FreeImage_SetPixelColor(m_image, x, y, &col);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color Image::getPixel(int x, int y)
|
Color Image::getPixel(int x, int y)
|
||||||
@ -64,43 +63,41 @@ Color Image::getPixel(int x, int y)
|
|||||||
if(x < 0 || x > m_width || y < 0 || y > m_height)
|
if(x < 0 || x > m_width || y < 0 || y > m_height)
|
||||||
throw std::out_of_range("sizecheck");
|
throw std::out_of_range("sizecheck");
|
||||||
#endif
|
#endif
|
||||||
return int2color(m_image->tpixels[y][x]);
|
RGBQUAD c;
|
||||||
|
FreeImage_GetPixelColor(m_image, x, y, &c);
|
||||||
|
return rgbquad2color(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::drawLine(int x1, int y1, int x2, int y2, const Color &c)
|
void Image::drawLine(int x1, int y1, int x2, int y2, const Color &c)
|
||||||
{
|
{
|
||||||
SIZECHECK(x1, y1);
|
SIZECHECK(x1, y1);
|
||||||
SIZECHECK(x2, y2);
|
SIZECHECK(x2, y2);
|
||||||
gdImageLine(m_image, x1, y1, x2, y2, color2int(c));
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::drawText(int x, int y, const std::string &s, const Color &c)
|
void Image::drawText(int x, int y, const std::string &s, const Color &c)
|
||||||
{
|
{
|
||||||
SIZECHECK(x, y);
|
SIZECHECK(x, y);
|
||||||
gdImageString(m_image, gdFontGetMediumBold(), x, y, (unsigned char*) s.c_str(), color2int(c));
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::drawFilledRect(int x, int y, int w, int h, const Color &c)
|
void Image::drawFilledRect(int x, int y, int w, int h, const Color &c)
|
||||||
{
|
{
|
||||||
SIZECHECK(x, y);
|
SIZECHECK(x, y);
|
||||||
SIZECHECK(x + w - 1, y + h - 1);
|
SIZECHECK(x + w - 1, y + h - 1);
|
||||||
gdImageFilledRectangle(m_image, x, y, x + w - 1, y + h - 1, color2int(c));
|
RGBQUAD col = color2rgbquad(c);
|
||||||
|
for(int xx = 0; xx < w; xx++)
|
||||||
|
for(int yy = 0; yy < h; yy++)
|
||||||
|
FreeImage_SetPixelColor(m_image, x + xx, y + yy, &col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::drawCircle(int x, int y, int diameter, const Color &c)
|
void Image::drawCircle(int x, int y, int diameter, const Color &c)
|
||||||
{
|
{
|
||||||
SIZECHECK(x, y);
|
SIZECHECK(x, y);
|
||||||
gdImageArc(m_image, x, y, diameter, diameter, 0, 360, color2int(c));
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::save(const std::string &filename)
|
void Image::save(const std::string &filename)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(filename.c_str(), "wb");
|
FreeImage_Save(FIF_PNG, m_image, filename.c_str()); // other formats?
|
||||||
if(!f) {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << "Error writing image file: " << std::strerror(errno);
|
|
||||||
throw std::runtime_error(oss.str());
|
|
||||||
}
|
|
||||||
gdImagePng(m_image, f); // other formats?
|
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
|
4
Image.h
4
Image.h
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gd.h>
|
#include <FreeImage.h>
|
||||||
|
|
||||||
struct Color {
|
struct Color {
|
||||||
Color() : r(0), g(0), b(0), a(0) {};
|
Color() : r(0), g(0), b(0), a(0) {};
|
||||||
@ -29,7 +29,7 @@ private:
|
|||||||
Image(const Image&);
|
Image(const Image&);
|
||||||
|
|
||||||
int m_width, m_height;
|
int m_width, m_height;
|
||||||
gdImagePtr m_image;
|
FIBITMAP *m_image;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGE_HEADER
|
#endif // IMAGE_HEADER
|
||||||
|
@ -10,7 +10,7 @@ This version is both faster and provides more features than the now deprecated P
|
|||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* libgd
|
* FreeImage
|
||||||
* sqlite3
|
* sqlite3
|
||||||
* leveldb (optional, set ENABLE_LEVELDB=1 in CMake to enable leveldb support)
|
* leveldb (optional, set ENABLE_LEVELDB=1 in CMake to enable leveldb support)
|
||||||
* hiredis (optional, set ENABLE_REDIS=1 in CMake to enable redis support)
|
* hiredis (optional, set ENABLE_REDIS=1 in CMake to enable redis support)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef TILEGENERATOR_HEADER
|
#ifndef TILEGENERATOR_HEADER
|
||||||
#define TILEGENERATOR_HEADER
|
#define TILEGENERATOR_HEADER
|
||||||
|
|
||||||
#include <gd.h>
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
15
colors.txt
15
colors.txt
@ -7,14 +7,7 @@ beds:fancy_bed_top 172 112 103
|
|||||||
# bones
|
# bones
|
||||||
bones:bones 86 86 86
|
bones:bones 86 86 86
|
||||||
|
|
||||||
# carts
|
|
||||||
carts:brakerail 129 110 81
|
|
||||||
carts:powerrail 154 136 81
|
|
||||||
carts:rail 143 123 90
|
|
||||||
|
|
||||||
# default
|
# default
|
||||||
default:acacia_bush_leaves 90 124 55
|
|
||||||
default:acacia_bush_stem 84 76 69
|
|
||||||
default:acacia_leaves 108 147 67
|
default:acacia_leaves 108 147 67
|
||||||
default:acacia_sapling 87 116 61
|
default:acacia_sapling 87 116 61
|
||||||
default:acacia_tree 188 109 90
|
default:acacia_tree 188 109 90
|
||||||
@ -27,8 +20,6 @@ default:aspen_wood 209 198 169
|
|||||||
default:bookshelf 128 99 55
|
default:bookshelf 128 99 55
|
||||||
default:brick 117 71 69
|
default:brick 117 71 69
|
||||||
default:bronzeblock 185 110 15
|
default:bronzeblock 185 110 15
|
||||||
default:bush_leaves 34 52 29
|
|
||||||
default:bush_stem 45 33 23
|
|
||||||
default:cactus 52 116 15
|
default:cactus 52 116 15
|
||||||
default:chest 140 108 65
|
default:chest 140 108 65
|
||||||
default:chest_locked 140 108 65
|
default:chest_locked 140 108 65
|
||||||
@ -37,9 +28,6 @@ default:cloud 255 255 255
|
|||||||
default:coalblock 57 57 57
|
default:coalblock 57 57 57
|
||||||
default:cobble 88 84 82
|
default:cobble 88 84 82
|
||||||
default:copperblock 192 126 63
|
default:copperblock 192 126 63
|
||||||
default:coral_brown 139 104 72
|
|
||||||
default:coral_orange 191 62 12
|
|
||||||
default:coral_skeleton 235 230 214
|
|
||||||
default:desert_cobble 146 95 76
|
default:desert_cobble 146 95 76
|
||||||
default:desert_sand 206 165 98
|
default:desert_sand 206 165 98
|
||||||
default:desert_stone 129 79 60
|
default:desert_stone 129 79 60
|
||||||
@ -95,6 +83,7 @@ default:pine_needles 13 36 21
|
|||||||
default:pine_sapling 27 48 25
|
default:pine_sapling 27 48 25
|
||||||
default:pine_tree 182 155 124
|
default:pine_tree 182 155 124
|
||||||
default:pine_wood 221 184 128
|
default:pine_wood 221 184 128
|
||||||
|
default:rail 143 123 90
|
||||||
default:river_water_flowing 39 66 106 128 224
|
default:river_water_flowing 39 66 106 128 224
|
||||||
default:river_water_source 39 66 106 128 224
|
default:river_water_source 39 66 106 128 224
|
||||||
default:sand 214 207 158
|
default:sand 214 207 158
|
||||||
@ -118,8 +107,6 @@ default:stone_with_iron 97 94 93
|
|||||||
default:stone_with_mese 97 94 93
|
default:stone_with_mese 97 94 93
|
||||||
default:stonebrick 99 96 95
|
default:stonebrick 99 96 95
|
||||||
default:torch 120 98 67
|
default:torch 120 98 67
|
||||||
default:torch_ceiling 120 98 67
|
|
||||||
default:torch_wall 120 98 67
|
|
||||||
default:tree 164 131 88
|
default:tree 164 131 88
|
||||||
default:water_flowing 39 66 106 128 224
|
default:water_flowing 39 66 106 128 224
|
||||||
default:water_source 39 66 106 128 224
|
default:water_source 39 66 106 128 224
|
||||||
|
Reference in New Issue
Block a user