37 read(std::istream &in,
const string &filename) {
41 int ch = get_line_or_semicolon(in, line);
42 while (ch != EOF || !line.empty()) {
46 size_t hash = line.find(
'#');
47 if (hash != string::npos) {
48 line = line.substr(0, hash);
54 }
else if (line[0] ==
':') {
58 if (words[0] ==
":group") {
59 okflag = parse_group_line(words);
61 }
else if (words[0] ==
":palette") {
62 okflag = parse_palette_line(words);
64 }
else if (words[0] ==
":margin") {
65 okflag = parse_margin_line(words);
67 }
else if (words[0] ==
":background") {
68 okflag = parse_background_line(words);
70 }
else if (words[0] ==
":coverage") {
71 okflag = parse_coverage_line(words);
73 }
else if (words[0] ==
":powertwo") {
74 okflag = parse_powertwo_line(words);
76 }
else if (words[0] ==
":imagetype") {
77 okflag = parse_imagetype_line(words);
79 }
else if (words[0] ==
":shadowtype") {
80 okflag = parse_shadowtype_line(words);
82 }
else if (words[0] ==
":round") {
83 okflag = parse_round_line(words);
85 }
else if (words[0] ==
":remap") {
86 okflag = parse_remap_line(words);
88 }
else if (words[0] ==
":cutout") {
89 okflag = parse_cutout_line(words);
91 }
else if (words[0] ==
":textureswap") {
92 okflag = parse_textureswap_line(words);
95 nout <<
"Invalid keyword " << words[0] <<
"\n";
101 TxaLine &txa_line = _lines.back();
103 okflag = txa_line.
parse(line);
107 nout <<
"Error on line " << line_number <<
" of " << filename <<
"\n";
113 ch = get_line_or_semicolon(in, line);
117 nout <<
"I/O error reading " << filename <<
"\n";
132 Lines::const_iterator li;
133 for (li = _lines.begin(); li != _lines.end(); ++li) {
134 if ((*li).match_egg(egg_file)) {
150 Lines::const_iterator li;
151 for (li = _lines.begin(); li != _lines.end(); ++li) {
152 if ((*li).match_texture(texture)) {
166 Lines::const_iterator li;
167 for (li = _lines.begin(); li != _lines.end(); ++li) {
168 out << (*li) <<
"\n";
178 get_line_or_semicolon(std::istream &in,
string &line) {
181 char semicolon =
';';
183 while (ch != EOF && ch !=
'\n' && ch != semicolon) {
200 parse_group_line(
const vector_string &words) {
201 vector_string::const_iterator wi;
203 assert (wi != words.end());
206 const string &group_name = (*wi);
217 State state = S_none;
219 bool first_on =
true;
221 while (wi != words.end()) {
222 const string &word = (*wi);
223 if (word ==
"with") {
227 }
else if (word ==
"on") {
230 }
else if (word ==
"includes") {
233 }
else if (word ==
"dir") {
236 }
else if (word ==
"margin") {
242 nout <<
"Invalid keyword: " << word <<
"\n";
289 parse_palette_line(
const vector_string &words) {
290 if (words.size() != 3) {
291 nout <<
"Exactly two parameters required for :palette, the x and y " 292 <<
"size of the palette images to generate.\n";
298 nout <<
"Invalid palette size: " << words[1] <<
" " << words[2] <<
"\n";
302 if (pal->_pal_x_size <= 0 || pal->_pal_y_size <= 0) {
303 nout <<
"Invalid palette size: " << pal->_pal_x_size
304 <<
" " << pal->_pal_y_size <<
"\n";
316 parse_margin_line(
const vector_string &words) {
317 if (words.size() != 2) {
318 nout <<
"Exactly one parameter required for :margin, the " 319 <<
"size of the default margin to apply.\n";
324 nout <<
"Invalid margin: " << words[1] <<
"\n";
328 if (pal->_margin < 0) {
329 nout <<
"Invalid margin: " << pal->_margin <<
"\n";
341 parse_background_line(
const vector_string &words) {
342 if (words.size() != 5) {
343 nout <<
"Exactly four parameter required for :background: the " 344 <<
"four [r g b a] components of the background color.\n";
352 nout <<
"Invalid color: " 353 << words[1] <<
" " << words[2] <<
" " 354 << words[3] <<
" " << words[4] <<
" " <<
"\n";
366 parse_coverage_line(
const vector_string &words) {
367 if (words.size() != 2) {
368 nout <<
"Exactly one parameter required for :coverage, the " 369 <<
"value for the default coverage threshold.\n";
375 nout <<
"Invalid coverage threshold: " << words[1] <<
"\n";
379 if (pal->_coverage_threshold <= 0.0) {
380 nout <<
"Invalid coverage threshold: " << pal->_coverage_threshold <<
"\n";
393 parse_powertwo_line(
const vector_string &words) {
394 if (words.size() != 2) {
395 nout <<
"Exactly one parameter required for :powertwo, either a 0 " 402 nout <<
"Invalid powertwo flag: " << words[1] <<
"\n";
406 if (flag != 0 && flag != 1) {
407 nout <<
"Invalid powertwo flag: " << flag <<
"\n";
411 pal->_force_power_2 = (flag != 0);
422 parse_imagetype_line(
const vector_string &words) {
423 if (words.size() != 2) {
424 nout <<
"Exactly one parameter required for :imagetype.\n";
427 const string &imagetype = words[1];
428 if (!parse_image_type_request(imagetype, pal->_color_type, pal->_alpha_type)) {
429 nout <<
"\nKnown image types are:\n";
444 parse_shadowtype_line(
const vector_string &words) {
445 if (words.size() != 2) {
446 nout <<
"Exactly one parameter required for :shadowtype.\n";
449 const string &shadowtype = words[1];
450 if (!parse_image_type_request(shadowtype, pal->_shadow_color_type,
451 pal->_shadow_alpha_type)) {
452 nout <<
"\nKnown image types are:\n";
466 parse_round_line(
const vector_string &words) {
467 if (words.size() == 2) {
468 if (words[1] ==
"no") {
469 pal->_round_uvs =
false;
472 nout <<
"Invalid round keyword: " << words[1] <<
".\n" 473 <<
"Expected 'no', or a round fraction and fuzz factor.\n";
478 if (words.size() != 3) {
479 nout <<
"Exactly two parameters required for :round, the fraction " 480 <<
"to round to, and the fuzz factor.\n";
486 nout <<
"Invalid rounding: " << words[1] <<
" " << words[2] <<
"\n";
490 if (pal->_round_unit <= 0.0 || pal->_round_fuzz < 0.0) {
491 nout <<
"Invalid rounding: " << pal->_round_unit
492 <<
" " << pal->_round_fuzz <<
"\n";
496 pal->_round_uvs =
true;
506 parse_remap_line(
const vector_string &words) {
508 while (i < (
int)words.size()) {
509 const string &keyword = words[i];
510 if (keyword ==
"char") {
513 if (i == (
int)words.size()) {
514 nout <<
"Keyword expected following 'char'\n";
518 if (pal->_remap_char_uv == Palettizer::RU_invalid) {
519 nout <<
"Invalid remap keyword: " << words[i] <<
"\n";
526 if (pal->_remap_uv == Palettizer::RU_invalid) {
527 nout <<
"Invalid remap keyword: " << words[i] <<
"\n";
531 pal->_remap_char_uv = pal->_remap_uv;
548 parse_cutout_line(
const vector_string &words) {
549 if (words.size() < 2 || words.size() > 3) {
550 nout <<
":cutout alpha-mode [ratio]\n";
555 if (am == EggRenderMode::AM_unspecified) {
556 nout <<
"Invalid cutout keyword: " << words[1] <<
"\n";
559 pal->_cutout_mode = am;
561 if (words.size() >= 3) {
563 nout <<
"Invalid cutout ratio: " << words[2] <<
"\n";
575 parse_textureswap_line(
const vector_string &words) {
576 vector_string::const_iterator wi;
578 assert (wi != words.end());
581 const string &group_name = (*wi);
585 string sourceTextureName = (*wi);
591 size_t dot = sourceTextureName.rfind(
'.');
592 if (dot != string::npos) {
593 sourceTextureName = sourceTextureName.substr(0, dot);
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
static RemapUV string_remap(const std::string &str)
Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invali...
PaletteGroup * get_palette_group(const std::string &name)
Returns the PaletteGroup with the given name.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double string_to_double(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
bool match_egg(EggFile *egg_file) const
Searches for a matching line in the .txa file for the given egg file and applies its specifications.
static AlphaMode string_alpha_mode(const std::string &string)
Returns the AlphaMode value associated with the given string representation, or AM_unspecified if the...
void write(std::ostream &out, int indent_level=0) const
Writes a list of supported image file types to the indicated output stream, one per line.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the highest level of grouping for TextureImages.
This is a single matching line in the .txa file.
void group_with(PaletteGroup *other)
Indicates a dependency of this group on some other group.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static PNMFileTypeRegistry * get_global_ptr()
Returns a pointer to the global PNMFileTypeRegistry object.
bool read(std::istream &in, const std::string &filename)
Reads the indicated stream, and returns true if successful, or false if there is an error.
int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const std::string & get_dirname() const
Returns the directory name associated with the palette group.
bool parse(const std::string &line)
Accepts a string that defines a line of the .txa file and parses it into its constinuent parts.
void add_texture_swap_info(const std::string sourceTextureName, const vector_string &swapTextures)
Store textureswap information from textures.txa.
void set_dirname(const std::string &dirname)
Sets the directory name associated with the palette group.
string trim_left(const string &str)
Returns a new string representing the contents of the given string with the leading whitespace remove...
bool has_dirname() const
Returns true if the directory name has been explicitly set for this group.
This represents a single source texture that is referenced by one or more egg files.
void write(std::ostream &out) const
Outputs a representation of the lines that were read in to the indicated output stream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a single egg file known to the palettizer.
bool match_texture(TextureImage *texture) const
Searches for a matching line in the .txa file for the given texture and applies its specifications.
void set_margin_override(const int override)
Returns the set of groups this group depends on.