fix some issues with video textures

This commit is contained in:
David Rose 2006-06-19 13:29:18 +00:00
parent 5a44148f12
commit bcb66a94d7
7 changed files with 288 additions and 275 deletions

View File

@ -591,16 +591,16 @@ load_model(const NodePath &parent, Filename filename) {
// The extension isn't a known model file type; is it a known // The extension isn't a known model file type; is it a known
// image file extension? // image file extension?
if (extension == "txo") { if (extension == "txo") {
// A texture object. Not exactly an image, but certainly a // A texture object. Not exactly an image, but certainly a
// texture. // texture.
is_image = true; is_image = true;
} else { } else {
TexturePool *texture_pool = TexturePool::get_global_ptr(); TexturePool *texture_pool = TexturePool::get_global_ptr();
if (texture_pool->get_texture_type(extension) != NULL) { if (texture_pool->get_texture_type(extension) != NULL) {
// It is a known image file extension. // It is a known image file extension.
is_image = true; is_image = true;
} }
} }
} }
} }

View File

@ -895,7 +895,7 @@ get_ram_image() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void Texture:: void Texture::
set_ram_image(PTA_uchar image, Texture::CompressionMode compression, set_ram_image(PTA_uchar image, Texture::CompressionMode compression,
size_t page_size) { size_t page_size) {
nassertv(compression != CM_default); nassertv(compression != CM_default);
nassertv(compression != CM_off || image.size() == get_expected_ram_image_size()); nassertv(compression != CM_off || image.size() == get_expected_ram_image_size());
if (_ram_images.empty()) { if (_ram_images.empty()) {
@ -1232,7 +1232,7 @@ write(ostream &out, int indent_level) const {
case TT_3d_texture: case TT_3d_texture:
out << "3-d, " << get_x_size() << " x " << get_y_size() out << "3-d, " << get_x_size() << " x " << get_y_size()
<< " x " << get_z_size(); << " x " << get_z_size();
break; break;
case TT_cube_map: case TT_cube_map:
@ -1344,7 +1344,7 @@ write(ostream &out, int indent_level) const {
case TT_3d_texture: case TT_3d_texture:
out << get_wrap_u() << " x " << get_wrap_v() out << get_wrap_u() << " x " << get_wrap_v()
<< " x " << get_wrap_w() << ", "; << " x " << get_wrap_w() << ", ";
break; break;
case TT_cube_map: case TT_cube_map:
@ -1367,18 +1367,18 @@ write(ostream &out, int indent_level) const {
int count = 0; int count = 0;
size_t total_size = 0; size_t total_size = 0;
for (int n = 1; n < num_ram_mipmap_images; ++n) { for (int n = 1; n < num_ram_mipmap_images; ++n) {
if (has_ram_mipmap_image(n)) { if (has_ram_mipmap_image(n)) {
++count; ++count;
total_size += get_ram_mipmap_image_size(n); total_size += get_ram_mipmap_image_size(n);
} else { } else {
// Stop at the first gap. // Stop at the first gap.
break; break;
} }
} }
indent(out, indent_level + 2) indent(out, indent_level + 2)
<< count << count
<< " mipmap levels also present in ram (" << total_size << " mipmap levels also present in ram (" << total_size
<< " bytes).\n"; << " bytes).\n";
} }
} else { } else {
@ -1644,8 +1644,8 @@ make_texture() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Texture:: bool Texture::
do_read(const Filename &fullpath, const Filename &alpha_fullpath, do_read(const Filename &fullpath, const Filename &alpha_fullpath,
int primary_file_num_channels, int alpha_file_channel, int primary_file_num_channels, int alpha_file_channel,
int z, int n, bool read_pages, bool read_mipmaps, int z, int n, bool read_pages, bool read_mipmaps,
BamCacheRecord *record) { BamCacheRecord *record) {
if ((z == 0 || read_pages) && (n == 0 || read_mipmaps)) { if ((z == 0 || read_pages) && (n == 0 || read_mipmaps)) {
// When we re-read the page 0 of the base image, we clear // When we re-read the page 0 of the base image, we clear
@ -1699,7 +1699,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
// determined by the number of files we find. After mipmap // determined by the number of files we find. After mipmap
// level 0, though, the number of pages is predetermined. // level 0, though, the number of pages is predetermined.
if (n != 0) { if (n != 0) {
z_size = get_expected_mipmap_z_size(n); z_size = get_expected_mipmap_z_size(n);
} }
z = 0; z = 0;
@ -1708,41 +1708,41 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
Filename alpha_n_pattern = Filename::pattern_filename(alpha_fullpath_pattern.get_filename_index(z)); Filename alpha_n_pattern = Filename::pattern_filename(alpha_fullpath_pattern.get_filename_index(z));
if (!n_pattern.has_hash()) { if (!n_pattern.has_hash()) {
gobj_cat.error() gobj_cat.error()
<< "Filename requires two different hash sequences: " << fullpath << "Filename requires two different hash sequences: " << fullpath
<< "\n"; << "\n";
return false; return false;
} }
Filename file = n_pattern.get_filename_index(n); Filename file = n_pattern.get_filename_index(n);
Filename alpha_file = alpha_n_pattern.get_filename_index(n); Filename alpha_file = alpha_n_pattern.get_filename_index(n);
if ((n_size == 0 && (vfs->exists(file) || n == 0)) || if ((n_size == 0 && (vfs->exists(file) || n == 0)) ||
(n_size != 0 && n < n_size)) { (n_size != 0 && n < n_size)) {
// Continue through the loop. // Continue through the loop.
} else { } else {
// We've reached the end of the mipmap sequence. // We've reached the end of the mipmap sequence.
break; break;
} }
while ((z_size == 0 && (vfs->exists(file) || z == 0)) || while ((z_size == 0 && (vfs->exists(file) || z == 0)) ||
(z_size != 0 && z < z_size)) { (z_size != 0 && z < z_size)) {
if (!do_read_one(file, alpha_file, z, n, primary_file_num_channels, if (!do_read_one(file, alpha_file, z, n, primary_file_num_channels,
alpha_file_channel, record)) { alpha_file_channel, record)) {
return false; return false;
} }
++z; ++z;
n_pattern = Filename::pattern_filename(fullpath_pattern.get_filename_index(z)); n_pattern = Filename::pattern_filename(fullpath_pattern.get_filename_index(z));
file = n_pattern.get_filename_index(n); file = n_pattern.get_filename_index(n);
alpha_file = alpha_n_pattern.get_filename_index(n); alpha_file = alpha_n_pattern.get_filename_index(n);
} }
if (n == 0 && n_size == 0) { if (n == 0 && n_size == 0) {
// If n_size is not specified, it gets implicitly set after we // If n_size is not specified, it gets implicitly set after we
// read the base texture image (which determines the size of // read the base texture image (which determines the size of
// the texture). // the texture).
n_size = get_expected_num_mipmap_levels(); n_size = get_expected_num_mipmap_levels();
} }
++n; ++n;
} }
@ -1753,8 +1753,8 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
Filename alpha_fullpath_pattern = Filename::pattern_filename(alpha_fullpath); Filename alpha_fullpath_pattern = Filename::pattern_filename(alpha_fullpath);
if (!fullpath_pattern.has_hash()) { if (!fullpath_pattern.has_hash()) {
gobj_cat.error() gobj_cat.error()
<< "Filename requires a hash mark: " << fullpath << "Filename requires a hash mark: " << fullpath
<< "\n"; << "\n";
return false; return false;
} }
@ -1763,10 +1763,10 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
Filename file = fullpath_pattern.get_filename_index(z); Filename file = fullpath_pattern.get_filename_index(z);
Filename alpha_file = alpha_fullpath_pattern.get_filename_index(z); Filename alpha_file = alpha_fullpath_pattern.get_filename_index(z);
while ((z_size == 0 && (vfs->exists(file) || z == 0)) || while ((z_size == 0 && (vfs->exists(file) || z == 0)) ||
(z_size != 0 && z < z_size)) { (z_size != 0 && z < z_size)) {
if (!do_read_one(file, alpha_file, z, 0, primary_file_num_channels, if (!do_read_one(file, alpha_file, z, 0, primary_file_num_channels,
alpha_file_channel, record)) { alpha_file_channel, record)) {
return false; return false;
} }
++z; ++z;
@ -1780,8 +1780,8 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
Filename alpha_fullpath_pattern = Filename::pattern_filename(alpha_fullpath); Filename alpha_fullpath_pattern = Filename::pattern_filename(alpha_fullpath);
if (!fullpath_pattern.has_hash()) { if (!fullpath_pattern.has_hash()) {
gobj_cat.error() gobj_cat.error()
<< "Filename requires a hash mark: " << fullpath << "Filename requires a hash mark: " << fullpath
<< "\n"; << "\n";
return false; return false;
} }
@ -1790,9 +1790,9 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
Filename alpha_file = alpha_fullpath_pattern.get_filename_index(n); Filename alpha_file = alpha_fullpath_pattern.get_filename_index(n);
while ((n_size == 0 && (vfs->exists(file) || n == 0)) || while ((n_size == 0 && (vfs->exists(file) || n == 0)) ||
(n_size != 0 && n < n_size)) { (n_size != 0 && n < n_size)) {
if (!do_read_one(file, alpha_file, z, n, if (!do_read_one(file, alpha_file, z, n,
primary_file_num_channels, alpha_file_channel, primary_file_num_channels, alpha_file_channel,
record)) { record)) {
return false; return false;
} }
@ -1811,7 +1811,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
} else { } else {
// Just an ordinary read of one file. // Just an ordinary read of one file.
if (!do_read_one(fullpath, alpha_fullpath, z, n, if (!do_read_one(fullpath, alpha_fullpath, z, n,
primary_file_num_channels, alpha_file_channel, primary_file_num_channels, alpha_file_channel,
record)) { record)) {
return false; return false;
} }
@ -1833,7 +1833,7 @@ do_read(const Filename &fullpath, const Filename &alpha_fullpath,
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Texture:: bool Texture::
do_read_one(const Filename &fullpath, const Filename &alpha_fullpath, do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel, int z, int n, int primary_file_num_channels, int alpha_file_channel,
BamCacheRecord *record) { BamCacheRecord *record) {
if (record != (BamCacheRecord *)NULL) { if (record != (BamCacheRecord *)NULL) {
record->add_dependent_file(fullpath); record->add_dependent_file(fullpath);
@ -1869,23 +1869,23 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
if (textures_header_only) { if (textures_header_only) {
if (!alpha_image.read_header(alpha_fullpath)) { if (!alpha_image.read_header(alpha_fullpath)) {
gobj_cat.error() gobj_cat.error()
<< "Texture::read() - couldn't read: " << alpha_fullpath << endl; << "Texture::read() - couldn't read: " << alpha_fullpath << endl;
return false; return false;
} }
alpha_image = PNMImage(1, 1, alpha_image.get_num_channels(), alpha_image = PNMImage(1, 1, alpha_image.get_num_channels(),
alpha_image.get_maxval(), alpha_image.get_maxval(),
alpha_image.get_type()); alpha_image.get_type());
alpha_image.fill(1.0); alpha_image.fill(1.0);
if (alpha_image.has_alpha()) { if (alpha_image.has_alpha()) {
alpha_image.alpha_fill(1.0); alpha_image.alpha_fill(1.0);
} }
} else { } else {
if (!alpha_image.read(alpha_fullpath, NULL, true)) { if (!alpha_image.read(alpha_fullpath, NULL, true)) {
gobj_cat.error() gobj_cat.error()
<< "Texture::read() - couldn't read (alpha): " << alpha_fullpath << endl; << "Texture::read() - couldn't read (alpha): " << alpha_fullpath << endl;
return false; return false;
} }
} }
} }
@ -1914,16 +1914,16 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
// The grayscale (alpha channel) image must be the same size as the // The grayscale (alpha channel) image must be the same size as the
// main image. // main image.
if (image.get_x_size() != alpha_image.get_x_size() || if (image.get_x_size() != alpha_image.get_x_size() ||
image.get_y_size() != alpha_image.get_y_size()) { image.get_y_size() != alpha_image.get_y_size()) {
gobj_cat.info() gobj_cat.info()
<< "Automatically rescaling " << alpha_fullpath.get_basename() << "Automatically rescaling " << alpha_fullpath.get_basename()
<< " from " << alpha_image.get_x_size() << " by " << " from " << alpha_image.get_x_size() << " by "
<< alpha_image.get_y_size() << " to " << image.get_x_size() << alpha_image.get_y_size() << " to " << image.get_x_size()
<< " by " << image.get_y_size() << "\n"; << " by " << image.get_y_size() << "\n";
PNMImage scaled(image.get_x_size(), image.get_y_size(), PNMImage scaled(image.get_x_size(), image.get_y_size(),
alpha_image.get_num_channels(), alpha_image.get_num_channels(),
alpha_image.get_maxval(), alpha_image.get_type()); alpha_image.get_maxval(), alpha_image.get_type());
scaled.quick_filter_from(alpha_image); scaled.quick_filter_from(alpha_image);
alpha_image = scaled; alpha_image = scaled;
} }
@ -1941,31 +1941,31 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
image.add_alpha(); image.add_alpha();
if (alpha_file_channel == 4 || if (alpha_file_channel == 4 ||
(alpha_file_channel == 2 && alpha_image.get_num_channels() == 2)) { (alpha_file_channel == 2 && alpha_image.get_num_channels() == 2)) {
// Use the alpha channel. // Use the alpha channel.
for (int x = 0; x < image.get_x_size(); x++) { for (int x = 0; x < image.get_x_size(); x++) {
for (int y = 0; y < image.get_y_size(); y++) { for (int y = 0; y < image.get_y_size(); y++) {
image.set_alpha(x, y, alpha_image.get_alpha(x, y)); image.set_alpha(x, y, alpha_image.get_alpha(x, y));
} }
} }
_alpha_file_channel = alpha_image.get_num_channels(); _alpha_file_channel = alpha_image.get_num_channels();
} else if (alpha_file_channel >= 1 && alpha_file_channel <= 3 && } else if (alpha_file_channel >= 1 && alpha_file_channel <= 3 &&
alpha_image.get_num_channels() >= 3) { alpha_image.get_num_channels() >= 3) {
// Use the appropriate red, green, or blue channel. // Use the appropriate red, green, or blue channel.
for (int x = 0; x < image.get_x_size(); x++) { for (int x = 0; x < image.get_x_size(); x++) {
for (int y = 0; y < image.get_y_size(); y++) { for (int y = 0; y < image.get_y_size(); y++) {
image.set_alpha(x, y, alpha_image.get_channel_val(x, y, alpha_file_channel - 1)); image.set_alpha(x, y, alpha_image.get_channel_val(x, y, alpha_file_channel - 1));
} }
} }
_alpha_file_channel = alpha_file_channel; _alpha_file_channel = alpha_file_channel;
} else { } else {
// Use the grayscale channel. // Use the grayscale channel.
for (int x = 0; x < image.get_x_size(); x++) { for (int x = 0; x < image.get_x_size(); x++) {
for (int y = 0; y < image.get_y_size(); y++) { for (int y = 0; y < image.get_y_size(); y++) {
image.set_alpha(x, y, alpha_image.get_gray(x, y)); image.set_alpha(x, y, alpha_image.get_gray(x, y));
} }
} }
_alpha_file_channel = 0; _alpha_file_channel = 0;
} }
@ -2003,18 +2003,18 @@ do_write(const Filename &fullpath, int z, int n, bool write_pages, bool write_mi
int z_size = get_expected_mipmap_z_size(n); int z_size = get_expected_mipmap_z_size(n);
for (z = 0; z < z_size; ++z) { for (z = 0; z < z_size; ++z) {
Filename n_pattern = Filename::pattern_filename(fullpath_pattern.get_filename_index(z)); Filename n_pattern = Filename::pattern_filename(fullpath_pattern.get_filename_index(z));
if (!n_pattern.has_hash()) { if (!n_pattern.has_hash()) {
gobj_cat.error() gobj_cat.error()
<< "Filename requires two different hash sequences: " << fullpath << "Filename requires two different hash sequences: " << fullpath
<< "\n"; << "\n";
return false; return false;
} }
if (!do_write_one(n_pattern.get_filename_index(n), z, n)) { if (!do_write_one(n_pattern.get_filename_index(n), z, n)) {
return false; return false;
} }
} }
} }
@ -2023,14 +2023,14 @@ do_write(const Filename &fullpath, int z, int n, bool write_pages, bool write_mi
Filename fullpath_pattern = Filename::pattern_filename(fullpath); Filename fullpath_pattern = Filename::pattern_filename(fullpath);
if (!fullpath_pattern.has_hash()) { if (!fullpath_pattern.has_hash()) {
gobj_cat.error() gobj_cat.error()
<< "Filename requires a hash mark: " << fullpath << "Filename requires a hash mark: " << fullpath
<< "\n"; << "\n";
return false; return false;
} }
for (z = 0; z < _z_size; ++z) { for (z = 0; z < _z_size; ++z) {
if (!do_write_one(fullpath_pattern.get_filename_index(z), z, n)) { if (!do_write_one(fullpath_pattern.get_filename_index(z), z, n)) {
return false; return false;
} }
} }
@ -2039,15 +2039,15 @@ do_write(const Filename &fullpath, int z, int n, bool write_pages, bool write_mi
Filename fullpath_pattern = Filename::pattern_filename(fullpath); Filename fullpath_pattern = Filename::pattern_filename(fullpath);
if (!fullpath_pattern.has_hash()) { if (!fullpath_pattern.has_hash()) {
gobj_cat.error() gobj_cat.error()
<< "Filename requires a hash mark: " << fullpath << "Filename requires a hash mark: " << fullpath
<< "\n"; << "\n";
return false; return false;
} }
int num_levels = get_num_ram_mipmap_images(); int num_levels = get_num_ram_mipmap_images();
for (int n = 0; n < num_levels; ++n) { for (int n = 0; n < num_levels; ++n) {
if (!do_write_one(fullpath_pattern.get_filename_index(n), z, n)) { if (!do_write_one(fullpath_pattern.get_filename_index(n), z, n)) {
return false; return false;
} }
} }
@ -2228,8 +2228,8 @@ reload_ram_image() {
} }
do_read(get_fullpath(), get_alpha_fullpath(), do_read(get_fullpath(), get_alpha_fullpath(),
_primary_file_num_channels, _alpha_file_channel, _primary_file_num_channels, _alpha_file_channel,
z, n, _has_read_pages, _has_read_mipmaps, NULL); z, n, _has_read_pages, _has_read_mipmaps, NULL);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -2827,58 +2827,58 @@ filter_2d_mipmap_pages(Texture::RamImage &to, const Texture::RamImage &from,
if (y_size != 1) { if (y_size != 1) {
int y; int y;
for (y = 0; y < y_size - 1; y += 2) { for (y = 0; y < y_size - 1; y += 2) {
// For each row. // For each row.
nassertv(p == to._image.p() + z * to._page_size + (y / 2) * to_row_size); nassertv(p == to._image.p() + z * to._page_size + (y / 2) * to_row_size);
nassertv(q == from._image.p() + z * from._page_size + y * row_size); nassertv(q == from._image.p() + z * from._page_size + y * row_size);
if (x_size != 1) { if (x_size != 1) {
int x; int x;
for (x = 0; x < x_size - 1; x += 2) { for (x = 0; x < x_size - 1; x += 2) {
// For each pixel. // For each pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, pixel_size, row_size); filter_component(p, q, pixel_size, row_size);
} }
q += pixel_size; q += pixel_size;
} }
if (x < x_size) { if (x < x_size) {
// Skip the last odd pixel. // Skip the last odd pixel.
q += pixel_size; q += pixel_size;
} }
} else { } else {
// Just one pixel. // Just one pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, 0, row_size); filter_component(p, q, 0, row_size);
} }
} }
q += row_size; q += row_size;
} }
if (y < y_size) { if (y < y_size) {
// Skip the last odd row. // Skip the last odd row.
q += row_size; q += row_size;
} }
} else { } else {
// Just one row. // Just one row.
if (x_size != 1) { if (x_size != 1) {
int x; int x;
for (x = 0; x < x_size - 1; x += 2) { for (x = 0; x < x_size - 1; x += 2) {
// For each pixel. // For each pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, pixel_size, 0); filter_component(p, q, pixel_size, 0);
} }
q += pixel_size; q += pixel_size;
} }
if (x < x_size) { if (x < x_size) {
// Skip the last odd pixel. // Skip the last odd pixel.
q += pixel_size; q += pixel_size;
} }
} else { } else {
// Just one pixel. // Just one pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, 0, 0); filter_component(p, q, 0, 0);
} }
} }
} }
@ -2925,61 +2925,61 @@ filter_3d_mipmap_level(Texture::RamImage &to, const Texture::RamImage &from,
nassertv(p == to._image.p() + (z / 2) * to_page_size); nassertv(p == to._image.p() + (z / 2) * to_page_size);
nassertv(q == from._image.p() + z * page_size); nassertv(q == from._image.p() + z * page_size);
if (y_size != 1) { if (y_size != 1) {
int y; int y;
for (y = 0; y < y_size - 1; y += 2) { for (y = 0; y < y_size - 1; y += 2) {
// For each row. // For each row.
nassertv(p == to._image.p() + (z / 2) * to_page_size + (y / 2) * to_row_size); nassertv(p == to._image.p() + (z / 2) * to_page_size + (y / 2) * to_row_size);
nassertv(q == from._image.p() + z * page_size + y * row_size); nassertv(q == from._image.p() + z * page_size + y * row_size);
if (x_size != 1) { if (x_size != 1) {
int x; int x;
for (x = 0; x < x_size - 1; x += 2) { for (x = 0; x < x_size - 1; x += 2) {
// For each pixel. // For each pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, pixel_size, row_size, page_size); filter_component(p, q, pixel_size, row_size, page_size);
} }
q += pixel_size; q += pixel_size;
} }
if (x < x_size) { if (x < x_size) {
// Skip the last odd pixel. // Skip the last odd pixel.
q += pixel_size; q += pixel_size;
} }
} else { } else {
// Just one pixel. // Just one pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, 0, row_size, page_size); filter_component(p, q, 0, row_size, page_size);
} }
} }
q += row_size; q += row_size;
} }
if (y < y_size) { if (y < y_size) {
// Skip the last odd row. // Skip the last odd row.
q += row_size; q += row_size;
} }
} else { } else {
// Just one row. // Just one row.
if (x_size != 1) { if (x_size != 1) {
int x; int x;
for (x = 0; x < x_size - 1; x += 2) { for (x = 0; x < x_size - 1; x += 2) {
// For each pixel. // For each pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, pixel_size, 0, page_size); filter_component(p, q, pixel_size, 0, page_size);
} }
q += pixel_size; q += pixel_size;
} }
if (x < x_size) { if (x < x_size) {
// Skip the last odd pixel. // Skip the last odd pixel.
q += pixel_size; q += pixel_size;
} }
} else { } else {
// Just one pixel. // Just one pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, 0, 0, page_size); filter_component(p, q, 0, 0, page_size);
} }
} }
} }
q += page_size; q += page_size;
} }
@ -2992,58 +2992,58 @@ filter_3d_mipmap_level(Texture::RamImage &to, const Texture::RamImage &from,
if (y_size != 1) { if (y_size != 1) {
int y; int y;
for (y = 0; y < y_size - 1; y += 2) { for (y = 0; y < y_size - 1; y += 2) {
// For each row. // For each row.
nassertv(p == to._image.p() + (y / 2) * to_row_size); nassertv(p == to._image.p() + (y / 2) * to_row_size);
nassertv(q == from._image.p() + y * row_size); nassertv(q == from._image.p() + y * row_size);
if (x_size != 1) { if (x_size != 1) {
int x; int x;
for (x = 0; x < x_size - 1; x += 2) { for (x = 0; x < x_size - 1; x += 2) {
// For each pixel. // For each pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, pixel_size, row_size, 0); filter_component(p, q, pixel_size, row_size, 0);
} }
q += pixel_size; q += pixel_size;
} }
if (x < x_size) { if (x < x_size) {
// Skip the last odd pixel. // Skip the last odd pixel.
q += pixel_size; q += pixel_size;
} }
} else { } else {
// Just one pixel. // Just one pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, 0, row_size, 0); filter_component(p, q, 0, row_size, 0);
} }
} }
q += row_size; q += row_size;
} }
if (y < y_size) { if (y < y_size) {
// Skip the last odd row. // Skip the last odd row.
q += row_size; q += row_size;
} }
} else { } else {
// Just one row. // Just one row.
if (x_size != 1) { if (x_size != 1) {
int x; int x;
for (x = 0; x < x_size - 1; x += 2) { for (x = 0; x < x_size - 1; x += 2) {
// For each pixel. // For each pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, pixel_size, 0, 0); filter_component(p, q, pixel_size, 0, 0);
} }
q += pixel_size; q += pixel_size;
} }
if (x < x_size) { if (x < x_size) {
// Skip the last odd pixel. // Skip the last odd pixel.
q += pixel_size; q += pixel_size;
} }
} else { } else {
// Just one pixel. // Just one pixel.
for (int c = 0; c < _num_components; ++c) { for (int c = 0; c < _num_components; ++c) {
// For each component. // For each component.
filter_component(p, q, 0, 0, 0); filter_component(p, q, 0, 0, 0);
} }
} }
} }
} }
@ -3299,7 +3299,7 @@ fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) {
_ram_images.push_back(RamImage()); _ram_images.push_back(RamImage());
_ram_images[n]._page_size = get_expected_ram_page_size(); _ram_images[n]._page_size = get_expected_ram_page_size();
if (manager->get_file_minor_ver() >= 1) { if (manager->get_file_minor_ver() >= 1) {
_ram_images[n]._page_size = scan.get_uint32(); _ram_images[n]._page_size = scan.get_uint32();
} }
size_t u_size = scan.get_uint32(); size_t u_size = scan.get_uint32();
@ -3307,7 +3307,7 @@ fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) {
// fill the _image buffer with image data // fill the _image buffer with image data
PTA_uchar image = PTA_uchar::empty_array(u_size); PTA_uchar image = PTA_uchar::empty_array(u_size);
for (size_t u_idx = 0; u_idx < u_size; ++u_idx) { for (size_t u_idx = 0; u_idx < u_size; ++u_idx) {
image[(int)u_idx] = scan.get_uint8(); image[(int)u_idx] = scan.get_uint8();
} }
_ram_images[n]._image = image; _ram_images[n]._image = image;
} }

