Add a default color for nodes

This is useful to show invisible ('air' or 'invalid') nodes in blocks
that are in the database using a different color than blocks that are
not in the database (which will have no color at all, causing the
background color to show).
master
Rogier 2014-05-23 13:16:07 +02:00
parent 5369adb937
commit ced0390611
5 changed files with 34 additions and 1 deletions

View File

@ -12,6 +12,11 @@
are: point, line, rectangle, ellipse (circle), text.
Translucency (alpha) is supported, although for ellipses, it does not
work as expected (due to a bug in libgd)
- A default color can be specified for invisible/undefined nodes in rendered
blocks Normally, such nodes are not drawn, so they have the background
color; If a different default color is specified, undefined/invisible
nodes in defined blocks get the default color, and can be distinguished
from undefined blocks (which still have the regular background color).
Enhancements:
- Failure to process a command-line option now causes a specific error message.

View File

@ -137,6 +137,13 @@ colors <file>:
bgcolor:
Background color of image, `--bgcolor #ffffff`
blockcolor:
Default color of nodes in blocks that are in the database, `--blockcolor #ffffff`
If a block is in the database, but some of its nodes are not visible (because they are
air, or 'invalid', the nodes are drawn in this color (as opposed to the background
color, which shows for blocks that are not in the database)
scalecolor:
Color of scale, `--scalecolor #000000`

View File

@ -122,6 +122,7 @@ TileGenerator::TileGenerator():
verboseStatistics(false),
progressIndicator(false),
m_bgColor(255, 255, 255),
m_blockDefaultColor(0, 0, 0, 0),
m_scaleColor(0, 0, 0),
m_originColor(255, 0, 0),
m_playerColor(255, 0, 0),
@ -175,6 +176,13 @@ void TileGenerator::setBgColor(const Color &bgColor)
m_bgColor = bgColor;
}
void TileGenerator::setBlockDefaultColor(const Color &color)
{
m_blockDefaultColor = color;
// Any value will do, except for 0
m_blockDefaultColor.a = 1;
}
void TileGenerator::setShrinkGeometry(bool shrink)
{
m_shrinkGeometry = shrink;
@ -801,7 +809,7 @@ void TileGenerator::pushPixelRows(int zPosLimit) {
{ int ix = mapX2ImageX(mapX); assert(ix - m_border >= 0 && ix - m_border < m_pictWidth); }
{ int iy = mapY2ImageY(mapY); assert(iy - m_border >= 0 && iy - m_border < m_pictHeight); }
#endif
if (pixel.is_valid())
if (pixel.is_valid() || pixel.color().to_uint())
m_image->tpixels[mapY2ImageY(mapY)][mapX2ImageX(mapX)] = pixel.color().to_libgd();
}
}
@ -1203,6 +1211,11 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
if (m_readedPixels[z] & (1 << x)) {
continue;
}
if (m_blockDefaultColor.to_uint() && !m_blockPixelAttributes.attribute(zBegin + 15 - z,xBegin + x).color().to_uint()) {
PixelAttribute pixel = PixelAttribute(m_blockDefaultColor, NAN);
m_blockPixelAttributes.attribute(zBegin + 15 - z,xBegin + x) = pixel;
rowIsEmpty = false;
}
for (int y = maxY; y >= minY; --y) {
int position = x + (y << 4) + (z << 8);
int content = readBlockContent(mapData, version, position);

View File

@ -83,6 +83,7 @@ public:
TileGenerator();
~TileGenerator();
void setBgColor(const Color &bgColor);
void setBlockDefaultColor(const Color &olor);
void setScaleColor(const Color &scaleColor);
void setOriginColor(const Color &originColor);
void setPlayerColor(const Color &playerColor);
@ -159,6 +160,7 @@ public:
private:
Color m_bgColor;
Color m_blockDefaultColor;
Color m_scaleColor;
Color m_originColor;
Color m_playerColor;

View File

@ -25,6 +25,7 @@ using namespace std;
#define OPT_SQLITE_CACHEWORLDROW 0x81
#define OPT_PROGRESS_INDICATOR 0x82
#define OPT_DRAW_OBJECT 0x83
#define OPT_BLOCKCOLOR 0x84
#define OPT_VERBOSE_SEARCH_COLORS 0x86
// Will be replaced with the actual name and location of the executable (if found)
@ -61,6 +62,7 @@ void usage()
" -o/--output <output_image.png>\n"
" --colors <file>\n"
" --bgcolor <color>\n"
" --blockcolor <color>\n"
" --scalecolor <color>\n"
" --playercolor <color>\n"
" --origincolor <color>\n"
@ -516,6 +518,7 @@ int main(int argc, char *argv[])
{"output", required_argument, 0, 'o'},
{"colors", required_argument, 0, 'C'},
{"bgcolor", required_argument, 0, 'b'},
{"blockcolor", required_argument, 0, OPT_BLOCKCOLOR},
{"scalecolor", required_argument, 0, 's'},
{"origincolor", required_argument, 0, 'r'},
{"playercolor", required_argument, 0, 'p'},
@ -596,6 +599,9 @@ int main(int argc, char *argv[])
case 'b':
generator.setBgColor(Color(optarg, 0));
break;
case OPT_BLOCKCOLOR:
generator.setBlockDefaultColor(Color(optarg, 0));
break;
case 's':
generator.setScaleColor(Color(optarg,0));
break;