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
// image file extension?
if (extension == "txo") {
// A texture object. Not exactly an image, but certainly a
// texture.
is_image = true;
// A texture object. Not exactly an image, but certainly a
// texture.
is_image = true;
} else {
TexturePool *texture_pool = TexturePool::get_global_ptr();
if (texture_pool->get_texture_type(extension) != NULL) {
// It is a known image file extension.
is_image = true;
}
TexturePool *texture_pool = TexturePool::get_global_ptr();
if (texture_pool->get_texture_type(extension) != NULL) {
// It is a known image file extension.
is_image = true;
}
}
}
}

View File

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

View File

@ -202,17 +202,17 @@ PUBLISHED:
INLINE bool read(const Filename &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,
bool read_pages, bool read_mipmaps);
bool read_pages, bool read_mipmaps);
INLINE bool read(const Filename &fullpath, const Filename &alpha_fullpath,
int primary_file_num_channels, int alpha_file_channel,
int z, int n, bool read_pages, bool read_mipmaps,
int primary_file_num_channels, int alpha_file_channel,
int z, int n, bool read_pages, bool read_mipmaps,
BamCacheRecord *record = NULL);
INLINE bool write(const Filename &fullpath);
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 write_txo(ostream &out, const string &filename = "stream") const;
@ -281,7 +281,7 @@ PUBLISHED:
INLINE PTA_uchar modify_ram_image();
INLINE PTA_uchar make_ram_image();
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();
INLINE void set_keep_ram_image(bool keep_ram_image);
virtual bool get_keep_ram_image() const;
@ -363,14 +363,14 @@ public:
protected:
virtual bool do_read(const Filename &fullpath, const Filename &alpha_fullpath,
int primary_file_num_channels, int alpha_file_channel,
int z, int n, bool read_pages, bool read_mipmaps,
int primary_file_num_channels, int alpha_file_channel,
int z, int n, bool read_pages, bool read_mipmaps,
BamCacheRecord *record);
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);
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;
virtual bool do_load_one(const PNMImage &pnmimage, const string &name,

View File

@ -23,6 +23,7 @@
#include "clockObject.h"
#include "config_gobj.h"
#include "config_grutil.h"
#include "bamCacheRecord.h"
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
//frame rate. Duration comes in as a generic timestamp,
//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()) {
grutil_cat.debug()
<< "Loaded " << stream._filename << ", " << num_frames << " frames at "
@ -196,7 +197,8 @@ make_texture() {
// Description: Called once per frame, as needed, to load the new
// image contents.
////////////////////////////////////////////////////////////////////
void FFMpegTexture::update_frame(int frame) {
void FFMpegTexture::
update_frame(int frame) {
int max_z = max(_z_size, (int)_pages.size());
for (int z = 0; z < max_z; ++z) {
VideoPage &page = _pages[z];
@ -310,7 +312,12 @@ void FFMpegTexture::update_frame(int frame) {
////////////////////////////////////////////////////////////////////
bool FFMpegTexture::
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(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 (!page._alpha.read(alpha_fullpath)) {
grutil_cat.error()
<< "FFMPEG couldn't read " << alpha_fullpath << " as video.\n";
<< "FFMPEG couldn't read " << alpha_fullpath << " as video.\n";
page._color.clear();
return false;
}
@ -492,9 +499,6 @@ get_frame_data(int frame) {
AVStream* vstream=pFormatCtx->streams[streamNumber];
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
if(frame==comingFrom)
@ -507,9 +511,12 @@ get_frame_data(int frame) {
}
else
{
double timeStamp=((double)AV_TIME_BASE*frame *vstream->r_frame_rate.den)/vstream->r_frame_rate.num;
double currTimeStamp;
//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.
//Hurry up and move through frames until we find a frame just after it.
pCodecCtx->hurry_up = 1;
@ -517,9 +524,8 @@ get_frame_data(int frame) {
av_read_frame( pFormatCtx, &packet );
// should really be checking that this is a video packet
currTimeStamp = (long long)(packet.pts / packet.duration *
AV_TIME_BASE / av_q2d( vstream->r_frame_rate));
currTimeStamp = (((double)AV_TIME_BASE * packet.pts) /
((double)packet.duration * av_q2d( vstream->r_frame_rate)));
if( currTimeStamp > timeStamp )
break;

View File

@ -50,8 +50,8 @@ public:
protected:
virtual void update_frame(int frame);
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,
int z, int n);

View File

@ -24,6 +24,7 @@
#include "config_gobj.h"
#include "config_grutil.h"
#include "bamReader.h"
#include "bamCacheRecord.h"
TypeHandle OpenCVTexture::_type_handle;
@ -295,7 +296,12 @@ update_frame(int frame) {
////////////////////////////////////////////////////////////////////
bool OpenCVTexture::
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(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.
////////////////////////////////////////////////////////////////////
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()) {
VideoPage &page = modify_page(z);
page._color.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,
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:
class VideoPage;