View File

@ -202,17 +202,17 @@ PUBLISHED:
INLINE bool read(const Filename &fullpath); INLINE bool read(const Filename &fullpath);
INLINE bool read(const Filename &fullpath, const Filename &alpha_fullpath, INLINE bool read(const Filename &fullpath, const Filename &alpha_fullpath,
int primary_file_num_channels, int alpha_file_channel); int primary_file_num_channels, int alpha_file_channel);
INLINE bool read(const Filename &fullpath, int z, int n, INLINE bool read(const Filename &fullpath, int z, int n,
bool read_pages, bool read_mipmaps); bool read_pages, bool read_mipmaps);
INLINE bool read(const Filename &fullpath, const Filename &alpha_fullpath, INLINE bool read(const Filename &fullpath, const Filename &alpha_fullpath,
int primary_file_num_channels, int alpha_file_channel, int primary_file_num_channels, int alpha_file_channel,
int z, int n, bool read_pages, bool read_mipmaps, int z, int n, bool read_pages, bool read_mipmaps,
BamCacheRecord *record = NULL); BamCacheRecord *record = NULL);
INLINE bool write(const Filename &fullpath); INLINE bool write(const Filename &fullpath);
INLINE bool write(const Filename &fullpath, int z, int n, INLINE bool write(const Filename &fullpath, int z, int n,
bool write_pages, bool write_mipmaps); bool write_pages, bool write_mipmaps);
bool read_txo(istream &in, const string &filename = "stream"); bool read_txo(istream &in, const string &filename = "stream");
bool write_txo(ostream &out, const string &filename = "stream") const; bool write_txo(ostream &out, const string &filename = "stream") const;
@ -281,7 +281,7 @@ PUBLISHED:
INLINE PTA_uchar modify_ram_image(); INLINE PTA_uchar modify_ram_image();
INLINE PTA_uchar make_ram_image(); INLINE PTA_uchar make_ram_image();
void set_ram_image(PTA_uchar image, CompressionMode compression = CM_off, void set_ram_image(PTA_uchar image, CompressionMode compression = CM_off,
size_t page_size = 0); size_t page_size = 0);
void clear_ram_image(); void clear_ram_image();
INLINE void set_keep_ram_image(bool keep_ram_image); INLINE void set_keep_ram_image(bool keep_ram_image);
virtual bool get_keep_ram_image() const; virtual bool get_keep_ram_image() const;
@ -363,14 +363,14 @@ public:
protected: protected:
virtual bool do_read(const Filename &fullpath, const Filename &alpha_fullpath, virtual bool do_read(const Filename &fullpath, const Filename &alpha_fullpath,
int primary_file_num_channels, int alpha_file_channel, int primary_file_num_channels, int alpha_file_channel,
int z, int n, bool read_pages, bool read_mipmaps, int z, int n, bool read_pages, bool read_mipmaps,
BamCacheRecord *record); BamCacheRecord *record);
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath, virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel, int z, int n, int primary_file_num_channels, int alpha_file_channel,
BamCacheRecord *record); BamCacheRecord *record);
bool do_write(const Filename &fullpath, int z, int n, bool do_write(const Filename &fullpath, int z, int n,
bool write_pages, bool write_mipmaps) const; bool write_pages, bool write_mipmaps) const;
bool do_write_one(const Filename &fullpath, int z, int n) const; bool do_write_one(const Filename &fullpath, int z, int n) const;
virtual bool do_load_one(const PNMImage &pnmimage, const string &name, virtual bool do_load_one(const PNMImage &pnmimage, const string &name,

View File

@ -23,6 +23,7 @@
#include "clockObject.h" #include "clockObject.h"
#include "config_gobj.h" #include "config_gobj.h"
#include "config_grutil.h" #include "config_grutil.h"
#include "bamCacheRecord.h"
TypeHandle FFMpegTexture::_type_handle; TypeHandle FFMpegTexture::_type_handle;
@ -127,7 +128,7 @@ reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
//Number of frames is a little questionable if we've got variable //Number of frames is a little questionable if we've got variable
//frame rate. Duration comes in as a generic timestamp, //frame rate. Duration comes in as a generic timestamp,
//and is therefore multiplied by AV_TIME_BASE. //and is therefore multiplied by AV_TIME_BASE.
num_frames = (int(stream.pFormatCtx->duration*frame_rate))/AV_TIME_BASE; num_frames = (int)((stream.pFormatCtx->duration*frame_rate)/AV_TIME_BASE);
if (grutil_cat.is_debug()) { if (grutil_cat.is_debug()) {
grutil_cat.debug() grutil_cat.debug()
<< "Loaded " << stream._filename << ", " << num_frames << " frames at " << "Loaded " << stream._filename << ", " << num_frames << " frames at "
@ -196,7 +197,8 @@ make_texture() {
// Description: Called once per frame, as needed, to load the new // Description: Called once per frame, as needed, to load the new
// image contents. // image contents.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FFMpegTexture::update_frame(int frame) { void FFMpegTexture::
update_frame(int frame) {
int max_z = max(_z_size, (int)_pages.size()); int max_z = max(_z_size, (int)_pages.size());
for (int z = 0; z < max_z; ++z) { for (int z = 0; z < max_z; ++z) {
VideoPage &page = _pages[z]; VideoPage &page = _pages[z];
@ -310,7 +312,12 @@ void FFMpegTexture::update_frame(int frame) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool FFMpegTexture:: bool FFMpegTexture::
do_read_one(const Filename &fullpath, const Filename &alpha_fullpath, do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel) { int z, int n, int primary_file_num_channels, int alpha_file_channel,
BamCacheRecord *record) {
if (record != (BamCacheRecord *)NULL) {
record->add_dependent_file(fullpath);
}
nassertr(n == 0, false); nassertr(n == 0, false);
nassertr(z >= 0 && z < get_z_size(), false); nassertr(z >= 0 && z < get_z_size(), false);
@ -324,7 +331,7 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
if (!alpha_fullpath.empty()) { if (!alpha_fullpath.empty()) {
if (!page._alpha.read(alpha_fullpath)) { if (!page._alpha.read(alpha_fullpath)) {
grutil_cat.error() grutil_cat.error()
<< "FFMPEG couldn't read " << alpha_fullpath << " as video.\n"; << "FFMPEG couldn't read " << alpha_fullpath << " as video.\n";
page._color.clear(); page._color.clear();
return false; return false;
} }
@ -493,9 +500,6 @@ get_frame_data(int frame) {
int gotFrame; int gotFrame;
long long timeStamp=(AV_TIME_BASE/vstream->r_frame_rate.num)*(frame *vstream->r_frame_rate.den);
long long currTimeStamp;
//first find out where to go //first find out where to go
if(frame==comingFrom) if(frame==comingFrom)
{ {
@ -507,8 +511,11 @@ get_frame_data(int frame) {
} }
else else
{ {
double timeStamp=((double)AV_TIME_BASE*frame *vstream->r_frame_rate.den)/vstream->r_frame_rate.num;
double currTimeStamp;
//find point in time //find point in time
int res=av_seek_frame( pFormatCtx,-1, timeStamp,AVSEEK_FLAG_BACKWARD ); int res=av_seek_frame( pFormatCtx,-1, (long long)timeStamp,AVSEEK_FLAG_BACKWARD );
//Okay, now we're at the nearest keyframe behind our timestamp. //Okay, now we're at the nearest keyframe behind our timestamp.
//Hurry up and move through frames until we find a frame just after it. //Hurry up and move through frames until we find a frame just after it.
@ -517,9 +524,8 @@ get_frame_data(int frame) {
av_read_frame( pFormatCtx, &packet ); av_read_frame( pFormatCtx, &packet );
// should really be checking that this is a video packet // should really be checking that this is a video packet
currTimeStamp = (long long)(packet.pts / packet.duration * currTimeStamp = (((double)AV_TIME_BASE * packet.pts) /
AV_TIME_BASE / av_q2d( vstream->r_frame_rate)); ((double)packet.duration * av_q2d( vstream->r_frame_rate)));
if( currTimeStamp > timeStamp ) if( currTimeStamp > timeStamp )
break; break;

View File

@ -50,8 +50,8 @@ public:
protected: protected:
virtual void update_frame(int frame); virtual void update_frame(int frame);
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath, virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel); int z, int n, int primary_file_num_channels, int alpha_file_channel,
BamCacheRecord *record);
virtual bool do_load_one(const PNMImage &pnmimage, const string &name, virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
int z, int n); int z, int n);

View File

@ -24,6 +24,7 @@
#include "config_gobj.h" #include "config_gobj.h"
#include "config_grutil.h" #include "config_grutil.h"
#include "bamReader.h" #include "bamReader.h"
#include "bamCacheRecord.h"
TypeHandle OpenCVTexture::_type_handle; TypeHandle OpenCVTexture::_type_handle;
@ -295,7 +296,12 @@ update_frame(int frame) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool OpenCVTexture:: bool OpenCVTexture::
do_read_one(const Filename &fullpath, const Filename &alpha_fullpath, do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel) { int z, int n, int primary_file_num_channels, int alpha_file_channel,
BamCacheRecord *record) {
if (record != (BamCacheRecord *)NULL) {
record->add_dependent_file(fullpath);
}
nassertr(n == 0, false); nassertr(n == 0, false);
nassertr(z >= 0 && z < get_z_size(), false); nassertr(z >= 0 && z < get_z_size(), false);
@ -367,14 +373,14 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
// texture) to the indicated static image. // texture) to the indicated static image.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool OpenCVTexture:: bool OpenCVTexture::
do_load_one(const PNMImage &pnmimage, int z, int n) { do_load_one(const PNMImage &pnmimage, const string &name, int z, int n) {
if (z <= (int)_pages.size()) { if (z <= (int)_pages.size()) {
VideoPage &page = modify_page(z); VideoPage &page = modify_page(z);
page._color.clear(); page._color.clear();
page._alpha.clear(); page._alpha.clear();
} }
return Texture::do_load_one(pnmimage, z, n); return Texture::do_load_one(pnmimage, name, z, n);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -56,7 +56,8 @@ protected:
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath, virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel); int z, int n, int primary_file_num_channels, int alpha_file_channel);
virtual bool do_load_one(const PNMImage &pnmimage, int z, int n); virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
int z, int n);
private: private:
class VideoPage; class VideoPage;