mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
image comment
This commit is contained in:
parent
bd97d329c4
commit
85d75121c4
@ -1574,7 +1574,8 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
self.camFrustumVis.removeNode()
|
self.camFrustumVis.removeNode()
|
||||||
|
|
||||||
def screenshot(self, namePrefix = 'screenshot',
|
def screenshot(self, namePrefix = 'screenshot',
|
||||||
defaultFilename = 1, source = None):
|
defaultFilename = 1, source = None,
|
||||||
|
imageComment=""):
|
||||||
""" Captures a screenshot from the main window or from the
|
""" Captures a screenshot from the main window or from the
|
||||||
specified window or Texture and writes it to a filename in the
|
specified window or Texture and writes it to a filename in the
|
||||||
current directory (or to a specified directory).
|
current directory (or to a specified directory).
|
||||||
@ -1610,7 +1611,7 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
else:
|
else:
|
||||||
saved = source.write(filename)
|
saved = source.write(filename)
|
||||||
else:
|
else:
|
||||||
saved = source.saveScreenshot(filename)
|
saved = source.saveScreenshot(filename, imageComment)
|
||||||
|
|
||||||
# Announce to anybody that a screenshot has been taken
|
# Announce to anybody that a screenshot has been taken
|
||||||
messenger.send('screenshot', [filename])
|
messenger.send('screenshot', [filename])
|
||||||
|
@ -611,12 +611,13 @@ save_screenshot_default(const string &prefix) {
|
|||||||
// filename. Returns true on success, false on failure.
|
// filename. Returns true on success, false on failure.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool DisplayRegion::
|
bool DisplayRegion::
|
||||||
save_screenshot(const Filename &filename) {
|
save_screenshot(const Filename &filename, const string &image_comment) {
|
||||||
PNMImage image;
|
PNMImage image;
|
||||||
if (!get_screenshot(image)) {
|
if (!get_screenshot(image)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image.set_comment(image_comment);
|
||||||
if (!image.write(filename)) {
|
if (!image.write(filename)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -111,13 +111,16 @@ PUBLISHED:
|
|||||||
|
|
||||||
void output(ostream &out) const;
|
void output(ostream &out) const;
|
||||||
|
|
||||||
static Filename make_screenshot_filename(const string &prefix = "screenshot");
|
static Filename make_screenshot_filename(
|
||||||
|
const string &prefix = "screenshot");
|
||||||
Filename save_screenshot_default(const string &prefix = "screenshot");
|
Filename save_screenshot_default(const string &prefix = "screenshot");
|
||||||
bool save_screenshot(const Filename &filename);
|
bool save_screenshot(
|
||||||
|
const Filename &filename, const string &image_comment = "");
|
||||||
bool get_screenshot(PNMImage &image);
|
bool get_screenshot(PNMImage &image);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
INLINE void set_cull_result(CullResult *cull_result, SceneSetup *scene_setup);
|
INLINE void set_cull_result(
|
||||||
|
CullResult *cull_result, SceneSetup *scene_setup);
|
||||||
INLINE CullResult *get_cull_result() const;
|
INLINE CullResult *get_cull_result() const;
|
||||||
INLINE SceneSetup *get_scene_setup() const;
|
INLINE SceneSetup *get_scene_setup() const;
|
||||||
|
|
||||||
|
@ -423,11 +423,15 @@ save_screenshot_default(const string &prefix) {
|
|||||||
// Function: GraphicsOutput::save_screenshot
|
// Function: GraphicsOutput::save_screenshot
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Saves a screenshot of the region to the indicated
|
// Description: Saves a screenshot of the region to the indicated
|
||||||
// filename. Returns true on success, false on failure.
|
// filename. The image comment is an optional user
|
||||||
|
// readable string that will be saved with the header
|
||||||
|
// of the image (if the file format supports embedded
|
||||||
|
// data; for example jpg allows comments). Returns
|
||||||
|
// true on success, false on failure.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE bool GraphicsOutput::
|
INLINE bool GraphicsOutput::
|
||||||
save_screenshot(const Filename &filename) {
|
save_screenshot(const Filename &filename, const string &image_comment) {
|
||||||
return _default_display_region->save_screenshot(filename);
|
return _default_display_region->save_screenshot(filename, image_comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -145,16 +145,20 @@ PUBLISHED:
|
|||||||
int get_num_active_display_regions() const;
|
int get_num_active_display_regions() const;
|
||||||
PT(DisplayRegion) get_active_display_region(int n) const;
|
PT(DisplayRegion) get_active_display_region(int n) const;
|
||||||
|
|
||||||
GraphicsOutput *make_texture_buffer(const string &name, int x_size, int y_size,
|
GraphicsOutput *make_texture_buffer(
|
||||||
Texture *tex = NULL, bool to_ram = false);
|
const string &name, int x_size, int y_size,
|
||||||
|
Texture *tex = NULL, bool to_ram = false);
|
||||||
GraphicsOutput *make_cube_map(const string &name, int size,
|
GraphicsOutput *make_cube_map(const string &name, int size,
|
||||||
NodePath &camera_rig,
|
NodePath &camera_rig,
|
||||||
DrawMask camera_mask = DrawMask::all_on(),
|
DrawMask camera_mask = DrawMask::all_on(),
|
||||||
bool to_ram = false);
|
bool to_ram = false);
|
||||||
|
|
||||||
INLINE static Filename make_screenshot_filename(const string &prefix = "screenshot");
|
INLINE static Filename make_screenshot_filename(
|
||||||
INLINE Filename save_screenshot_default(const string &prefix = "screenshot");
|
const string &prefix = "screenshot");
|
||||||
INLINE bool save_screenshot(const Filename &filename);
|
INLINE Filename save_screenshot_default(
|
||||||
|
const string &prefix = "screenshot");
|
||||||
|
INLINE bool save_screenshot(
|
||||||
|
const Filename &filename, const string &image_comment);
|
||||||
INLINE bool get_screenshot(PNMImage &image);
|
INLINE bool get_screenshot(PNMImage &image);
|
||||||
|
|
||||||
NodePath get_texture_card();
|
NodePath get_texture_card();
|
||||||
|
@ -41,6 +41,7 @@ clear() {
|
|||||||
_y_size = 0;
|
_y_size = 0;
|
||||||
_num_channels = 0;
|
_num_channels = 0;
|
||||||
_maxval = 255;
|
_maxval = 255;
|
||||||
|
_comment.clear();
|
||||||
_type = (PNMFileType *)NULL;
|
_type = (PNMFileType *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ clear(int x_size, int y_size, int num_channels,
|
|||||||
_y_size = y_size;
|
_y_size = y_size;
|
||||||
_num_channels = num_channels;
|
_num_channels = num_channels;
|
||||||
_maxval = maxval;
|
_maxval = maxval;
|
||||||
|
_comment.clear();
|
||||||
_type = type;
|
_type = type;
|
||||||
|
|
||||||
if (has_alpha()) {
|
if (has_alpha()) {
|
||||||
|
@ -56,6 +56,7 @@ operator = (const PNMImageHeader ©) {
|
|||||||
_y_size = copy._y_size;
|
_y_size = copy._y_size;
|
||||||
_num_channels = copy._num_channels;
|
_num_channels = copy._num_channels;
|
||||||
_maxval = copy._maxval;
|
_maxval = copy._maxval;
|
||||||
|
_comment = copy._comment;
|
||||||
_type = copy._type;
|
_type = copy._type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +181,26 @@ get_y_size() const {
|
|||||||
return _y_size;
|
return _y_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImageHeader::get_comment
|
||||||
|
// Access: Published
|
||||||
|
// Description: Gets the user comment from the file.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE string PNMImageHeader::
|
||||||
|
get_comment() const {
|
||||||
|
return _comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImageHeader::set_comment
|
||||||
|
// Access: Published
|
||||||
|
// Description: Writes a user comment string to the image (header).
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE void PNMImageHeader::
|
||||||
|
set_comment(const string& comment) {
|
||||||
|
_comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PNMImageHeader::has_type
|
// Function: PNMImageHeader::has_type
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -72,6 +72,9 @@ PUBLISHED:
|
|||||||
INLINE int get_x_size() const;
|
INLINE int get_x_size() const;
|
||||||
INLINE int get_y_size() const;
|
INLINE int get_y_size() const;
|
||||||
|
|
||||||
|
INLINE string get_comment() const;
|
||||||
|
INLINE void set_comment(const string &comment);
|
||||||
|
|
||||||
INLINE bool has_type() const;
|
INLINE bool has_type() const;
|
||||||
INLINE PNMFileType *get_type() const;
|
INLINE PNMFileType *get_type() const;
|
||||||
INLINE void set_type(PNMFileType *type);
|
INLINE void set_type(PNMFileType *type);
|
||||||
@ -128,6 +131,7 @@ protected:
|
|||||||
int _x_size, _y_size;
|
int _x_size, _y_size;
|
||||||
int _num_channels;
|
int _num_channels;
|
||||||
xelval _maxval;
|
xelval _maxval;
|
||||||
|
string _comment;
|
||||||
PNMFileType *_type;
|
PNMFileType *_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
|
|||||||
// Hope we can putback() more than one character.
|
// Hope we can putback() more than one character.
|
||||||
for (string::reverse_iterator mi = magic_number.rbegin();
|
for (string::reverse_iterator mi = magic_number.rbegin();
|
||||||
mi != magic_number.rend();
|
mi != magic_number.rend();
|
||||||
mi++) {
|
++mi) {
|
||||||
_file->putback(*mi);
|
_file->putback(*mi);
|
||||||
}
|
}
|
||||||
if (_file->fail()) {
|
if (_file->fail()) {
|
||||||
@ -284,8 +284,10 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
|
|||||||
/* Step 2: specify data source (eg, a file) */
|
/* Step 2: specify data source (eg, a file) */
|
||||||
jpeg_istream_src(&_cinfo, file);
|
jpeg_istream_src(&_cinfo, file);
|
||||||
|
|
||||||
/* Step 3: read file parameters with jpeg_read_header() */
|
/* Step 3: let lib jpeg know that we want to read the comment field */
|
||||||
|
jpeg_save_markers(&_cinfo, JPEG_COM, 0xffff);
|
||||||
|
|
||||||
|
/* Step 4: read file parameters with jpeg_read_header() */
|
||||||
jpeg_read_header(&_cinfo, TRUE);
|
jpeg_read_header(&_cinfo, TRUE);
|
||||||
/* We can ignore the return value from jpeg_read_header since
|
/* We can ignore the return value from jpeg_read_header since
|
||||||
* (a) suspension is not possible with the stdio data source, and
|
* (a) suspension is not possible with the stdio data source, and
|
||||||
@ -293,11 +295,11 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
|
|||||||
* See libjpeg.doc for more info.
|
* See libjpeg.doc for more info.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Step 4: set parameters for decompression */
|
/* Step 6: set parameters for decompression */
|
||||||
_cinfo.scale_num = jpeg_scale_num;
|
_cinfo.scale_num = jpeg_scale_num;
|
||||||
_cinfo.scale_denom = jpeg_scale_denom;
|
_cinfo.scale_denom = jpeg_scale_denom;
|
||||||
|
|
||||||
/* Step 5: Start decompressor */
|
/* Step 7: Start decompressor */
|
||||||
|
|
||||||
jpeg_start_decompress(&_cinfo);
|
jpeg_start_decompress(&_cinfo);
|
||||||
/* We can ignore the return value since suspension is not possible
|
/* We can ignore the return value since suspension is not possible
|
||||||
|
@ -201,7 +201,6 @@ Writer(PNMFileType *type, ostream *file, bool owns_file) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PNMFileTypeJPG::Writer::write_data
|
// Function: PNMFileTypeJPG::Writer::write_data
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
@ -297,6 +296,12 @@ write_data(xel *array, xelval *) {
|
|||||||
*/
|
*/
|
||||||
jpeg_start_compress(&cinfo, TRUE);
|
jpeg_start_compress(&cinfo, TRUE);
|
||||||
|
|
||||||
|
/* Write the user comment, if any */
|
||||||
|
if (_comment.size()) {
|
||||||
|
jpeg_write_marker(
|
||||||
|
&cinfo, JPEG_COM, (JOCTET *)_comment.c_str(), strlen(_comment.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
/* Step 5: while (scan lines remain to be written) */
|
/* Step 5: while (scan lines remain to be written) */
|
||||||
/* jpeg_write_scanlines(...); */
|
/* jpeg_write_scanlines(...); */
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ output_screenshot(Filename &fn)
|
|||||||
framework.do_frame();
|
framework.do_frame();
|
||||||
|
|
||||||
WindowFramework *wf = framework.get_window(0);
|
WindowFramework *wf = framework.get_window(0);
|
||||||
bool ok = wf->get_graphics_window()->save_screenshot(fn);
|
bool ok = wf->get_graphics_window()->save_screenshot(fn, "from pview");
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
cerr << "Could not generate screenshot " << fn << "\n";
|
cerr << "Could not generate screenshot " << fn << "\n";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user