From 5ae23c901b9081136e48fc52189c55d4197b79e2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 12 Sep 2003 22:37:52 +0000 Subject: [PATCH] integrate egg-palettize with egg-mkfont --- pandatool/src/egg-mkfont/Sources.pp | 2 +- pandatool/src/egg-mkfont/eggMakeFont.cxx | 191 ++++++++++++++---- pandatool/src/egg-mkfont/eggMakeFont.h | 12 +- pandatool/src/egg-palettize/Sources.pp | 26 +-- pandatool/src/egg-palettize/eggPalettize.cxx | 15 +- pandatool/src/palettizer/Sources.pp | 33 +++ .../config_palettizer.cxx} | 16 +- .../config_palettizer.h} | 10 +- .../destTextureImage.cxx | 0 .../destTextureImage.h | 0 .../{egg-palettize => palettizer}/eggFile.cxx | 0 .../{egg-palettize => palettizer}/eggFile.h | 0 .../filenameUnifier.cxx | 0 .../filenameUnifier.h | 0 .../imageFile.cxx | 0 .../{egg-palettize => palettizer}/imageFile.h | 0 .../omitReason.cxx | 0 .../omitReason.h | 0 .../pal_string_utils.cxx | 0 .../pal_string_utils.h | 0 .../paletteGroup.cxx | 0 .../paletteGroup.h | 0 .../paletteGroups.cxx | 0 .../paletteGroups.h | 0 .../paletteImage.cxx | 24 ++- .../paletteImage.h | 4 +- .../palettePage.cxx | 0 .../palettePage.h | 0 .../palettizer.cxx | 29 ++- .../palettizer.h | 8 +- .../palettizer_composite1.cxx} | 49 +++-- .../sourceTextureImage.cxx | 15 +- .../sourceTextureImage.h | 2 + .../textureImage.cxx | 19 +- .../textureImage.h | 1 + .../textureMemoryCounter.cxx | 0 .../textureMemoryCounter.h | 0 .../texturePlacement.cxx | 0 .../texturePlacement.h | 0 .../texturePosition.cxx | 0 .../texturePosition.h | 0 .../textureProperties.cxx | 10 +- .../textureProperties.h | 1 + .../textureReference.cxx | 0 .../textureReference.h | 0 .../textureRequest.cxx | 1 + .../textureRequest.h | 1 + .../{egg-palettize => palettizer}/txaFile.cxx | 31 +++ .../{egg-palettize => palettizer}/txaFile.h | 1 + .../{egg-palettize => palettizer}/txaLine.cxx | 9 + .../{egg-palettize => palettizer}/txaLine.h | 1 + 51 files changed, 392 insertions(+), 119 deletions(-) create mode 100644 pandatool/src/palettizer/Sources.pp rename pandatool/src/{egg-palettize/config_egg_palettize.cxx => palettizer/config_palettizer.cxx} (91%) rename pandatool/src/{egg-palettize/config_egg_palettize.h => palettizer/config_palettizer.h} (80%) rename pandatool/src/{egg-palettize => palettizer}/destTextureImage.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/destTextureImage.h (100%) rename pandatool/src/{egg-palettize => palettizer}/eggFile.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/eggFile.h (100%) rename pandatool/src/{egg-palettize => palettizer}/filenameUnifier.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/filenameUnifier.h (100%) rename pandatool/src/{egg-palettize => palettizer}/imageFile.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/imageFile.h (100%) rename pandatool/src/{egg-palettize => palettizer}/omitReason.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/omitReason.h (100%) rename pandatool/src/{egg-palettize => palettizer}/pal_string_utils.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/pal_string_utils.h (100%) rename pandatool/src/{egg-palettize => palettizer}/paletteGroup.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/paletteGroup.h (100%) rename pandatool/src/{egg-palettize => palettizer}/paletteGroups.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/paletteGroups.h (100%) rename pandatool/src/{egg-palettize => palettizer}/paletteImage.cxx (98%) rename pandatool/src/{egg-palettize => palettizer}/paletteImage.h (98%) rename pandatool/src/{egg-palettize => palettizer}/palettePage.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/palettePage.h (100%) rename pandatool/src/{egg-palettize => palettizer}/palettizer.cxx (97%) rename pandatool/src/{egg-palettize => palettizer}/palettizer.h (93%) rename pandatool/src/{egg-palettize/egg-palettize_composite1.cxx => palettizer/palettizer_composite1.cxx} (90%) rename pandatool/src/{egg-palettize => palettizer}/sourceTextureImage.cxx (95%) rename pandatool/src/{egg-palettize => palettizer}/sourceTextureImage.h (97%) rename pandatool/src/{egg-palettize => palettizer}/textureImage.cxx (98%) rename pandatool/src/{egg-palettize => palettizer}/textureImage.h (99%) rename pandatool/src/{egg-palettize => palettizer}/textureMemoryCounter.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/textureMemoryCounter.h (100%) rename pandatool/src/{egg-palettize => palettizer}/texturePlacement.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/texturePlacement.h (100%) rename pandatool/src/{egg-palettize => palettizer}/texturePosition.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/texturePosition.h (100%) rename pandatool/src/{egg-palettize => palettizer}/textureProperties.cxx (98%) rename pandatool/src/{egg-palettize => palettizer}/textureProperties.h (98%) rename pandatool/src/{egg-palettize => palettizer}/textureReference.cxx (100%) rename pandatool/src/{egg-palettize => palettizer}/textureReference.h (100%) rename pandatool/src/{egg-palettize => palettizer}/textureRequest.cxx (98%) rename pandatool/src/{egg-palettize => palettizer}/textureRequest.h (98%) rename pandatool/src/{egg-palettize => palettizer}/txaFile.cxx (92%) rename pandatool/src/{egg-palettize => palettizer}/txaFile.h (97%) rename pandatool/src/{egg-palettize => palettizer}/txaLine.cxx (98%) rename pandatool/src/{egg-palettize => palettizer}/txaLine.h (99%) diff --git a/pandatool/src/egg-mkfont/Sources.pp b/pandatool/src/egg-mkfont/Sources.pp index 84c4c161a3..286bd964e6 100644 --- a/pandatool/src/egg-mkfont/Sources.pp +++ b/pandatool/src/egg-mkfont/Sources.pp @@ -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 \ diff --git a/pandatool/src/egg-mkfont/eggMakeFont.cxx b/pandatool/src/egg-mkfont/eggMakeFont.cxx index 5a1b2fc203..29f87b72eb 100644 --- a/pandatool/src/egg-mkfont/eggMakeFont.cxx +++ b/pandatool/src/egg-mkfont/eggMakeFont.cxx @@ -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); diff --git a/pandatool/src/egg-mkfont/eggMakeFont.h b/pandatool/src/egg-mkfont/eggMakeFont.h index 98497700d5..a9c1ea733e 100644 --- a/pandatool/src/egg-mkfont/eggMakeFont.h +++ b/pandatool/src/egg-mkfont/eggMakeFont.h @@ -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 TRefs; TRefs _trefs; + + typedef pvector Textures; + Textures _textures; }; diff --git a/pandatool/src/egg-palettize/Sources.pp b/pandatool/src/egg-palettize/Sources.pp index 281b58c3c5..e04daf95e6 100644 --- a/pandatool/src/egg-palettize/Sources.pp +++ b/pandatool/src/egg-palettize/Sources.pp @@ -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 diff --git a/pandatool/src/egg-palettize/eggPalettize.cxx b/pandatool/src/egg-palettize/eggPalettize.cxx index 832d39cc9e..830ade5856 100644 --- a/pandatool/src/egg-palettize/eggPalettize.cxx +++ b/pandatool/src/egg-palettize/eggPalettize.cxx @@ -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) { diff --git a/pandatool/src/palettizer/Sources.pp b/pandatool/src/palettizer/Sources.pp new file mode 100644 index 0000000000..dcab55182f --- /dev/null +++ b/pandatool/src/palettizer/Sources.pp @@ -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 diff --git a/pandatool/src/egg-palettize/config_egg_palettize.cxx b/pandatool/src/palettizer/config_palettizer.cxx similarity index 91% rename from pandatool/src/egg-palettize/config_egg_palettize.cxx rename to pandatool/src/palettizer/config_palettizer.cxx index 45c3203167..910b77b0bc 100644 --- a/pandatool/src/egg-palettize/config_egg_palettize.cxx +++ b/pandatool/src/palettizer/config_palettizer.cxx @@ -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; diff --git a/pandatool/src/egg-palettize/config_egg_palettize.h b/pandatool/src/palettizer/config_palettizer.h similarity index 80% rename from pandatool/src/egg-palettize/config_egg_palettize.h rename to pandatool/src/palettizer/config_palettizer.h index b248514933..b22eb67aef 100644 --- a/pandatool/src/egg-palettize/config_egg_palettize.h +++ b/pandatool/src/palettizer/config_palettizer.h @@ -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__ */ diff --git a/pandatool/src/egg-palettize/destTextureImage.cxx b/pandatool/src/palettizer/destTextureImage.cxx similarity index 100% rename from pandatool/src/egg-palettize/destTextureImage.cxx rename to pandatool/src/palettizer/destTextureImage.cxx diff --git a/pandatool/src/egg-palettize/destTextureImage.h b/pandatool/src/palettizer/destTextureImage.h similarity index 100% rename from pandatool/src/egg-palettize/destTextureImage.h rename to pandatool/src/palettizer/destTextureImage.h diff --git a/pandatool/src/egg-palettize/eggFile.cxx b/pandatool/src/palettizer/eggFile.cxx similarity index 100% rename from pandatool/src/egg-palettize/eggFile.cxx rename to pandatool/src/palettizer/eggFile.cxx diff --git a/pandatool/src/egg-palettize/eggFile.h b/pandatool/src/palettizer/eggFile.h similarity index 100% rename from pandatool/src/egg-palettize/eggFile.h rename to pandatool/src/palettizer/eggFile.h diff --git a/pandatool/src/egg-palettize/filenameUnifier.cxx b/pandatool/src/palettizer/filenameUnifier.cxx similarity index 100% rename from pandatool/src/egg-palettize/filenameUnifier.cxx rename to pandatool/src/palettizer/filenameUnifier.cxx diff --git a/pandatool/src/egg-palettize/filenameUnifier.h b/pandatool/src/palettizer/filenameUnifier.h similarity index 100% rename from pandatool/src/egg-palettize/filenameUnifier.h rename to pandatool/src/palettizer/filenameUnifier.h diff --git a/pandatool/src/egg-palettize/imageFile.cxx b/pandatool/src/palettizer/imageFile.cxx similarity index 100% rename from pandatool/src/egg-palettize/imageFile.cxx rename to pandatool/src/palettizer/imageFile.cxx diff --git a/pandatool/src/egg-palettize/imageFile.h b/pandatool/src/palettizer/imageFile.h similarity index 100% rename from pandatool/src/egg-palettize/imageFile.h rename to pandatool/src/palettizer/imageFile.h diff --git a/pandatool/src/egg-palettize/omitReason.cxx b/pandatool/src/palettizer/omitReason.cxx similarity index 100% rename from pandatool/src/egg-palettize/omitReason.cxx rename to pandatool/src/palettizer/omitReason.cxx diff --git a/pandatool/src/egg-palettize/omitReason.h b/pandatool/src/palettizer/omitReason.h similarity index 100% rename from pandatool/src/egg-palettize/omitReason.h rename to pandatool/src/palettizer/omitReason.h diff --git a/pandatool/src/egg-palettize/pal_string_utils.cxx b/pandatool/src/palettizer/pal_string_utils.cxx similarity index 100% rename from pandatool/src/egg-palettize/pal_string_utils.cxx rename to pandatool/src/palettizer/pal_string_utils.cxx diff --git a/pandatool/src/egg-palettize/pal_string_utils.h b/pandatool/src/palettizer/pal_string_utils.h similarity index 100% rename from pandatool/src/egg-palettize/pal_string_utils.h rename to pandatool/src/palettizer/pal_string_utils.h diff --git a/pandatool/src/egg-palettize/paletteGroup.cxx b/pandatool/src/palettizer/paletteGroup.cxx similarity index 100% rename from pandatool/src/egg-palettize/paletteGroup.cxx rename to pandatool/src/palettizer/paletteGroup.cxx diff --git a/pandatool/src/egg-palettize/paletteGroup.h b/pandatool/src/palettizer/paletteGroup.h similarity index 100% rename from pandatool/src/egg-palettize/paletteGroup.h rename to pandatool/src/palettizer/paletteGroup.h diff --git a/pandatool/src/egg-palettize/paletteGroups.cxx b/pandatool/src/palettizer/paletteGroups.cxx similarity index 100% rename from pandatool/src/egg-palettize/paletteGroups.cxx rename to pandatool/src/palettizer/paletteGroups.cxx diff --git a/pandatool/src/egg-palettize/paletteGroups.h b/pandatool/src/palettizer/paletteGroups.h similarity index 100% rename from pandatool/src/egg-palettize/paletteGroups.h rename to pandatool/src/palettizer/paletteGroups.h diff --git a/pandatool/src/egg-palettize/paletteImage.cxx b/pandatool/src/palettizer/paletteImage.cxx similarity index 98% rename from pandatool/src/egg-palettize/paletteImage.cxx rename to pandatool/src/palettizer/paletteImage.cxx index f102a92027..c6cd047d65 100644 --- a/pandatool/src/egg-palettize/paletteImage.cxx +++ b/pandatool/src/palettizer/paletteImage.cxx @@ -25,11 +25,11 @@ #include "sourceTextureImage.h" #include "filenameUnifier.h" -#include -#include -#include -#include -#include +#include "indent.h" +#include "datagram.h" +#include "datagramIterator.h" +#include "bamReader.h" +#include "bamWriter.h" #include @@ -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; diff --git a/pandatool/src/egg-palettize/paletteImage.h b/pandatool/src/palettizer/paletteImage.h similarity index 98% rename from pandatool/src/egg-palettize/paletteImage.h rename to pandatool/src/palettizer/paletteImage.h index 49bbc8b660..8e82078f3c 100644 --- a/pandatool/src/egg-palettize/paletteImage.h +++ b/pandatool/src/palettizer/paletteImage.h @@ -19,11 +19,11 @@ #ifndef PALETTEIMAGE_H #define PALETTEIMAGE_H -#include +#include "pandatoolbase.h" #include "imageFile.h" -#include +#include "pnmImage.h" class PalettePage; class TexturePlacement; diff --git a/pandatool/src/egg-palettize/palettePage.cxx b/pandatool/src/palettizer/palettePage.cxx similarity index 100% rename from pandatool/src/egg-palettize/palettePage.cxx rename to pandatool/src/palettizer/palettePage.cxx diff --git a/pandatool/src/egg-palettize/palettePage.h b/pandatool/src/palettizer/palettePage.h similarity index 100% rename from pandatool/src/egg-palettize/palettePage.h rename to pandatool/src/palettizer/palettePage.h diff --git a/pandatool/src/egg-palettize/palettizer.cxx b/pandatool/src/palettizer/palettizer.cxx similarity index 97% rename from pandatool/src/egg-palettize/palettizer.cxx rename to pandatool/src/palettizer/palettizer.cxx index f9c039fe23..82e105cb7e 100644 --- a/pandatool/src/egg-palettize/palettizer.cxx +++ b/pandatool/src/palettizer/palettizer.cxx @@ -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(); diff --git a/pandatool/src/egg-palettize/palettizer.h b/pandatool/src/palettizer/palettizer.h similarity index 93% rename from pandatool/src/egg-palettize/palettizer.h rename to pandatool/src/palettizer/palettizer.h index 7bf2107d35..c73e40a29c 100644 --- a/pandatool/src/egg-palettize/palettizer.h +++ b/pandatool/src/palettizer/palettizer.h @@ -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 diff --git a/pandatool/src/egg-palettize/egg-palettize_composite1.cxx b/pandatool/src/palettizer/palettizer_composite1.cxx similarity index 90% rename from pandatool/src/egg-palettize/egg-palettize_composite1.cxx rename to pandatool/src/palettizer/palettizer_composite1.cxx index 6dc40ac4a3..c8086bf570 100644 --- a/pandatool/src/egg-palettize/egg-palettize_composite1.cxx +++ b/pandatool/src/palettizer/palettizer_composite1.cxx @@ -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" + diff --git a/pandatool/src/egg-palettize/sourceTextureImage.cxx b/pandatool/src/palettizer/sourceTextureImage.cxx similarity index 95% rename from pandatool/src/egg-palettize/sourceTextureImage.cxx rename to pandatool/src/palettizer/sourceTextureImage.cxx index 3dce048ee0..3c40ec77ed 100644 --- a/pandatool/src/egg-palettize/sourceTextureImage.cxx +++ b/pandatool/src/palettizer/sourceTextureImage.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; } diff --git a/pandatool/src/egg-palettize/sourceTextureImage.h b/pandatool/src/palettizer/sourceTextureImage.h similarity index 97% rename from pandatool/src/egg-palettize/sourceTextureImage.h rename to pandatool/src/palettizer/sourceTextureImage.h index 98efe9071e..a0bc7786f4 100644 --- a/pandatool/src/egg-palettize/sourceTextureImage.h +++ b/pandatool/src/palettizer/sourceTextureImage.h @@ -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; diff --git a/pandatool/src/egg-palettize/textureImage.cxx b/pandatool/src/palettizer/textureImage.cxx similarity index 98% rename from pandatool/src/egg-palettize/textureImage.cxx rename to pandatool/src/palettizer/textureImage.cxx index 4859ca1a8f..f949f80256 100644 --- a/pandatool/src/egg-palettize/textureImage.cxx +++ b/pandatool/src/palettizer/textureImage.cxx @@ -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 diff --git a/pandatool/src/egg-palettize/textureImage.h b/pandatool/src/palettizer/textureImage.h similarity index 99% rename from pandatool/src/egg-palettize/textureImage.h rename to pandatool/src/palettizer/textureImage.h index e9fd130d47..6eb9cda2c4 100644 --- a/pandatool/src/egg-palettize/textureImage.h +++ b/pandatool/src/palettizer/textureImage.h @@ -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); diff --git a/pandatool/src/egg-palettize/textureMemoryCounter.cxx b/pandatool/src/palettizer/textureMemoryCounter.cxx similarity index 100% rename from pandatool/src/egg-palettize/textureMemoryCounter.cxx rename to pandatool/src/palettizer/textureMemoryCounter.cxx diff --git a/pandatool/src/egg-palettize/textureMemoryCounter.h b/pandatool/src/palettizer/textureMemoryCounter.h similarity index 100% rename from pandatool/src/egg-palettize/textureMemoryCounter.h rename to pandatool/src/palettizer/textureMemoryCounter.h diff --git a/pandatool/src/egg-palettize/texturePlacement.cxx b/pandatool/src/palettizer/texturePlacement.cxx similarity index 100% rename from pandatool/src/egg-palettize/texturePlacement.cxx rename to pandatool/src/palettizer/texturePlacement.cxx diff --git a/pandatool/src/egg-palettize/texturePlacement.h b/pandatool/src/palettizer/texturePlacement.h similarity index 100% rename from pandatool/src/egg-palettize/texturePlacement.h rename to pandatool/src/palettizer/texturePlacement.h diff --git a/pandatool/src/egg-palettize/texturePosition.cxx b/pandatool/src/palettizer/texturePosition.cxx similarity index 100% rename from pandatool/src/egg-palettize/texturePosition.cxx rename to pandatool/src/palettizer/texturePosition.cxx diff --git a/pandatool/src/egg-palettize/texturePosition.h b/pandatool/src/palettizer/texturePosition.h similarity index 100% rename from pandatool/src/egg-palettize/texturePosition.h rename to pandatool/src/palettizer/texturePosition.h diff --git a/pandatool/src/egg-palettize/textureProperties.cxx b/pandatool/src/palettizer/textureProperties.cxx similarity index 98% rename from pandatool/src/egg-palettize/textureProperties.cxx rename to pandatool/src/palettizer/textureProperties.cxx index 2994df8f86..78d5d4427d 100644 --- a/pandatool/src/egg-palettize/textureProperties.cxx +++ b/pandatool/src/palettizer/textureProperties.cxx @@ -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(); diff --git a/pandatool/src/egg-palettize/textureProperties.h b/pandatool/src/palettizer/textureProperties.h similarity index 98% rename from pandatool/src/egg-palettize/textureProperties.h rename to pandatool/src/palettizer/textureProperties.h index 20173f112c..83cab8c327 100644 --- a/pandatool/src/egg-palettize/textureProperties.h +++ b/pandatool/src/palettizer/textureProperties.h @@ -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; diff --git a/pandatool/src/egg-palettize/textureReference.cxx b/pandatool/src/palettizer/textureReference.cxx similarity index 100% rename from pandatool/src/egg-palettize/textureReference.cxx rename to pandatool/src/palettizer/textureReference.cxx diff --git a/pandatool/src/egg-palettize/textureReference.h b/pandatool/src/palettizer/textureReference.h similarity index 100% rename from pandatool/src/egg-palettize/textureReference.h rename to pandatool/src/palettizer/textureReference.h diff --git a/pandatool/src/egg-palettize/textureRequest.cxx b/pandatool/src/palettizer/textureRequest.cxx similarity index 98% rename from pandatool/src/egg-palettize/textureRequest.cxx rename to pandatool/src/palettizer/textureRequest.cxx index 7e33973406..6053c8efa1 100644 --- a/pandatool/src/egg-palettize/textureRequest.cxx +++ b/pandatool/src/palettizer/textureRequest.cxx @@ -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; diff --git a/pandatool/src/egg-palettize/textureRequest.h b/pandatool/src/palettizer/textureRequest.h similarity index 98% rename from pandatool/src/egg-palettize/textureRequest.h rename to pandatool/src/palettizer/textureRequest.h index 9d6ac6c776..89207615e9 100644 --- a/pandatool/src/egg-palettize/textureRequest.h +++ b/pandatool/src/palettizer/textureRequest.h @@ -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; diff --git a/pandatool/src/egg-palettize/txaFile.cxx b/pandatool/src/palettizer/txaFile.cxx similarity index 92% rename from pandatool/src/egg-palettize/txaFile.cxx rename to pandatool/src/palettizer/txaFile.cxx index c8812cebb0..3837435cf3 100644 --- a/pandatool/src/egg-palettize/txaFile.cxx +++ b/pandatool/src/palettizer/txaFile.cxx @@ -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 diff --git a/pandatool/src/egg-palettize/txaFile.h b/pandatool/src/palettizer/txaFile.h similarity index 97% rename from pandatool/src/egg-palettize/txaFile.h rename to pandatool/src/palettizer/txaFile.h index 3d843964ed..02a3151247 100644 --- a/pandatool/src/egg-palettize/txaFile.h +++ b/pandatool/src/palettizer/txaFile.h @@ -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); diff --git a/pandatool/src/egg-palettize/txaLine.cxx b/pandatool/src/palettizer/txaLine.cxx similarity index 98% rename from pandatool/src/egg-palettize/txaLine.cxx rename to pandatool/src/palettizer/txaLine.cxx index e4483d97ef..d8f7080022 100644 --- a/pandatool/src/egg-palettize/txaLine.cxx +++ b/pandatool/src/palettizer/txaLine.cxx @@ -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; } diff --git a/pandatool/src/egg-palettize/txaLine.h b/pandatool/src/palettizer/txaLine.h similarity index 99% rename from pandatool/src/egg-palettize/txaLine.h rename to pandatool/src/palettizer/txaLine.h index 4746f491f5..d00f99f00b 100644 --- a/pandatool/src/egg-palettize/txaLine.h +++ b/pandatool/src/palettizer/txaLine.h @@ -71,6 +71,7 @@ private: EggTexture::Format _format; bool _force_format; bool _generic_format; + bool _keep_format; EggRenderMode::AlphaMode _alpha_mode; int _aniso_degree;