summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/rltiles/tool
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2011-10-02 03:23:19 +0200
committerAdam Borowski <kilobyte@angband.pl>2011-10-02 03:28:23 +0200
commit41b259ab8140afb2dd011eeb364b48e6db0fcfed (patch)
tree75f20e5c89162448380aa34eb2f43cd5a3a75532 /crawl-ref/source/rltiles/tool
parent0594cdf657f780e13e3726b549610818ad1d44e7 (diff)
downloadcrawl-ref-41b259ab8140afb2dd011eeb364b48e6db0fcfed.tar.gz
crawl-ref-41b259ab8140afb2dd011eeb364b48e6db0fcfed.zip
A new rltiles command %texture that can use an image as a mask for compositing.
For example, simulacra tiles may be produced from zombies by using a zombie tile as a cut-out mask applied to an ice texture. Pixels that are black (exactly) stay black. Pixels of any other colour use the texture. Pixels that are transparent (fully or partially) retain transparency.
Diffstat (limited to 'crawl-ref/source/rltiles/tool')
-rw-r--r--crawl-ref/source/rltiles/tool/tile.cc35
-rw-r--r--crawl-ref/source/rltiles/tool/tile.h1
-rw-r--r--crawl-ref/source/rltiles/tool/tile_list_processor.cc36
-rw-r--r--crawl-ref/source/rltiles/tool/tile_list_processor.h1
4 files changed, 73 insertions, 0 deletions
diff --git a/crawl-ref/source/rltiles/tool/tile.cc b/crawl-ref/source/rltiles/tool/tile.cc
index c2c0bbc7ee..672ac3cf75 100644
--- a/crawl-ref/source/rltiles/tool/tile.cc
+++ b/crawl-ref/source/rltiles/tool/tile.cc
@@ -327,6 +327,41 @@ bool tile::compose(const tile &img)
return (true);
}
+bool tile::texture(const tile &img)
+{
+ if (!valid())
+ {
+ fprintf(stderr, "Error: can't texture onto an unloaded image.\n");
+ return (false);
+ }
+
+ if (!img.valid())
+ {
+ fprintf(stderr, "Error: can't texture from an unloaded image.\n");
+ return (false);
+ }
+
+ if (m_width != img.m_width || m_height != img.m_height)
+ {
+ fprintf(stderr, "Error: can't texture with mismatched dimensions. "
+ "(%d, %d) onto (%d, %d)\n",
+ img.m_width, img.m_height, m_width, m_height);
+ return (false);
+ }
+
+ for (int i = 0; i < m_width * m_height; i += 1)
+ {
+ const tile_colour *src = &img.m_pixels[i];
+ tile_colour *dest = &m_pixels[i];
+
+ if (dest->r || dest->g || dest->b)
+ dest->r = src->r, dest->g = src->g, dest->b = src->b;
+ // alpha is unchanged
+ }
+
+ return (true);
+}
+
bool tile::load(const std::string &new_filename)
{
m_filename = new_filename;
diff --git a/crawl-ref/source/rltiles/tool/tile.h b/crawl-ref/source/rltiles/tool/tile.h
index 7381763ead..fff878d055 100644
--- a/crawl-ref/source/rltiles/tool/tile.h
+++ b/crawl-ref/source/rltiles/tool/tile.h
@@ -27,6 +27,7 @@ public:
void copy(const tile &img);
bool compose(const tile &img);
+ bool texture(const tile &img);
void replace_colour(tile_colour &find, tile_colour &replace);
void fill(const tile_colour &col);
diff --git a/crawl-ref/source/rltiles/tool/tile_list_processor.cc b/crawl-ref/source/rltiles/tool/tile_list_processor.cc
index 24452ce864..4e7d19c6bc 100644
--- a/crawl-ref/source/rltiles/tool/tile_list_processor.cc
+++ b/crawl-ref/source/rltiles/tool/tile_list_processor.cc
@@ -16,6 +16,7 @@ tile_list_processor::tile_list_processor() :
m_corpsify(false),
m_composing(false),
m_shrink(true),
+ m_texture(0),
m_prefix("TILE"),
m_start_value("0"),
m_variation_idx(-1),
@@ -30,6 +31,8 @@ tile_list_processor::~tile_list_processor()
delete m_back[i];
m_back.resize(0);
+ if (m_texture)
+ delete m_texture;
}
bool tile_list_processor::load_image(tile &img, const char *filename,
@@ -395,6 +398,9 @@ bool tile_list_processor::process_line(char *read_line, const char *list_file,
else if (m_rim)
m_compose.add_rim(tile_colour::black);
+ if (m_texture)
+ m_compose.texture(*m_texture);
+
if (!m_back.empty())
{
const unsigned int pseudo_rand = m_page.m_tiles.size() * 54321;
@@ -415,6 +421,30 @@ bool tile_list_processor::process_line(char *read_line, const char *list_file,
m_compose.unload();
m_composing = false;
}
+ else if (strcmp(arg, "texture") == 0)
+ {
+ CHECK_ARG(1);
+
+ if (m_texture)
+ delete m_texture;
+
+ if (strcmp(m_args[1], "none") == 0)
+ {
+ CHECK_NO_ARG(2);
+ m_texture = 0;
+ return (true);
+ }
+
+ CHECK_NO_ARG(2);
+ tile *img = new tile();
+ if (!load_image(*img, m_args[1], true))
+ {
+ fprintf(stderr, "Error(%s:%d): couldn't load image "
+ "'%s'.\n", list_file, line, m_args[1]);
+ return (false);
+ }
+ m_texture = img;
+ }
else if (strcmp(arg, "include") == 0)
{
CHECK_ARG(1);
@@ -698,6 +728,9 @@ bool tile_list_processor::process_line(char *read_line, const char *list_file,
if (m_corpsify)
m_compose.corpsify();
+ if (m_texture)
+ m_compose.texture(*m_texture);
+
const unsigned int pseudo_rand = m_page.m_tiles.size() * 54321;
tile *back = m_back[pseudo_rand % m_back.size()];
img.copy(*back);
@@ -720,6 +753,9 @@ bool tile_list_processor::process_line(char *read_line, const char *list_file,
if (m_corpsify)
img.corpsify();
+
+ if (m_texture)
+ img.texture(*m_texture);
}
recolour(img);
diff --git a/crawl-ref/source/rltiles/tool/tile_list_processor.h b/crawl-ref/source/rltiles/tool/tile_list_processor.h
index 337c0a637a..3333186adb 100644
--- a/crawl-ref/source/rltiles/tool/tile_list_processor.h
+++ b/crawl-ref/source/rltiles/tool/tile_list_processor.h
@@ -46,6 +46,7 @@ protected:
std::vector<std::string> m_categories;
std::vector<int> m_ctg_counts;
tile m_compose;
+ tile* m_texture;
int m_variation_idx;
int m_variation_col;
int m_weight;