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