mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-05 11:28:17 -04:00
integrate egg-palettize with egg-mkfont
This commit is contained in:
parent
458d86dcbf
commit
5ae23c901b
@ -3,7 +3,7 @@
|
||||
#define USE_PACKAGES freetype
|
||||
|
||||
#define LOCAL_LIBS \
|
||||
eggbase progbase
|
||||
palettizer eggbase progbase
|
||||
#define OTHER_LIBS \
|
||||
pnmtext:c pnmimagetypes:c pnmimage:c \
|
||||
egg:c linmath:c putil:c express:c pandaegg:m panda:m pandaexpress:m \
|
||||
|
@ -18,6 +18,10 @@
|
||||
|
||||
#include "eggMakeFont.h"
|
||||
#include "rangeIterator.h"
|
||||
#include "palettizer.h"
|
||||
#include "eggFile.h"
|
||||
#include "textureImage.h"
|
||||
#include "sourceTextureImage.h"
|
||||
#include "pnmTextMaker.h"
|
||||
#include "pnmTextGlyph.h"
|
||||
#include "eggGroup.h"
|
||||
@ -43,25 +47,15 @@ EggMakeFont() : EggWriter(true, false) {
|
||||
"rendering text, even if FreeType is not compiled into "
|
||||
"the executing Panda.\n\n"
|
||||
|
||||
"It is strongly recommended that the resulting egg file "
|
||||
"be subsequently passed through egg-palettize to consolidate the many "
|
||||
"generated texture images into a single texture image to "
|
||||
"improve rendering performance. This can also reduce the "
|
||||
"texture images to achieve antialiasing.");
|
||||
"The generated egg file is normally run through egg-palettize "
|
||||
"automatically as part of the generation process, which collects "
|
||||
"the individual glyph textures into a small number of texture "
|
||||
"maps.");
|
||||
|
||||
clear_runlines();
|
||||
add_runline("[opts] -o output.egg font");
|
||||
add_runline("[opts] font output.egg");
|
||||
|
||||
add_option
|
||||
("i", "pattern", 0,
|
||||
"The pattern to be used to generate the texture images. This string "
|
||||
"will be passed to sprintf to generate the actual file name; it "
|
||||
"should contain the string %d or %x (or some variant such as %03d) "
|
||||
"which will be filled in with the Unicode number of each symbol. "
|
||||
"If it is omitted, the default is based on the name of the egg file.",
|
||||
&EggMakeFont::dispatch_string, NULL, &_output_image_pattern);
|
||||
|
||||
add_option
|
||||
("fg", "r,g,b[,a]", 0,
|
||||
"Specifies the foreground color of the generated texture map. The "
|
||||
@ -136,14 +130,7 @@ EggMakeFont() : EggWriter(true, false) {
|
||||
"or more fixed-size fonts instead of a scalable font, the scale factor "
|
||||
"may be automatically adjusted as necessary to scale the closest-"
|
||||
"matching font to the desired pixel size.",
|
||||
&EggMakeFont::dispatch_double, NULL, &_scale_factor);
|
||||
|
||||
add_option
|
||||
("nr", "", 0,
|
||||
"Don't actually reduce the images after applying the scale factor, but "
|
||||
"leave them at their inflated sizes. Presumably you will reduce "
|
||||
"them later, for instance with egg-palettize.",
|
||||
&EggMakeFont::dispatch_none, &_no_reduce);
|
||||
&EggMakeFont::dispatch_double, &_got_scale_factor, &_scale_factor);
|
||||
|
||||
add_option
|
||||
("noaa", "", 0,
|
||||
@ -153,6 +140,45 @@ EggMakeFont() : EggWriter(true, false) {
|
||||
"both kinds of antialiasing enabled.",
|
||||
&EggMakeFont::dispatch_none, &_no_native_aa);
|
||||
|
||||
add_option
|
||||
("nopal", "", 0,
|
||||
"Don't run egg-palettize automatically on the output file, but "
|
||||
"just output the raw egg file and all of its individual texture "
|
||||
"images, one for each glyph.",
|
||||
&EggMakeFont::dispatch_none, &_no_palettize);
|
||||
|
||||
add_option
|
||||
("nr", "", 0,
|
||||
"Don't actually reduce the images after applying the scale factor, but "
|
||||
"leave them at their inflated sizes. Presumably you will reduce "
|
||||
"them later, for instance with egg-palettize. This has no effect "
|
||||
"unless -nopal is specified.",
|
||||
&EggMakeFont::dispatch_none, &_no_reduce);
|
||||
|
||||
add_option
|
||||
("gp", "pattern", 0,
|
||||
"The pattern to be used to generate the glyph texture images. This "
|
||||
"string will be passed to sprintf to generate the actual file name; it "
|
||||
"should contain the string %d or %x (or some variant such as %03d) "
|
||||
"which will be filled in with the Unicode number of each symbol. "
|
||||
"If it is omitted, the default is based on the name of the egg file. "
|
||||
"This has no effect unless -nopal is specified.",
|
||||
&EggMakeFont::dispatch_string, NULL, &_output_glyph_pattern);
|
||||
|
||||
add_option
|
||||
("pp", "pattern", 0,
|
||||
"The pattern to be used to generate the palette texture images. This "
|
||||
"string is effectively passed to egg-palettize as the -tn option, and "
|
||||
"thus should contain %i for the palette index number. This is used "
|
||||
"if -nopal is not specified.",
|
||||
&EggMakeFont::dispatch_string, NULL, &_output_palette_pattern);
|
||||
|
||||
add_option
|
||||
("ps", "xsize,ysize", 0,
|
||||
"Specify the size of the palette texture images. This is used if "
|
||||
"-nopal is not specified.",
|
||||
&EggMakeFont::dispatch_int_pair, NULL, _palette_size);
|
||||
|
||||
add_option
|
||||
("face", "index", 0,
|
||||
"Specify the face index of the particular face within the font file "
|
||||
@ -162,12 +188,12 @@ EggMakeFont() : EggWriter(true, false) {
|
||||
|
||||
_fg.set(1.0, 1.0, 1.0, 1.0);
|
||||
_bg.set(1.0, 1.0, 1.0, 0.0);
|
||||
_interior.set(1.0, 1.0, 1.0, 0.0);
|
||||
_interior.set(1.0, 1.0, 1.0, 1.0);
|
||||
_pixels_per_unit = 30.0;
|
||||
_point_size = 10.0;
|
||||
_poly_margin = 1.0;
|
||||
_tex_margin = 2;
|
||||
_scale_factor = 2.0;
|
||||
_palette_size[0] = _palette_size[1] = 256;
|
||||
_face_index = 0;
|
||||
|
||||
_text_maker = NULL;
|
||||
@ -208,15 +234,46 @@ run() {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (_no_reduce) {
|
||||
if (_got_interior) {
|
||||
_no_native_aa = true;
|
||||
}
|
||||
|
||||
if (!_got_scale_factor) {
|
||||
// The default scale factor is 4 if we are not using FreeType's
|
||||
// antialias, or 2 if we are.
|
||||
if (_no_native_aa) {
|
||||
_scale_factor = 4.0;
|
||||
} else {
|
||||
_scale_factor = 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
_palettize_scale_factor = _scale_factor;
|
||||
if (_no_reduce || !_no_palettize) {
|
||||
// If _no_reduce is true (-nr was specified), we want to keep the
|
||||
// glyph textures full-sized, because the user asked for that.
|
||||
|
||||
// If _no_palettize is false (-nopal was not specified), we still
|
||||
// want to keep the glyph textures full-sized, because the
|
||||
// palettizer will reduce them later.
|
||||
|
||||
_tex_margin *= _scale_factor;
|
||||
_poly_margin *= _scale_factor;
|
||||
_pixels_per_unit *= _scale_factor;
|
||||
_scale_factor = 1.0;
|
||||
}
|
||||
|
||||
if (_no_reduce) {
|
||||
// If -nr was specified, but we're still palettizing, we don't
|
||||
// even want to reduce the palette images. Instead, we'll
|
||||
// generate extra-large palette images.
|
||||
_palette_size[0] *= _palettize_scale_factor;
|
||||
_palette_size[1] *= _palettize_scale_factor;
|
||||
_palettize_scale_factor = 1.0;
|
||||
}
|
||||
|
||||
_text_maker->set_point_size(_point_size);
|
||||
_text_maker->set_native_antialias(!_no_native_aa && !_got_interior);
|
||||
_text_maker->set_native_antialias(!_no_native_aa);
|
||||
_text_maker->set_interior_flag(_got_interior);
|
||||
_text_maker->set_pixels_per_unit(_pixels_per_unit);
|
||||
_text_maker->set_scale_factor(_scale_factor);
|
||||
@ -226,9 +283,13 @@ run() {
|
||||
// set.
|
||||
_range.add_range(0x20, 0x7e);
|
||||
}
|
||||
if (_output_image_pattern.empty()) {
|
||||
if (_output_glyph_pattern.empty()) {
|
||||
// Create a default texture filename pattern.
|
||||
_output_image_pattern = get_output_filename().get_fullpath_wo_extension() + "%03d.rgb";
|
||||
_output_glyph_pattern = get_output_filename().get_fullpath_wo_extension() + "%03d.rgb";
|
||||
}
|
||||
if (_output_palette_pattern.empty()) {
|
||||
// Create a default texture filename pattern.
|
||||
_output_palette_pattern = get_output_filename().get_fullpath_wo_extension() + "_%i.rgb";
|
||||
}
|
||||
|
||||
// Figure out how many channels we need based on the foreground and
|
||||
@ -249,6 +310,7 @@ run() {
|
||||
// one-channel image.
|
||||
_fg[0] = _fg[1] = _fg[2] = _fg[3];
|
||||
_bg[0] = _bg[1] = _bg[2] = _bg[3];
|
||||
_interior[0] = _interior[1] = _interior[2] = _interior[3];
|
||||
_num_channels = 1;
|
||||
_format = EggTexture::F_alpha;
|
||||
} else {
|
||||
@ -266,6 +328,28 @@ run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Create a global Palettizer object. We'll use this even if the
|
||||
// user specified -nopal, if nothing else just to hold all of the
|
||||
// TextureImage pointers.
|
||||
pal = new Palettizer;
|
||||
pal->_generated_image_pattern = _output_palette_pattern;
|
||||
pal->_omit_solitary = true;
|
||||
pal->_round_uvs = false;
|
||||
|
||||
// Generate a txa script for the palettizer. We have the palettizer
|
||||
// reduce all of the texture images by the inverse of our scale
|
||||
// factor.
|
||||
char buffer[1024];
|
||||
sprintf(buffer, ":margin 0;:background %f %f %f %f;:palette %d %d;*: %f%% keep-format",
|
||||
_bg[0], _bg[1], _bg[2], _bg[3],
|
||||
_palette_size[0], _palette_size[1],
|
||||
100.0 / _palettize_scale_factor);
|
||||
istringstream txa_script(buffer);
|
||||
pal->read_txa_file(txa_script, "default script");
|
||||
|
||||
pal->all_params_set();
|
||||
|
||||
// Now create all the egg structures.
|
||||
_group = new EggGroup();
|
||||
_data.add_child(_group);
|
||||
|
||||
@ -291,7 +375,33 @@ run() {
|
||||
add_character(ri.get_code());
|
||||
} while (ri.next());
|
||||
|
||||
write_egg_file();
|
||||
if (_no_palettize) {
|
||||
// Ok, no palettize step; just write out the egg file and all of
|
||||
// the textures.
|
||||
Textures::iterator ti;
|
||||
for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
|
||||
TextureImage *texture = (*ti);
|
||||
texture->write(texture->read_source_image());
|
||||
}
|
||||
|
||||
write_egg_file();
|
||||
|
||||
} else {
|
||||
// Pass the generated egg structure through egg-palettize, without
|
||||
// writing it to disk first.
|
||||
string name = get_output_filename().get_basename();
|
||||
EggFile *egg_file = pal->get_egg_file(name);
|
||||
egg_file->from_command_line(&_data, "", get_output_filename(),
|
||||
get_exec_command());
|
||||
|
||||
pal->add_command_line_egg(egg_file);
|
||||
pal->process_all(true, "");
|
||||
pal->optimal_resize();
|
||||
pal->generate_images(true);
|
||||
if (!pal->write_eggs()) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -427,13 +537,13 @@ get_tref(PNMTextGlyph *glyph, int character) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggMakeFont::make_tref
|
||||
// Access: Private
|
||||
// Description: Writes out the texture image for an indicated glyph,
|
||||
// Description: Generates a texture image for the indicated glyph,
|
||||
// and returns its egg reference.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
EggTexture *EggMakeFont::
|
||||
make_tref(PNMTextGlyph *glyph, int character) {
|
||||
char buffer[1024];
|
||||
sprintf(buffer, _output_image_pattern.c_str(), character);
|
||||
sprintf(buffer, _output_glyph_pattern.c_str(), character);
|
||||
|
||||
Filename texture_filename = buffer;
|
||||
PNMImage image(glyph->get_width() + _tex_margin * 2,
|
||||
@ -450,13 +560,20 @@ make_tref(PNMTextGlyph *glyph, int character) {
|
||||
glyph->get_top() + _tex_margin, _fg);
|
||||
}
|
||||
|
||||
if (!image.write(texture_filename)) {
|
||||
nout << "Unable to write " << texture_filename << "\n";
|
||||
}
|
||||
// We don't write the image to disk immediately, since it might just
|
||||
// get palettized. But we do record it in a TextureImage object
|
||||
// within the global Palettizer, so that it may be written out
|
||||
// later.
|
||||
|
||||
EggTexture *tref =
|
||||
new EggTexture(texture_filename.get_basename_wo_extension(),
|
||||
texture_filename);
|
||||
string name = texture_filename.get_basename_wo_extension();
|
||||
TextureImage *texture = pal->get_texture(name);
|
||||
_textures.push_back(texture);
|
||||
texture->set_filename("", texture_filename);
|
||||
SourceTextureImage *source = texture->get_source(texture_filename, "", 0);
|
||||
texture->set_source_image(image);
|
||||
source->set_header(image);
|
||||
|
||||
EggTexture *tref = new EggTexture(name, texture_filename);
|
||||
tref->set_format(_format);
|
||||
tref->set_wrap_mode(EggTexture::WM_clamp);
|
||||
tref->set_minfilter(EggTexture::FT_linear_mipmap_linear);
|
||||
|
@ -25,11 +25,13 @@
|
||||
#include "eggWriter.h"
|
||||
#include "eggTexture.h"
|
||||
#include "pmap.h"
|
||||
#include "pvector.h"
|
||||
|
||||
class PNMTextMaker;
|
||||
class PNMTextGlyph;
|
||||
class EggVertexPool;
|
||||
class EggGroup;
|
||||
class TextureImage;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : EggMakeFont
|
||||
@ -67,13 +69,18 @@ private:
|
||||
double _point_size;
|
||||
double _poly_margin;
|
||||
int _tex_margin;
|
||||
bool _got_scale_factor;
|
||||
double _scale_factor;
|
||||
bool _no_reduce;
|
||||
bool _no_native_aa;
|
||||
bool _no_palettize;
|
||||
int _palette_size[2];
|
||||
|
||||
double _palettize_scale_factor;
|
||||
Filename _input_font_filename;
|
||||
int _face_index;
|
||||
string _output_image_pattern;
|
||||
string _output_glyph_pattern;
|
||||
string _output_palette_pattern;
|
||||
|
||||
PNMTextMaker *_text_maker;
|
||||
|
||||
@ -84,6 +91,9 @@ private:
|
||||
|
||||
typedef pmap<PNMTextGlyph *, EggTexture *> TRefs;
|
||||
TRefs _trefs;
|
||||
|
||||
typedef pvector<TextureImage *> Textures;
|
||||
Textures _textures;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#begin bin_target
|
||||
#define TARGET egg-palettize
|
||||
#define LOCAL_LIBS \
|
||||
eggbase progbase
|
||||
palettizer eggbase progbase
|
||||
#define OTHER_LIBS \
|
||||
egg:c pgraph:c linmath:c putil:c express:c pnmimage:c pnmimagetypes:c \
|
||||
event:c mathutil:c \
|
||||
@ -9,30 +9,8 @@
|
||||
dtoolutil:c dtoolbase:c dconfig:c dtoolconfig:m dtool:m pystub
|
||||
#define UNIX_SYS_LIBS m
|
||||
|
||||
#define COMBINED_SOURCES $[TARGET]_composite1.cxx
|
||||
|
||||
#define SOURCES \
|
||||
config_egg_palettize.h destTextureImage.h eggFile.h \
|
||||
eggPalettize.h filenameUnifier.h imageFile.h omitReason.h \
|
||||
pal_string_utils.h paletteGroup.h \
|
||||
paletteGroups.h paletteImage.h \
|
||||
palettePage.h palettizer.h sourceTextureImage.h \
|
||||
textureImage.h textureMemoryCounter.h texturePlacement.h \
|
||||
texturePosition.h textureProperties.h \
|
||||
textureReference.h textureRequest.h \
|
||||
txaFile.h txaLine.h
|
||||
|
||||
#define INCLUDED_SOURCES \
|
||||
config_egg_palettize.cxx destTextureImage.cxx eggFile.cxx \
|
||||
eggPalettize.cxx filenameUnifier.cxx imageFile.cxx \
|
||||
omitReason.cxx pal_string_utils.cxx paletteGroup.cxx \
|
||||
paletteGroups.cxx paletteImage.cxx palettePage.cxx \
|
||||
palettizer.cxx sourceTextureImage.cxx textureImage.cxx \
|
||||
textureMemoryCounter.cxx texturePlacement.cxx \
|
||||
texturePosition.cxx textureProperties.cxx \
|
||||
textureReference.cxx textureRequest.cxx txaFile.cxx \
|
||||
txaLine.cxx
|
||||
|
||||
eggPalettize.h eggPalettize.cxx
|
||||
|
||||
#end bin_target
|
||||
|
||||
|
@ -192,7 +192,7 @@ EggPalettize() : EggMultiFilter(true) {
|
||||
"may invalidate other egg files which share this palette.",
|
||||
&EggPalettize::dispatch_none, &_optimal);
|
||||
|
||||
// This isn't even implement yet. Presently, we never lock anyway.
|
||||
// This isn't even implemented yet. Presently, we never lock anyway.
|
||||
// Dangerous, but hard to implement reliable file locking across
|
||||
// NFS/Samba and between multiple OS's.
|
||||
/*
|
||||
@ -322,6 +322,11 @@ describe_input_file() {
|
||||
"match the number of channels. As above, any valid egg texture "
|
||||
"format may be used, e.g. force-rgba12, force-rgb5, etc.\n\n");
|
||||
|
||||
show_text(" keep-format", 10,
|
||||
"This specifies that the image format requested by an egg file "
|
||||
"should be exactly preserved, without attempting to optimize "
|
||||
"it by, for instance, automatically downgrading.\n\n");
|
||||
|
||||
show_text(" generic", 10,
|
||||
"Specifies that any image format requested by an egg file "
|
||||
"that requests a particular bitdepth should be replaced by "
|
||||
@ -391,6 +396,12 @@ describe_input_file() {
|
||||
"neighboring images within the same palette. The default "
|
||||
"is 2.\n\n");
|
||||
|
||||
show_text(" :background r g b a", 10,
|
||||
"Specifies the background color of the generated palette "
|
||||
"images. Normally, this is black, and it doesn't matter much "
|
||||
"since the background color is, by definition, the color "
|
||||
"of the palette images where nothing is used.\n\n");
|
||||
|
||||
show_text(" :coverage area", 10,
|
||||
"The 'coverage' of a texture refers to the fraction of "
|
||||
"the area in the texture image that is actually used, according "
|
||||
@ -715,7 +726,7 @@ run() {
|
||||
egg_file->from_command_line(egg_data, source_filename, dest_filename,
|
||||
egg_comment);
|
||||
|
||||
pal->_command_line_eggs.push_back(egg_file);
|
||||
pal->add_command_line_egg(egg_file);
|
||||
}
|
||||
|
||||
if (_optimal) {
|
||||
|
33
pandatool/src/palettizer/Sources.pp
Normal file
33
pandatool/src/palettizer/Sources.pp
Normal file
@ -0,0 +1,33 @@
|
||||
#begin ss_lib_target
|
||||
#define TARGET palettizer
|
||||
#define OTHER_LIBS \
|
||||
egg:c pgraph:c linmath:c putil:c express:c pnmimage:c pnmimagetypes:c \
|
||||
event:c mathutil:c \
|
||||
pandaegg:m panda:m pandaexpress:m \
|
||||
dtoolutil:c dtoolbase:c dconfig:c dtoolconfig:m dtool:m
|
||||
|
||||
#define COMBINED_SOURCES $[TARGET]_composite1.cxx
|
||||
|
||||
#define SOURCES \
|
||||
config_palettizer.h destTextureImage.h eggFile.h \
|
||||
filenameUnifier.h imageFile.h omitReason.h \
|
||||
pal_string_utils.h paletteGroup.h \
|
||||
paletteGroups.h paletteImage.h \
|
||||
palettePage.h palettizer.h sourceTextureImage.h \
|
||||
textureImage.h textureMemoryCounter.h texturePlacement.h \
|
||||
texturePosition.h textureProperties.h \
|
||||
textureReference.h textureRequest.h \
|
||||
txaFile.h txaLine.h
|
||||
|
||||
#define INCLUDED_SOURCES \
|
||||
config_palettizer.cxx destTextureImage.cxx eggFile.cxx \
|
||||
filenameUnifier.cxx imageFile.cxx \
|
||||
omitReason.cxx pal_string_utils.cxx paletteGroup.cxx \
|
||||
paletteGroups.cxx paletteImage.cxx palettePage.cxx \
|
||||
palettizer.cxx sourceTextureImage.cxx textureImage.cxx \
|
||||
textureMemoryCounter.cxx texturePlacement.cxx \
|
||||
texturePosition.cxx textureProperties.cxx \
|
||||
textureReference.cxx textureRequest.cxx txaFile.cxx \
|
||||
txaLine.cxx
|
||||
|
||||
#end ss_lib_target
|
@ -1,5 +1,5 @@
|
||||
// Filename: config_egg_palettize.cxx
|
||||
// Created by: drose (01Dec00)
|
||||
// Filename: config_palettizer.cxx
|
||||
// Created by: drose (12Sep03)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -16,7 +16,7 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "config_egg_palettize.h"
|
||||
#include "config_palettizer.h"
|
||||
#include "palettizer.h"
|
||||
#include "eggFile.h"
|
||||
#include "paletteGroup.h"
|
||||
@ -34,14 +34,14 @@
|
||||
|
||||
#include "dconfig.h"
|
||||
|
||||
Configure(config_egg_palettize);
|
||||
Configure(config_palettizer);
|
||||
|
||||
ConfigureFn(config_egg_palettize) {
|
||||
init_egg_palettize();
|
||||
ConfigureFn(config_palettizer) {
|
||||
init_palettizer();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: init_libegg_palettize
|
||||
// Function: init_libpalettizer
|
||||
// Description: Initializes the library. This must be called at
|
||||
// least once before any of the functions or classes in
|
||||
// this library can be used. Normally it will be
|
||||
@ -49,7 +49,7 @@ ConfigureFn(config_egg_palettize) {
|
||||
// called explicitly, but special cases exist.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
init_egg_palettize() {
|
||||
init_palettizer() {
|
||||
static bool initialized = false;
|
||||
if (initialized) {
|
||||
return;
|
@ -1,5 +1,5 @@
|
||||
// Filename: config_egg_palettize.h
|
||||
// Created by: drose (01Dec00)
|
||||
// Filename: config_palettizer.h
|
||||
// Created by: drose (12Sep03)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -16,11 +16,11 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef CONFIG_EGG_PALETTIZE_H
|
||||
#define CONFIG_EGG_PALETTIZE_H
|
||||
#ifndef CONFIG_PALETTIZER_H
|
||||
#define CONFIG_PALETTIZER_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
|
||||
void init_egg_palettize();
|
||||
void init_palettizer();
|
||||
|
||||
#endif /* __CONFIG_UTIL_H__ */
|
@ -25,11 +25,11 @@
|
||||
#include "sourceTextureImage.h"
|
||||
#include "filenameUnifier.h"
|
||||
|
||||
#include <indent.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
#include <bamReader.h>
|
||||
#include <bamWriter.h>
|
||||
#include "indent.h"
|
||||
#include "datagram.h"
|
||||
#include "datagramIterator.h"
|
||||
#include "bamReader.h"
|
||||
#include "bamWriter.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -96,15 +96,18 @@ operator = (const PaletteImage::ClearedRegion ©) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PaletteImage::ClearedRegion::
|
||||
clear(PNMImage &image) {
|
||||
RGBColord rgb(pal->_background[0], pal->_background[1], pal->_background[2]);
|
||||
double alpha = pal->_background[3];
|
||||
|
||||
for (int y = _y; y < _y + _y_size; y++) {
|
||||
for (int x = _x; x < _x + _x_size; x++) {
|
||||
image.set_xel_val(x, y, 0);
|
||||
image.set_xel(x, y, rgb);
|
||||
}
|
||||
}
|
||||
if (image.has_alpha()) {
|
||||
for (int y = _y; y < _y + _y_size; y++) {
|
||||
for (int x = _x; x < _x + _x_size; x++) {
|
||||
image.set_alpha_val(x, y, 0);
|
||||
image.set_alpha(x, y, alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,7 +219,7 @@ PaletteImage(PalettePage *page, int index) :
|
||||
// to have a filename extension. Otherwise, an embedded dot in the
|
||||
// group's name would make everything following appear to be an
|
||||
// extension, which would get lost in the set_filename() call.
|
||||
if (_basename.empty() || _basename[_basename.length() - 1] != '.') {
|
||||
if (_basename.find('.') == string::npos) {
|
||||
_basename += '.';
|
||||
}
|
||||
|
||||
@ -752,6 +755,11 @@ get_image() {
|
||||
_cleared_regions.clear();
|
||||
|
||||
_image.clear(get_x_size(), get_y_size(), _properties.get_num_channels());
|
||||
_image.fill(pal->_background[0], pal->_background[1], pal->_background[2]);
|
||||
if (_image.has_alpha()) {
|
||||
_image.alpha_fill(pal->_background[3]);
|
||||
}
|
||||
|
||||
_new_image = false;
|
||||
_got_image = true;
|
||||
|
@ -19,11 +19,11 @@
|
||||
#ifndef PALETTEIMAGE_H
|
||||
#define PALETTEIMAGE_H
|
||||
|
||||
#include <pandatoolbase.h>
|
||||
#include "pandatoolbase.h"
|
||||
|
||||
#include "imageFile.h"
|
||||
|
||||
#include <pnmImage.h>
|
||||
#include "pnmImage.h"
|
||||
|
||||
class PalettePage;
|
||||
class TexturePlacement;
|
@ -41,12 +41,13 @@ Palettizer *pal = (Palettizer *)NULL;
|
||||
// allows us to easily update egg-palettize to write out additional
|
||||
// information to its pi file, without having it increment the bam
|
||||
// version number for all bam and boo files anywhere in the world.
|
||||
int Palettizer::_pi_version = 12;
|
||||
int Palettizer::_pi_version = 13;
|
||||
// Updated to version 8 on 3/20/03 to remove extensions from texture key names.
|
||||
// Updated to version 9 on 4/13/03 to add a few properties in various places.
|
||||
// Updated to version 10 on 4/15/03 to add _alpha_file_channel.
|
||||
// Updated to version 11 on 4/30/03 to add TextureReference::_tref_name.
|
||||
// Updated to version 12 on 9/11/03 to add _generated_image_pattern.
|
||||
// Updated to version 13 on 9/13/03 to add _keep_format and _background.
|
||||
|
||||
int Palettizer::_min_pi_version = 8;
|
||||
// Dropped support for versions 7 and below on 7/14/03.
|
||||
@ -113,6 +114,7 @@ Palettizer() {
|
||||
_shadow_color_type = (PNMFileType *)NULL;
|
||||
_shadow_alpha_type = (PNMFileType *)NULL;
|
||||
_pal_x_size = _pal_y_size = 512;
|
||||
_background.set(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
_round_uvs = true;
|
||||
_round_unit = 0.1;
|
||||
@ -146,6 +148,7 @@ report_pi() const {
|
||||
<< " egg relative directory: "
|
||||
<< FilenameUnifier::make_user_filename(_rel_dirname) << "\n"
|
||||
<< " palettize size: " << _pal_x_size << " by " << _pal_y_size << "\n"
|
||||
<< " background: " << _background << "\n"
|
||||
<< " margin: " << _margin << "\n"
|
||||
<< " coverage threshold: " << _coverage_threshold << "\n"
|
||||
<< " force textures to power of 2: " << yesno(_force_power_2) << "\n"
|
||||
@ -732,6 +735,19 @@ remove_egg_file(const string &name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Palettizer::add_command_line_egg
|
||||
// Access: Public
|
||||
// Description: Adds the indicated EggFile to the list of eggs that
|
||||
// are considered to have been read on the command line.
|
||||
// These will be processed by
|
||||
// process_command_line_eggs().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void Palettizer::
|
||||
add_command_line_egg(EggFile *egg_file) {
|
||||
_command_line_eggs.push_back(egg_file);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Palettizer::get_palette_group
|
||||
// Access: Public
|
||||
@ -804,6 +820,7 @@ get_texture(const string &name) {
|
||||
image->set_name(name);
|
||||
// image->set_filename(name);
|
||||
_textures.insert(Textures::value_type(name, image));
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -892,6 +909,10 @@ write_datagram(BamWriter *writer, Datagram &datagram) {
|
||||
datagram.add_string(FilenameUnifier::make_bam_filename(_rel_dirname));
|
||||
datagram.add_int32(_pal_x_size);
|
||||
datagram.add_int32(_pal_y_size);
|
||||
datagram.add_float64(_background[0]);
|
||||
datagram.add_float64(_background[1]);
|
||||
datagram.add_float64(_background[2]);
|
||||
datagram.add_float64(_background[3]);
|
||||
datagram.add_int32(_margin);
|
||||
datagram.add_bool(_omit_solitary);
|
||||
datagram.add_float64(_coverage_threshold);
|
||||
@ -1029,6 +1050,12 @@ fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
FilenameUnifier::set_rel_dirname(_rel_dirname);
|
||||
_pal_x_size = scan.get_int32();
|
||||
_pal_y_size = scan.get_int32();
|
||||
if (_read_pi_version >= 13) {
|
||||
_background[0] = scan.get_float64();
|
||||
_background[1] = scan.get_float64();
|
||||
_background[2] = scan.get_float64();
|
||||
_background[3] = scan.get_float64();
|
||||
}
|
||||
_margin = scan.get_int32();
|
||||
_omit_solitary = scan.get_bool();
|
||||
_coverage_threshold = scan.get_float64();
|
@ -64,6 +64,8 @@ public:
|
||||
EggFile *get_egg_file(const string &name);
|
||||
bool remove_egg_file(const string &name);
|
||||
|
||||
void add_command_line_egg(EggFile *egg_file);
|
||||
|
||||
PaletteGroup *get_palette_group(const string &name);
|
||||
PaletteGroup *test_palette_group(const string &name) const;
|
||||
PaletteGroup *get_default_group();
|
||||
@ -100,6 +102,7 @@ public:
|
||||
Filename _shadow_dirname;
|
||||
Filename _rel_dirname;
|
||||
int _pal_x_size, _pal_y_size;
|
||||
Colord _background;
|
||||
int _margin;
|
||||
bool _omit_solitary;
|
||||
double _coverage_threshold;
|
||||
@ -169,10 +172,13 @@ public:
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
|
||||
friend class EggPalettize;
|
||||
friend class TxaLine;
|
||||
};
|
||||
|
||||
// This is a global Palettizer pointer that may be filled in when the
|
||||
// Palettizer is created, for convenience in referencing it from
|
||||
// multiple places. (Generally, a standalone program will only create
|
||||
// one Palettizer object in a session.)
|
||||
extern Palettizer *pal;
|
||||
|
||||
#endif
|
@ -1,25 +1,24 @@
|
||||
|
||||
#include "config_egg_palettize.cxx"
|
||||
#include "destTextureImage.cxx"
|
||||
#include "eggFile.cxx"
|
||||
#include "eggPalettize.cxx"
|
||||
#include "filenameUnifier.cxx"
|
||||
#include "imageFile.cxx"
|
||||
#include "omitReason.cxx"
|
||||
#include "pal_string_utils.cxx"
|
||||
#include "paletteGroup.cxx"
|
||||
#include "paletteGroups.cxx"
|
||||
#include "paletteImage.cxx"
|
||||
#include "palettePage.cxx"
|
||||
#include "palettizer.cxx"
|
||||
#include "sourceTextureImage.cxx"
|
||||
#include "textureImage.cxx"
|
||||
#include "textureMemoryCounter.cxx"
|
||||
#include "texturePlacement.cxx"
|
||||
#include "texturePosition.cxx"
|
||||
#include "textureProperties.cxx"
|
||||
#include "textureReference.cxx"
|
||||
#include "textureRequest.cxx"
|
||||
#include "txaFile.cxx"
|
||||
#include "txaLine.cxx"
|
||||
|
||||
|
||||
#include "config_palettizer.cxx"
|
||||
#include "destTextureImage.cxx"
|
||||
#include "eggFile.cxx"
|
||||
#include "filenameUnifier.cxx"
|
||||
#include "imageFile.cxx"
|
||||
#include "omitReason.cxx"
|
||||
#include "pal_string_utils.cxx"
|
||||
#include "paletteGroup.cxx"
|
||||
#include "paletteGroups.cxx"
|
||||
#include "paletteImage.cxx"
|
||||
#include "palettePage.cxx"
|
||||
#include "palettizer.cxx"
|
||||
#include "sourceTextureImage.cxx"
|
||||
#include "textureImage.cxx"
|
||||
#include "textureMemoryCounter.cxx"
|
||||
#include "texturePlacement.cxx"
|
||||
#include "texturePosition.cxx"
|
||||
#include "textureProperties.cxx"
|
||||
#include "textureReference.cxx"
|
||||
#include "textureRequest.cxx"
|
||||
#include "txaFile.cxx"
|
||||
#include "txaLine.cxx"
|
||||
|
@ -140,6 +140,19 @@ read_header() {
|
||||
return false;
|
||||
}
|
||||
|
||||
set_header(header);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: SourceTextureImage::set_header
|
||||
// Access: Public
|
||||
// Description: Sets the header information associated with this
|
||||
// image, as if it were loaded from the disk.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void SourceTextureImage::
|
||||
set_header(const PNMImageHeader &header) {
|
||||
_x_size = header.get_x_size();
|
||||
_y_size = header.get_y_size();
|
||||
int num_channels = header.get_num_channels();
|
||||
@ -155,8 +168,6 @@ read_header() {
|
||||
|
||||
_size_known = true;
|
||||
_successfully_read_header = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "imageFile.h"
|
||||
|
||||
class TextureImage;
|
||||
class PNMImageHeader;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : SourceTextureImage
|
||||
@ -45,6 +46,7 @@ public:
|
||||
|
||||
bool get_size();
|
||||
bool read_header();
|
||||
void set_header(const PNMImageHeader &header);
|
||||
|
||||
private:
|
||||
TextureImage *_texture;
|
@ -331,7 +331,7 @@ post_txa_file() {
|
||||
_y_size = _request._y_size;
|
||||
}
|
||||
|
||||
if (_properties.has_num_channels()) {
|
||||
if (_properties.has_num_channels() && !_request._keep_format) {
|
||||
int num_channels = _properties.get_num_channels();
|
||||
// Examine the image to determine if we can downgrade the number
|
||||
// of channels, for instance from color to grayscale.
|
||||
@ -352,11 +352,13 @@ post_txa_file() {
|
||||
}
|
||||
|
||||
_properties._generic_format = _request._generic_format;
|
||||
_properties._keep_format = _request._keep_format;
|
||||
|
||||
if (_request._format != EggTexture::F_unspecified) {
|
||||
_properties._format = _request._format;
|
||||
_properties._force_format = _request._force_format;
|
||||
}
|
||||
|
||||
if (_request._minfilter != EggTexture::FT_unspecified) {
|
||||
_properties._minfilter = _request._minfilter;
|
||||
}
|
||||
@ -750,6 +752,21 @@ read_source_image() {
|
||||
return _source_image;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextureImage::set_source_image
|
||||
// Access: Public
|
||||
// Description: Accepts the indicated source image as if it had been
|
||||
// read from disk. This image is copied into the
|
||||
// structure, and will be returned by future calls to
|
||||
// read_source_image().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void TextureImage::
|
||||
set_source_image(const PNMImage &image) {
|
||||
_source_image = image;
|
||||
_read_source_image = true;
|
||||
_ever_read_image = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextureImage::read_header
|
||||
// Access: Public
|
@ -89,6 +89,7 @@ public:
|
||||
void copy_unplaced(bool redo_all);
|
||||
|
||||
const PNMImage &read_source_image();
|
||||
void set_source_image(const PNMImage &image);
|
||||
void read_header();
|
||||
bool is_newer_than(const Filename &reference_filename);
|
||||
|
@ -39,6 +39,7 @@ TextureProperties() {
|
||||
_format = EggTexture::F_unspecified;
|
||||
_force_format = false;
|
||||
_generic_format = false;
|
||||
_keep_format = false;
|
||||
_minfilter = EggTexture::FT_unspecified;
|
||||
_magfilter = EggTexture::FT_unspecified;
|
||||
_anisotropic_degree = 0;
|
||||
@ -56,6 +57,7 @@ TextureProperties(const TextureProperties ©) :
|
||||
_format(copy._format),
|
||||
_force_format(copy._force_format),
|
||||
_generic_format(copy._generic_format),
|
||||
_keep_format(copy._keep_format),
|
||||
_minfilter(copy._minfilter),
|
||||
_magfilter(copy._magfilter),
|
||||
_anisotropic_degree(copy._anisotropic_degree),
|
||||
@ -76,6 +78,7 @@ void TextureProperties::
|
||||
operator = (const TextureProperties ©) {
|
||||
_force_format = copy._force_format;
|
||||
_generic_format = copy._generic_format;
|
||||
_keep_format = copy._keep_format;
|
||||
_minfilter = copy._minfilter;
|
||||
_magfilter = copy._magfilter;
|
||||
_anisotropic_degree = copy._anisotropic_degree;
|
||||
@ -336,7 +339,7 @@ fully_define() {
|
||||
|
||||
// Make sure the format reflects the number of channels, although we
|
||||
// accept a format that ignores an alpha channel.
|
||||
if (!_force_format) {
|
||||
if (!_force_format && !_keep_format) {
|
||||
switch (_num_channels) {
|
||||
case 1:
|
||||
switch (_format) {
|
||||
@ -783,6 +786,7 @@ write_datagram(BamWriter *writer, Datagram &datagram) {
|
||||
datagram.add_int32((int)_format);
|
||||
datagram.add_bool(_force_format);
|
||||
datagram.add_bool(_generic_format);
|
||||
datagram.add_bool(_keep_format);
|
||||
datagram.add_int32((int)_minfilter);
|
||||
datagram.add_int32((int)_magfilter);
|
||||
datagram.add_int32(_anisotropic_degree);
|
||||
@ -857,6 +861,10 @@ fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
if (Palettizer::_read_pi_version >= 9) {
|
||||
_generic_format = scan.get_bool();
|
||||
}
|
||||
_keep_format = false;
|
||||
if (Palettizer::_read_pi_version >= 13) {
|
||||
_keep_format = scan.get_bool();
|
||||
}
|
||||
_minfilter = (EggTexture::FilterType)scan.get_int32();
|
||||
_magfilter = (EggTexture::FilterType)scan.get_int32();
|
||||
_anisotropic_degree = scan.get_int32();
|
@ -64,6 +64,7 @@ public:
|
||||
EggTexture::Format _format;
|
||||
bool _force_format; // true when format has been explicitly specified
|
||||
bool _generic_format; // true if 'generic' keyword, meaning rgba8 -> rgba.
|
||||
bool _keep_format; // true if 'keep-format' keyword.
|
||||
EggTexture::FilterType _minfilter, _magfilter;
|
||||
int _anisotropic_degree;
|
||||
PNMFileType *_color_type;
|
@ -34,6 +34,7 @@ TextureRequest() {
|
||||
_format = EggTexture::F_unspecified;
|
||||
_force_format = false;
|
||||
_generic_format = false;
|
||||
_keep_format = false;
|
||||
_minfilter = EggTexture::FT_unspecified;
|
||||
_magfilter = EggTexture::FT_unspecified;
|
||||
_anisotropic_degree = 0;
|
@ -47,6 +47,7 @@ public:
|
||||
EggTexture::Format _format;
|
||||
bool _force_format;
|
||||
bool _generic_format;
|
||||
bool _keep_format;
|
||||
EggTexture::FilterType _minfilter;
|
||||
EggTexture::FilterType _magfilter;
|
||||
int _anisotropic_degree;
|
@ -71,6 +71,9 @@ read(istream &in, const string &filename) {
|
||||
} else if (words[0] == ":margin") {
|
||||
okflag = parse_margin_line(words);
|
||||
|
||||
} else if (words[0] == ":background") {
|
||||
okflag = parse_background_line(words);
|
||||
|
||||
} else if (words[0] == ":coverage") {
|
||||
okflag = parse_coverage_line(words);
|
||||
|
||||
@ -307,6 +310,34 @@ parse_margin_line(const vector_string &words) {
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TxaFile::parse_background_line
|
||||
// Access: Private
|
||||
// Description: Handles the line in a .txa file that begins with the
|
||||
// keyword ":background" and indicates the palette
|
||||
// background color.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool TxaFile::
|
||||
parse_background_line(const vector_string &words) {
|
||||
if (words.size() != 5) {
|
||||
nout << "Exactly four parameter required for :background: the "
|
||||
<< "four [r g b a] components of the background color.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string_to_double(words[1], pal->_background[0]) ||
|
||||
!string_to_double(words[2], pal->_background[1]) ||
|
||||
!string_to_double(words[3], pal->_background[2]) ||
|
||||
!string_to_double(words[4], pal->_background[3])) {
|
||||
nout << "Invalid color: "
|
||||
<< words[1] << " " << words[2] << " "
|
||||
<< words[3] << " " << words[4] << " " << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TxaFile::parse_coverage_line
|
||||
// Access: Private
|
@ -51,6 +51,7 @@ private:
|
||||
bool parse_group_line(const vector_string &words);
|
||||
bool parse_palette_line(const vector_string &words);
|
||||
bool parse_margin_line(const vector_string &words);
|
||||
bool parse_background_line(const vector_string &words);
|
||||
bool parse_coverage_line(const vector_string &words);
|
||||
bool parse_imagetype_line(const vector_string &words);
|
||||
bool parse_shadowtype_line(const vector_string &words);
|
@ -43,6 +43,7 @@ TxaLine() {
|
||||
_format = EggTexture::F_unspecified;
|
||||
_force_format = false;
|
||||
_generic_format = false;
|
||||
_keep_format = false;
|
||||
_alpha_mode = EggRenderMode::AM_unspecified;
|
||||
_got_margin = false;
|
||||
_margin = 0;
|
||||
@ -255,6 +256,10 @@ parse(const string &line) {
|
||||
// rgba.
|
||||
_generic_format = true;
|
||||
|
||||
} else if (word == "keep-format") {
|
||||
// Keep whatever image format was specified.
|
||||
_keep_format = true;
|
||||
|
||||
} else {
|
||||
// Maybe it's a group name.
|
||||
PaletteGroup *group = pal->test_palette_group(word);
|
||||
@ -435,6 +440,10 @@ match_texture(TextureImage *texture) const {
|
||||
request._generic_format = true;
|
||||
}
|
||||
|
||||
if (_keep_format) {
|
||||
request._keep_format = true;
|
||||
}
|
||||
|
||||
if (_alpha_mode != EggRenderMode::AM_unspecified) {
|
||||
request._alpha_mode = _alpha_mode;
|
||||
}
|
@ -71,6 +71,7 @@ private:
|
||||
EggTexture::Format _format;
|
||||
bool _force_format;
|
||||
bool _generic_format;
|
||||
bool _keep_format;
|
||||
EggRenderMode::AlphaMode _alpha_mode;
|
||||
|
||||
int _aniso_degree;
|
Loading…
x
Reference in New Issue
Block a user