restore format from bam

This commit is contained in:
David Rose 2003-07-18 00:43:35 +00:00
parent a2973a6558
commit 979280544c
4 changed files with 83 additions and 55 deletions

View File

@ -71,19 +71,6 @@ INLINE PixelBuffer::
} }
INLINE void PixelBuffer::
set_size(int x_org, int y_org, int x_size, int y_size) {
if ((_xsize != x_size) || (_ysize != y_size) ||
(_xorg != x_org) || (_yorg != y_org)) {
make_dirty();
}
_xsize = x_size;
_ysize = y_size;
_xorg = x_org;
_yorg = y_org;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PixelBuffer::set_xsize // Function: PixelBuffer::set_xsize
// Access: // Access:
@ -137,13 +124,47 @@ INLINE void PixelBuffer::set_yorg(int org)
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PixelBuffer::set_loaded // Function: PixelBuffer::set_size
// Access: // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void PixelBuffer::set_loaded() INLINE void PixelBuffer::
{ set_size(int x_org, int y_org, int x_size, int y_size) {
_loaded = true; if ((_xsize != x_size) || (_ysize != y_size) ||
(_xorg != x_org) || (_yorg != y_org)) {
make_dirty();
}
_xsize = x_size;
_ysize = y_size;
_xorg = x_org;
_yorg = y_org;
}
////////////////////////////////////////////////////////////////////
// Function: PixelBuffer::set_num_components
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void PixelBuffer::
set_num_components(int num_components) {
if (_num_components != num_components) {
_num_components = num_components;
make_dirty();
}
}
////////////////////////////////////////////////////////////////////
// Function: PixelBuffer::set_component_width
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void PixelBuffer::
set_component_width(int component_width) {
if (_component_width != component_width) {
_component_width = component_width;
make_dirty();
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -152,14 +173,23 @@ INLINE void PixelBuffer::set_loaded()
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void PixelBuffer:: INLINE void PixelBuffer::
set_format(PixelBuffer::Format format) set_format(PixelBuffer::Format format) {
{
if (_format != format) { if (_format != format) {
_format = format; _format = format;
make_dirty(); make_dirty();
} }
} }
////////////////////////////////////////////////////////////////////
// Function: PixelBuffer::set_loaded
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void PixelBuffer::set_loaded()
{
_loaded = true;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PixelBuffer::get_xsize // Function: PixelBuffer::get_xsize
// Access: Public // Access: Public
@ -218,7 +248,7 @@ get_border() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE int PixelBuffer:: INLINE int PixelBuffer::
get_num_components() const { get_num_components() const {
return _components; return _num_components;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -39,7 +39,7 @@ PixelBuffer(void) : ImageBuffer()
_border = 0; _border = 0;
_format = F_rgb; _format = F_rgb;
_type = T_unsigned_byte; _type = T_unsigned_byte;
_components = 3; _num_components = 3;
_component_width = 1; _component_width = 1;
_image = PTA_uchar(); _image = PTA_uchar();
@ -61,11 +61,11 @@ PixelBuffer(int xsize, int ysize, int components, int component_width,
_xorg = 0; _xorg = 0;
_yorg = 0; _yorg = 0;
_border = 0; _border = 0;
_components = components; _num_components = components;
_component_width = component_width; _component_width = component_width;
_type = type; _type = type;
_format = format; _format = format;
_image = PTA_uchar::empty_array((unsigned int)(_xsize * _ysize * _components * _component_width)); _image = PTA_uchar::empty_array((unsigned int)(_xsize * _ysize * _num_components * _component_width));
_loaded = true; _loaded = true;
} }
@ -83,12 +83,12 @@ PixelBuffer(int xsize, int ysize, int components, int component_width, Type type
_xorg = 0; _xorg = 0;
_yorg = 0; _yorg = 0;
_border = 0; _border = 0;
_components = components; _num_components = components;
_component_width = component_width; _component_width = component_width;
_type = type; _type = type;
_format = format; _format = format;
if(bAllocateRAM) if(bAllocateRAM)
_image = PTA_uchar::empty_array((unsigned int)(_xsize * _ysize * _components * _component_width)); _image = PTA_uchar::empty_array((unsigned int)(_xsize * _ysize * _num_components * _component_width));
else _image = PTA_uchar(); else _image = PTA_uchar();
_loaded = false; _loaded = false;
} }
@ -105,7 +105,7 @@ PixelBuffer(const PixelBuffer &copy) :
_xorg(copy._xorg), _xorg(copy._xorg),
_yorg(copy._yorg), _yorg(copy._yorg),
_border(copy._border), _border(copy._border),
_components(copy._components), _num_components(copy._num_components),
_component_width(copy._component_width), _component_width(copy._component_width),
_format(copy._format), _format(copy._format),
_type(copy._type), _type(copy._type),
@ -126,7 +126,7 @@ operator = (const PixelBuffer &copy) {
_xorg = copy._xorg; _xorg = copy._xorg;
_yorg = copy._yorg; _yorg = copy._yorg;
_border = copy._border; _border = copy._border;
_components = copy._components; _num_components = copy._num_components;
_component_width = copy._component_width; _component_width = copy._component_width;
_format = copy._format; _format = copy._format;
_type = copy._type; _type = copy._type;
@ -204,7 +204,7 @@ bool PixelBuffer::load(const PNMImage& pnmimage)
{ {
int num_components = pnmimage.get_num_channels(); int num_components = pnmimage.get_num_channels();
if (!_loaded || num_components != _components) { if (!_loaded || num_components != _num_components) {
// Come up with a default format based on the number of channels. // Come up with a default format based on the number of channels.
// But only do this the first time the file is loaded, or if the // But only do this the first time the file is loaded, or if the
// number of channels in the image changes on subsequent loads. // number of channels in the image changes on subsequent loads.
@ -235,7 +235,7 @@ bool PixelBuffer::load(const PNMImage& pnmimage)
_xsize = pnmimage.get_x_size(); _xsize = pnmimage.get_x_size();
_ysize = pnmimage.get_y_size(); _ysize = pnmimage.get_y_size();
_components = num_components; _num_components = num_components;
_loaded = true; _loaded = true;
// Now copy the pixel data from the PNMImage into our internal // Now copy the pixel data from the PNMImage into our internal
@ -248,7 +248,7 @@ bool PixelBuffer::load(const PNMImage& pnmimage)
// Most common case: one byte per pixel, and the source image // Most common case: one byte per pixel, and the source image
// shows a maxval of 255. No scaling is necessary. // shows a maxval of 255. No scaling is necessary.
_type = T_unsigned_byte; _type = T_unsigned_byte;
_image = PTA_uchar::empty_array((int)(_xsize * _ysize * _components)); _image = PTA_uchar::empty_array((int)(_xsize * _ysize * _num_components));
int idx = 0; int idx = 0;
for (int j = _ysize-1; j >= 0; j--) { for (int j = _ysize-1; j >= 0; j--) {
@ -270,7 +270,7 @@ bool PixelBuffer::load(const PNMImage& pnmimage)
// Another possible case: two bytes per pixel, and the source // Another possible case: two bytes per pixel, and the source
// image shows a maxval of 65535. Again, no scaling is necessary. // image shows a maxval of 65535. Again, no scaling is necessary.
_type = T_unsigned_short; _type = T_unsigned_short;
// _image = PTA_uchar::empty_array(_xsize * _ysize * _components * 2); // _image = PTA_uchar::empty_array(_xsize * _ysize * _num_components * 2);
int idx = 0; int idx = 0;
for (int j = _ysize-1; j >= 0; j--) { for (int j = _ysize-1; j >= 0; j--) {
@ -293,7 +293,7 @@ bool PixelBuffer::load(const PNMImage& pnmimage)
// something other than 255. In this case, we should scale the // something other than 255. In this case, we should scale the
// pixel values up to the appropriate amount. // pixel values up to the appropriate amount.
_type = T_unsigned_byte; _type = T_unsigned_byte;
_image = PTA_uchar::empty_array(_xsize * _ysize * _components); _image = PTA_uchar::empty_array(_xsize * _ysize * _num_components);
int idx = 0; int idx = 0;
double scale = 255.0 / (double)maxval; double scale = 255.0 / (double)maxval;
@ -317,7 +317,7 @@ bool PixelBuffer::load(const PNMImage& pnmimage)
// something other than 65535. Again, we must scale the pixel // something other than 65535. Again, we must scale the pixel
// values. // values.
_type = T_unsigned_short; _type = T_unsigned_short;
_image = PTA_uchar::empty_array(_xsize * _ysize * _components * 2); _image = PTA_uchar::empty_array(_xsize * _ysize * _num_components * 2);
int idx = 0; int idx = 0;
double scale = 65535.0 / (double)maxval; double scale = 65535.0 / (double)maxval;
@ -350,7 +350,7 @@ bool PixelBuffer::load(const PNMImage& pnmimage)
bool PixelBuffer:: bool PixelBuffer::
store(PNMImage &pnmimage) const { store(PNMImage &pnmimage) const {
if (_type == T_unsigned_byte) { if (_type == T_unsigned_byte) {
pnmimage.clear(_xsize, _ysize, _components); pnmimage.clear(_xsize, _ysize, _num_components);
bool has_alpha = pnmimage.has_alpha(); bool has_alpha = pnmimage.has_alpha();
bool is_grayscale = pnmimage.is_grayscale(); bool is_grayscale = pnmimage.is_grayscale();
@ -371,7 +371,7 @@ store(PNMImage &pnmimage) const {
return true; return true;
} else if (_type == T_unsigned_short) { } else if (_type == T_unsigned_short) {
pnmimage.clear(_xsize, _ysize, _components, 65535); pnmimage.clear(_xsize, _ysize, _num_components, 65535);
bool has_alpha = pnmimage.has_alpha(); bool has_alpha = pnmimage.has_alpha();
bool is_grayscale = pnmimage.is_grayscale(); bool is_grayscale = pnmimage.is_grayscale();
@ -411,7 +411,8 @@ copy(const PixelBuffer *pb) {
_xsize = pb->_xsize; _xsize = pb->_xsize;
_ysize = pb->_ysize; _ysize = pb->_ysize;
_border = pb->_border; _border = pb->_border;
_components = pb->_components; _num_components = pb->_num_components;
_component_width = pb->_component_width;
_format = pb->_format; _format = pb->_format;
_image = PTA_uchar::empty_array(0); _image = PTA_uchar::empty_array(0);
if (!pb->_image.empty()) if (!pb->_image.empty())

View File

@ -17,33 +17,24 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#ifndef PIXELBUFFER_H #ifndef PIXELBUFFER_H
#define PIXELBUFFER_H #define PIXELBUFFER_H
//
//////////////////////////////////////////////////////////////////// #include "pandabase.h"
// Includes
////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include "imageBuffer.h" #include "imageBuffer.h"
#include <pnmImage.h> #include "pnmImage.h"
#include <graphicsStateGuardianBase.h> #include "graphicsStateGuardianBase.h"
#include <pta_uchar.h> #include "pta_uchar.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
class RenderBuffer; class RenderBuffer;
class Filename; class Filename;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : PixelBuffer // Class : PixelBuffer
// Description : // Description : Maintains an array of pixel data corresponding to an
// Maintains an array of pixel data corresponding to an
// image, e.g. copied from the frame buffer, or as part // image, e.g. copied from the frame buffer, or as part
// of a Texture. // of a Texture.
//
// Pixel data is stored in a generic, uncompressed // Pixel data is stored in a generic, uncompressed
// format. Each row of pixels is laid out horizontally, // format. Each row of pixels is laid out horizontally,
// from the top to the bottom, with no padding between // from the top to the bottom, with no padding between
@ -124,6 +115,8 @@ public:
INLINE void set_xorg(int org); INLINE void set_xorg(int org);
INLINE void set_yorg(int org); INLINE void set_yorg(int org);
INLINE void set_size(int x_org, int y_org, int x_size, int y_size); INLINE void set_size(int x_org, int y_org, int x_size, int y_size);
INLINE void set_num_components(int num_components);
INLINE void set_component_width(int component_width);
INLINE void set_format(Format format); INLINE void set_format(Format format);
INLINE void set_loaded(); INLINE void set_loaded();
@ -178,7 +171,7 @@ protected:
int _xorg; int _xorg;
int _yorg; int _yorg;
int _border; int _border;
int _components; int _num_components;
int _component_width; int _component_width;
Format _format; Format _format;
Type _type; Type _type;

View File

@ -830,11 +830,15 @@ fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) {
if (_pbuffer != (PixelBuffer *)NULL) { if (_pbuffer != (PixelBuffer *)NULL) {
if (num_channels == _pbuffer->get_num_components()) { if (num_channels == _pbuffer->get_num_components()) {
// Only reset the format if the number of components hasn't // Only reset the format if the number of components hasn't
// changed. // changed, since if the number of components has changed our
// texture no longer matches what it was when the bam was
// written.
_pbuffer->set_format(format); _pbuffer->set_format(format);
} }
if (has_rawdata) { if (has_rawdata) {
// In the rawdata case, we must always set the format.
_pbuffer->set_format(format);
_pbuffer->set_xsize(scan.get_int32()); _pbuffer->set_xsize(scan.get_int32());
_pbuffer->set_ysize(scan.get_int32()); _pbuffer->set_ysize(scan.get_int32());
_pbuffer->set_xorg(scan.get_int32()); _pbuffer->set_xorg(scan.get_int32());