15 #include "movieVideoCursor.h" 16 #include "config_movies.h" 17 #include "pStatCollector.h" 18 #include "pStatTimer.h" 19 #include "bamReader.h" 20 #include "bamWriter.h" 22 PStatCollector MovieVideoCursor::_copy_pcollector(
"*:Copy Video into Texture");
23 PStatCollector MovieVideoCursor::_copy_pcollector_ram(
"*:Copy Video into Texture:modify_ram_image");
24 PStatCollector MovieVideoCursor::_copy_pcollector_copy(
"*:Copy Video into Texture:copy");
27 TypeHandle MovieVideoCursor::Buffer::_type_handle;
72 Texture::Format fmt = (get_num_components() == 4) ? Texture::F_rgba : Texture::F_rgb;
73 tex->
setup_texture(Texture::TT_2d_texture, fullx, fully, 1, Texture::T_unsigned_byte, fmt);
131 if (buffer == NULL) {
141 nassertv(page < t->get_num_pages());
154 memcpy(data, buffer->_block, size_x() * size_y() * get_num_components());
157 unsigned char *p = buffer->_block;
159 int src_stride = size_x() * get_num_components();
161 for (
int y=0; y<size_y(); y++) {
162 memcpy(data, p, src_stride);
167 int src_width = get_num_components();
169 for (
int y = 0; y < size_y(); ++y) {
170 for (
int x = 0; x < size_x(); ++x) {
191 if (buffer == NULL) {
201 nassertv(page < t->get_z_size());
202 nassertv((alpha_src >= 0) && (alpha_src <= get_num_components()));
214 int src_width = get_num_components();
215 int src_stride = size_x() * src_width;
217 unsigned char *p = buffer->_block;
218 if (alpha_src == 0) {
219 for (
int y=0; y<size_y(); y++) {
220 for (
int x=0; x<size_x(); x++) {
221 unsigned char *pp = &p[x * src_width];
222 data[x*4+3] = (pp[0] + pp[1] + pp[2]) / 3;
229 for (
int y=0; y<size_y(); y++) {
230 for (
int x=0; x<size_x(); x++) {
231 data[x*4+3] = p[x * src_width + alpha_src];
248 if (buffer == NULL) {
258 nassertv(page < t->get_z_size());
270 int src_stride = size_x() * get_num_components();
271 int src_width = get_num_components();
273 unsigned char *p = buffer->_block;
274 for (
int y=0; y<size_y(); y++) {
275 for (
int x=0; x<size_x(); x++) {
276 data[x * 4 + 0] = p[x * src_width + 0];
277 data[x * 4 + 1] = p[x * src_width + 1];
278 data[x * 4 + 2] = p[x * src_width + 2];
293 get_standard_buffer() {
294 if (_standard_buffer == NULL) {
295 _standard_buffer = make_new_buffer();
297 return _standard_buffer;
308 return new Buffer(size_x() * size_y() * get_num_components());
347 void MovieVideoCursor::
359 MovieVideoCursor::Buffer::
360 Buffer(
size_t block_size) :
361 _block_size(block_size)
364 _block = (
unsigned char *)_deleted_chain->
allocate(_block_size, get_class_type());
372 MovieVideoCursor::Buffer::
374 _deleted_chain->
deallocate(_block, get_class_type());
DeletedBufferChain * get_deleted_chain(size_t buffer_size)
Returns a pointer to a global DeletedBufferChain object suitable for allocating arrays of the indicat...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Base class for objects that can be written to and read from Bam files.
void setup_texture(TextureType texture_type, int x_size, int y_size, int z_size, ComponentType component_type, Format format)
Sets the texture to the indicated type and dimensions, presumably in preparation for calling read() o...
void setup_texture(Texture *tex) const
Set up the specified Texture object to contain content from this movie.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
int get_component_width() const
Returns the number of bytes stored for each color component of a texel.
void * allocate(size_t size, TypeHandle type_handle)
Allocates the memory for a new buffer of the indicated size (which must be no greater than the fixed ...
virtual void apply_to_texture_rgb(const Buffer *buffer, Texture *t, int page)
Copies this buffer's contents into the RGB channels of the supplied texture.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A lightweight class that represents a single element that may be timed and/or counted via stats...
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
virtual bool set_time(double timestamp, int loop_count)
Updates the cursor to the indicated time.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
void set_pad_size(int x=0, int y=0, int z=0)
Sets the size of the pad region.
void deallocate(void *ptr, TypeHandle type_handle)
Frees the memory for a buffer previously allocated via allocate().
void set_keep_ram_image(bool keep_ram_image)
Sets the flag that indicates whether this Texture is eligible to have its main RAM copy of the textur...
virtual int compare_timestamp(const Buffer *other) const
Used to sort different buffers to ensure they correspond to the same source frame, particularly important when synchronizing the different pages of a multi-page texture.
virtual void apply_to_texture(const Buffer *buffer, Texture *t, int page)
Stores this buffer's contents in the indicated texture.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
int get_y_size() const
Returns the height of the texture image in texels.
A MovieVideo is actually any source that provides a sequence of video frames.
virtual void apply_to_texture_alpha(const Buffer *buffer, Texture *t, int page, int alpha_src)
Copies this buffer's contents into the alpha channel of the supplied texture.
A class to retrieve the individual data elements previously stored in a Datagram. ...
int get_num_components() const
Returns the number of color components for each texel of the texture image.
TypeHandle is the identifier used to differentiate C++ class types.
PTA_uchar modify_ram_image()
Returns a modifiable pointer to the system-RAM image.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
bool adjust_this_size(int &x_size, int &y_size, const string &name, bool for_padding) const
Works like adjust_size, but also considers the texture class.
size_t get_expected_ram_page_size() const
Returns the number of bytes that should be used per each Z page of the 3-d texture.
int get_x_size() const
Returns the width of the texture image in texels.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
virtual double get_timestamp() const
Returns the nearest timestamp value of this particular buffer.