Panda3D
Loading...
Searching...
No Matches
pnmWriter.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pnmWriter.cxx
10 * @author drose
11 * @date 2000-06-14
12 */
13
14#include "pnmWriter.h"
15#include "thread.h"
16
17/**
18 *
19 */
20PNMWriter::
21~PNMWriter() {
22 if (_owns_file) {
23 delete _file;
24 }
25 _file = nullptr;
26}
27
28/**
29 * Returns true if this PNMFileType can accept a floating-point image type,
30 * false if it can only accept a normal, integer type. If this returns true,
31 * write_pfm() is implemented.
32 */
35 return false;
36}
37
38/**
39 * Returns true if this PNMFileType can accept an integer image type, false if
40 * it can only accept a floating-point type. If this returns true,
41 * write_data() or write_row() is implemented.
42 */
45 return true;
46}
47
48/**
49 * Writes floating-point data from the indicated PfmFile. Returns true on
50 * success, false on failure.
51 */
53write_pfm(const PfmFile &pfm) {
54 return false;
55}
56
57/**
58 * Writes out an entire image all at once, including the header, based on the
59 * image data stored in the given _x_size * _y_size array and alpha pointers.
60 * (If the image type has no alpha channel, alpha is ignored.) Returns the
61 * number of rows correctly written.
62 *
63 * It is the user's responsibility to fill in the header data via calls to
64 * set_x_size(), set_num_channels(), etc., or copy_header_from(), before
65 * calling write_data().
66 *
67 * It is important to delete the PNMWriter class after successfully writing
68 * the data. Failing to do this may result in some data not getting flushed!
69 *
70 * Derived classes need not override this if they instead provide
71 * supports_streaming() and write_row(), below.
72 */
74write_data(xel *array, xelval *alpha) {
75 if (_x_size <= 0 || _y_size <= 0) {
76 return 0;
77 }
78
79 if (!write_header()) {
80 return 0;
81 }
82
83 int y;
84 for (y = 0; y < _y_size; y++) {
85 if (!write_row(array + y * _x_size, alpha + y * _x_size)) {
87 return y;
88 }
89 }
90
91 return _y_size;
92}
93
94/**
95 * Returns true if this particular PNMWriter supports a streaming interface to
96 * writing the data: that is, it is capable of writing the image one row at a
97 * time, via repeated calls to write_row(). Returns false if the only way to
98 * write from this file is all at once, via write_data().
99 */
101supports_write_row() const {
102 return false;
103}
104
105/**
106 * Returns true if this particular PNMWriter understands grayscale images. If
107 * this is false, then the rgb values of the xel array will be pre-filled with
108 * the same value across all three channels, to allow the writer to simply
109 * write out RGB data for a grayscale image.
110 */
112supports_grayscale() const {
113 return true;
114}
115
116/**
117 * If supports_write_row(), above, returns true, this function may be called
118 * to write out the image header in preparation to writing out the image data
119 * one row at a time. Returns true if the header is successfully written,
120 * false if there is an error.
121 *
122 * It is the user's responsibility to fill in the header data via calls to
123 * set_x_size(), set_num_channels(), etc., or copy_header_from(), before
124 * calling write_header().
125 */
127write_header() {
128 return false;
129}
130
131/**
132 * If supports_write_row(), above, returns true, this function may be called
133 * repeatedly to write the image, one horizontal row at a time, beginning from
134 * the top. Returns true if the row is successfully written, false if there
135 * is an error.
136 *
137 * You must first call write_header() before writing the individual rows. It
138 * is also important to delete the PNMWriter class after successfully writing
139 * the last row. Failing to do this may result in some data not getting
140 * flushed!
141 */
143write_row(xel *, xelval *) {
144 return false;
145}
146
147/**
148 * Returns true if this particular PNMWriter can write to a general stream
149 * (including pipes, etc.), or false if the writer must occasionally fseek()
150 * on its output stream, and thus only disk streams are supported.
151 */
153supports_stream_write() const {
154 return false;
155}
virtual int write_data(xel *array, xelval *alpha)
Writes out an entire image all at once, including the header, based on the image data stored in the g...
Definition pnmWriter.cxx:74
virtual bool write_header()
If supports_write_row(), above, returns true, this function may be called to write out the image head...
virtual bool supports_write_row() const
Returns true if this particular PNMWriter supports a streaming interface to writing the data: that is...
virtual bool write_pfm(const PfmFile &pfm)
Writes floating-point data from the indicated PfmFile.
Definition pnmWriter.cxx:53
virtual bool supports_stream_write() const
Returns true if this particular PNMWriter can write to a general stream (including pipes,...
virtual bool write_row(xel *array, xelval *alpha)
If supports_write_row(), above, returns true, this function may be called repeatedly to write the ima...
virtual bool supports_grayscale() const
Returns true if this particular PNMWriter understands grayscale images.
virtual bool supports_floating_point()
Returns true if this PNMFileType can accept a floating-point image type, false if it can only accept ...
Definition pnmWriter.cxx:34
virtual bool supports_integer()
Returns true if this PNMFileType can accept an integer image type, false if it can only accept a floa...
Definition pnmWriter.cxx:44
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component,...
Definition pfmFile.h:31
static void consider_yield()
Possibly suspends the current thread for the rest of the current epoch, if it has run for enough this...
Definition thread.I:212
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.