00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "destTextureImage.h"
00016 #include "sourceTextureImage.h"
00017 #include "texturePlacement.h"
00018 #include "textureImage.h"
00019 #include "palettizer.h"
00020
00021 #include "datagram.h"
00022 #include "datagramIterator.h"
00023 #include "bamReader.h"
00024 #include "bamWriter.h"
00025
00026 TypeHandle DestTextureImage::_type_handle;
00027
00028
00029
00030
00031
00032
00033
00034
00035 DestTextureImage::
00036 DestTextureImage() {
00037 }
00038
00039
00040
00041
00042
00043
00044 DestTextureImage::
00045 DestTextureImage(TexturePlacement *placement) {
00046 TextureImage *texture = placement->get_texture();
00047 _properties = texture->get_properties();
00048 _size_known = texture->is_size_known();
00049 if (_size_known) {
00050 _x_size = texture->get_x_size();
00051 _y_size = texture->get_y_size();
00052
00053 if (pal->_force_power_2) {
00054 _x_size = to_power_2(_x_size);
00055 _y_size = to_power_2(_y_size);
00056 } else {
00057 _x_size = max(_x_size, 1);
00058 _y_size = max(_y_size, 1);
00059 }
00060 }
00061
00062 set_filename(placement->get_group(), texture->get_name());
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 void DestTextureImage::
00072 copy(TextureImage *texture) {
00073 const PNMImage &source_image = texture->read_source_image();
00074 if (source_image.is_valid()) {
00075 PNMImage dest_image(_x_size, _y_size, texture->get_num_channels(),
00076 source_image.get_maxval());
00077 dest_image.quick_filter_from(source_image);
00078 write(dest_image);
00079
00080 } else {
00081
00082 PNMImage dest_image(_x_size, _y_size, texture->get_num_channels());
00083 dest_image.fill(1.0, 0.0, 0.0);
00084 if (dest_image.has_alpha()) {
00085 dest_image.alpha_fill(1.0);
00086 }
00087
00088 write(dest_image);
00089 }
00090
00091 texture->release_source_image();
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 void DestTextureImage::
00103 copy_if_stale(const DestTextureImage *other, TextureImage *texture) {
00104 if (other->get_x_size() != get_x_size() ||
00105 other->get_y_size() != get_y_size() ||
00106 other->get_num_channels() != get_num_channels()) {
00107 copy(texture);
00108
00109 } else {
00110
00111 SourceTextureImage *source = texture->get_preferred_source();
00112
00113 if (source != (SourceTextureImage *)NULL &&
00114 source->get_filename().compare_timestamps(get_filename()) > 0) {
00115 copy(texture);
00116 }
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 int DestTextureImage::
00127 to_power_2(int value) {
00128 int x = 1;
00129 while ((x << 1) <= value) {
00130 x = (x << 1);
00131 }
00132 return x;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141 void DestTextureImage::
00142 register_with_read_factory() {
00143 BamReader::get_factory()->
00144 register_factory(get_class_type(), make_DestTextureImage);
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154 void DestTextureImage::
00155 write_datagram(BamWriter *writer, Datagram &datagram) {
00156 ImageFile::write_datagram(writer, datagram);
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 TypedWritable* DestTextureImage::
00168 make_DestTextureImage(const FactoryParams ¶ms) {
00169 DestTextureImage *me = new DestTextureImage;
00170 DatagramIterator scan;
00171 BamReader *manager;
00172
00173 parse_params(params, scan, manager);
00174 me->fillin(scan, manager);
00175 return me;
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185 void DestTextureImage::
00186 fillin(DatagramIterator &scan, BamReader *manager) {
00187 ImageFile::fillin(scan, manager);
00188 }