21 PStatCollector MovieVideoCursor::_copy_pcollector(
"*:Copy Video into Texture");
22 PStatCollector MovieVideoCursor::_copy_pcollector_ram(
"*:Copy Video into Texture:modify_ram_image");
23 PStatCollector MovieVideoCursor::_copy_pcollector_copy(
"*:Copy Video into Texture:copy");
26 TypeHandle MovieVideoCursor::Buffer::_type_handle;
64 switch (get_num_components()) {
66 fmt = Texture::F_luminance;
69 fmt = Texture::F_luminance_alpha;
75 fmt = Texture::F_rgba;
78 tex->
setup_texture(Texture::TT_2d_texture, fullx, fully, 1, Texture::T_unsigned_byte, fmt);
122 if (buffer ==
nullptr) {
134 nassertv(page < t->get_num_pages());
147 memcpy(data, buffer->_block, size_x() * size_y() * get_num_components());
150 unsigned char *p = buffer->_block;
151 int src_width = get_num_components();
153 if (src_width == dst_width) {
154 int src_stride = src_width * size_x();
156 for (
int y=0; y<size_y(); y++) {
157 memcpy(data, p, src_stride);
162 nassertv(src_width >= 3);
163 nassertv(dst_width >= 3);
164 for (
int y = 0; y < size_y(); ++y) {
165 for (
int x = 0; x < size_x(); ++x) {
183 if (buffer ==
nullptr) {
190 if (get_num_components() < 3) {
191 if (get_num_components() == 1 || alpha_src < 2 || alpha_src == 3) {
204 nassertv(page < t->get_z_size());
205 nassertv((alpha_src >= 0) && (alpha_src <= get_num_components()));
217 int src_width = get_num_components();
219 int src_stride = size_x() * src_width;
221 unsigned char *p = buffer->_block;
222 if (alpha_src == 0) {
223 nassertv(src_width >= 3);
224 for (
int y=0; y<size_y(); y++) {
225 for (
int x=0; x<size_x(); x++) {
226 unsigned char *pp = &p[x * src_width];
227 data[(x + 1) * dst_width - 1] = (pp[0] + pp[1] + pp[2]) / 3;
234 for (
int y=0; y<size_y(); y++) {
235 for (
int x=0; x<size_x(); x++) {
236 data[(x + 1) * dst_width - 1] = p[x * src_width + alpha_src];
250 if (buffer ==
nullptr) {
260 nassertv(page < t->get_z_size());
272 int src_width = get_num_components();
274 int src_stride = size_x() * src_width;
276 unsigned char *p = buffer->_block;
277 if (src_width >= 3) {
279 nassertv(dst_width >= 3);
280 for (
int y = 0; y < size_y(); ++y) {
281 for (
int x = 0; x < size_x(); ++x) {
282 data[x * dst_width + 0] = p[x * src_width + 0];
283 data[x * dst_width + 1] = p[x * src_width + 1];
284 data[x * dst_width + 2] = p[x * src_width + 2];
289 }
else if (dst_width == 4) {
291 for (
int y = 0; y < size_y(); ++y) {
292 for (
int x = 0; x < size_x(); ++x) {
293 unsigned char gray = p[x * src_width];
294 data[x * dst_width + 0] = gray;
295 data[x * dst_width + 1] = gray;
296 data[x * dst_width + 2] = gray;
309 get_standard_buffer() {
310 if (_standard_buffer ==
nullptr) {
311 _standard_buffer = make_new_buffer();
313 return _standard_buffer;
321 return new Buffer(size_x() * size_y() * get_num_components());
352 void MovieVideoCursor::
362 MovieVideoCursor::Buffer::
363 Buffer(
size_t block_size) :
364 _block_size(block_size)
367 _block = (
unsigned char *)_deleted_chain->
allocate(_block_size, get_class_type());
373 MovieVideoCursor::Buffer::
375 _deleted_chain->
deallocate(_block, get_class_type());
get_y_size
Returns the height of the texture image in texels.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
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.
bool adjust_this_size(int &x_size, int &y_size, const std::string &name, bool for_padding) const
Works like adjust_size, but also considers the texture class.
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.
get_expected_ram_page_size
Returns the number of bytes that should be used per each Z page of the 3-d texture.
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().
set_keep_ram_image
Sets the flag that indicates whether this Texture is eligible to have its main RAM copy of the textur...
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().
get_num_components
Returns the number of color components for each texel of the texture image.
virtual int compare_timestamp(const Buffer *other) const
Used to sort different buffers to ensure they correspond to the same source frame,...
virtual void apply_to_texture(const Buffer *buffer, Texture *t, int page)
Stores this buffer's contents in the indicated texture.
get_component_width
Returns the number of bytes stored for each color component of a texel.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT(MovieVideoCursor::Buffer) MovieVideoCursor
Gets the current video frame (as specified by set_time()) from the movie and returns it in a pre-allo...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
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.
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 ...
get_x_size
Returns the width of the texture image in texels.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
virtual double get_timestamp() const
Returns the nearest timestamp value of this particular buffer.