Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pnmimage/pnmImage.I

Go to the documentation of this file.
00001 // Filename: pnmImage.I
00002 // Created by:  drose (15Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: PNMImage::Constructor
00021 //       Access: Public
00022 //  Description:
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE PNMImage::
00025 PNMImage() {
00026   _array = NULL;
00027   _alpha = NULL;
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: PNMImage::Constructor
00032 //       Access: Public
00033 //  Description:
00034 ////////////////////////////////////////////////////////////////////
00035 INLINE PNMImage::
00036 PNMImage(const Filename &filename, PNMFileType *type) {
00037   _array = NULL;
00038   _alpha = NULL;
00039 
00040   read(filename, type);
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: PNMImage::Constructor
00045 //       Access: Public
00046 //  Description:
00047 ////////////////////////////////////////////////////////////////////
00048 INLINE PNMImage::
00049 PNMImage(int x_size, int y_size, int num_channels, xelval maxval,
00050          PNMFileType *type) {
00051   _array = NULL;
00052   _alpha = NULL;
00053 
00054   clear(x_size, y_size, num_channels, maxval, type);
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: PNMImage::Copy Constructor
00059 //       Access: Public
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 INLINE PNMImage::
00063 PNMImage(const PNMImage &copy) {
00064   // We don't need to invoke PNMImageHeader's copy constructor,
00065   // because we'll just call copy_from().
00066   _array = NULL;
00067   _alpha = NULL;
00068 
00069   copy_from(copy);
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: PNMImage::Copy Assigment Operator
00074 //       Access: Public
00075 //  Description:
00076 ////////////////////////////////////////////////////////////////////
00077 INLINE void PNMImage::
00078 operator = (const PNMImage &copy) {
00079   copy_from(copy);
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: PNMImage::Destructor
00084 //       Access: Public
00085 //  Description:
00086 ////////////////////////////////////////////////////////////////////
00087 INLINE PNMImage::
00088 ~PNMImage() {
00089   clear();
00090 }
00091 
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: PNMImage::clamp_val
00095 //       Access: Public
00096 //  Description: A handy function to clamp values to
00097 //               [0..get_maxval()].
00098 ////////////////////////////////////////////////////////////////////
00099 INLINE xelval PNMImage::
00100 clamp_val(int input_value) const {
00101   return (xelval)min(max(0, input_value), (int)get_maxval());
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: PNMImage::to_val
00106 //       Access: Public
00107 //  Description: A handy function to scale values from [0..1] to
00108 //               [0..get_maxval()].
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE xelval PNMImage::
00111 to_val(double input_value) const {
00112   return clamp_val((int)(input_value * get_maxval() + 0.5));
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: PNMImage::from_val
00117 //       Access: Public
00118 //  Description: A handy function to scale values from
00119 //               [0..get_maxval()] to [0..1].
00120 ////////////////////////////////////////////////////////////////////
00121 INLINE double PNMImage::
00122 from_val(xelval input_value) const {
00123   return (double)input_value / (double)get_maxval();
00124 }
00125 
00126 ////////////////////////////////////////////////////////////////////
00127 //     Function: PNMImage::fill
00128 //       Access: Public
00129 //  Description: Sets the entire image (except the alpha channel) to
00130 //               the given color.
00131 ////////////////////////////////////////////////////////////////////
00132 INLINE void PNMImage::
00133 fill(double red, double green, double blue) {
00134   fill_val((xelval)(red * get_maxval()),
00135            (xelval)(green * get_maxval()),
00136            (xelval)(blue * get_maxval()));
00137 }
00138 
00139 ////////////////////////////////////////////////////////////////////
00140 //     Function: PNMImage::fill
00141 //       Access: Public
00142 //  Description: Sets the entire image (except the alpha channel) to
00143 //               the given grayscale level.
00144 ////////////////////////////////////////////////////////////////////
00145 INLINE void PNMImage::
00146 fill(double gray) {
00147   fill(gray, gray, gray);
00148 }
00149 
00150 ////////////////////////////////////////////////////////////////////
00151 //     Function: PNMImage::fill_val
00152 //       Access: Public
00153 //  Description: Sets the entire image (except the alpha channel) to
00154 //               the given grayscale level.
00155 ////////////////////////////////////////////////////////////////////
00156 INLINE void PNMImage::
00157 fill_val(xelval gray) {
00158   fill_val(gray, gray, gray);
00159 }
00160 
00161 ////////////////////////////////////////////////////////////////////
00162 //     Function: PNMImage::alpha_fill
00163 //       Access: Public
00164 //  Description: Sets the entire alpha channel to the given level.
00165 ////////////////////////////////////////////////////////////////////
00166 INLINE void PNMImage::
00167 alpha_fill(double alpha) {
00168   alpha_fill_val((xelval)(alpha * get_maxval()));
00169 }
00170 
00171 ////////////////////////////////////////////////////////////////////
00172 //     Function: PNMImage::is_valid
00173 //       Access: Public
00174 //  Description: Returns true if the image has been read in or
00175 //               correctly initialized with a height and width.  If
00176 //               this returns false, virtually all member functions
00177 //               except clear() and read() are invalid function calls.
00178 ////////////////////////////////////////////////////////////////////
00179 INLINE bool PNMImage::
00180 is_valid() const {
00181   return (_array != NULL);
00182 }
00183 
00184 ////////////////////////////////////////////////////////////////////
00185 //     Function: PNMImage::set_num_channels
00186 //       Access: Public
00187 //  Description: Changes the number of channels associated with the
00188 //               image.  The new number of channels must be an integer
00189 //               in the range 1 through 4, inclusive.  This will
00190 //               allocate and/or deallocate memory as necessary to
00191 //               accomodate; see set_color_type().
00192 ////////////////////////////////////////////////////////////////////
00193 INLINE void PNMImage::
00194 set_num_channels(int num_channels) {
00195   nassertv(num_channels >= 1 && num_channels <= 4);
00196   set_color_type((ColorType)num_channels);
00197 }
00198 
00199 ////////////////////////////////////////////////////////////////////
00200 //     Function: PNMImage::add_alpha
00201 //       Access: Public
00202 //  Description: Adds an alpha channel to the image, if it does not
00203 //               already have one.  The alpha channel is initialized
00204 //               to zeros.
00205 ////////////////////////////////////////////////////////////////////
00206 INLINE void PNMImage::
00207 add_alpha() {
00208   set_color_type(is_grayscale() ? CT_two_channel : CT_four_channel);
00209 }
00210 
00211 ////////////////////////////////////////////////////////////////////
00212 //     Function: PNMImage::remove_alpha
00213 //       Access: Public
00214 //  Description: Removes the image's alpha channel, if it exists.
00215 ////////////////////////////////////////////////////////////////////
00216 INLINE void PNMImage::
00217 remove_alpha() {
00218   set_color_type(is_grayscale() ? CT_grayscale : CT_color);
00219 }
00220 
00221 ////////////////////////////////////////////////////////////////////
00222 //     Function: PNMImage::make_grayscale
00223 //       Access: Public
00224 //  Description: Converts the image from RGB to grayscale.  Any alpha
00225 //               channel, if present, is left undisturbed.
00226 ////////////////////////////////////////////////////////////////////
00227 INLINE void PNMImage::
00228 make_grayscale() {
00229   make_grayscale(_default_rc, _default_gc, _default_bc);
00230 }
00231 
00232 ////////////////////////////////////////////////////////////////////
00233 //     Function: PNMImage::make_rgb
00234 //       Access: Public
00235 //  Description: Converts the image from grayscale to RGB.  Any alpha
00236 //               channel, if present, is left undisturbed.
00237 ////////////////////////////////////////////////////////////////////
00238 INLINE void PNMImage::
00239 make_rgb() {
00240   set_color_type(has_alpha() ? CT_four_channel : CT_color);
00241 }
00242 
00243 ////////////////////////////////////////////////////////////////////
00244 //     Function: PNMImage::get_xel_val
00245 //       Access: Public
00246 //  Description: Returns the RGB color at the indicated pixel.  Each
00247 //               component is in the range 0..maxval.
00248 ////////////////////////////////////////////////////////////////////
00249 INLINE const xel &PNMImage::
00250 get_xel_val(int x, int y) const {
00251   return row(y)[x];
00252 }
00253 
00254 ////////////////////////////////////////////////////////////////////
00255 //     Function: PNMImage::set_xel_val
00256 //       Access: Public
00257 //  Description: Changes the RGB color at the indicated pixel.  Each
00258 //               component is in the range 0..maxval.
00259 ////////////////////////////////////////////////////////////////////
00260 INLINE void PNMImage::
00261 set_xel_val(int x, int y, const xel &value) {
00262   row(y)[x] = value;
00263 }
00264 
00265 ////////////////////////////////////////////////////////////////////
00266 //     Function: PNMImage::set_xel_val
00267 //       Access: Public
00268 //  Description: Changes the RGB color at the indicated pixel.  Each
00269 //               component is in the range 0..maxval.
00270 ////////////////////////////////////////////////////////////////////
00271 INLINE void PNMImage::
00272 set_xel_val(int x, int y, xelval r, xelval g, xelval b) {
00273   PPM_ASSIGN(row(y)[x], r, g, b);
00274 }
00275 
00276 ////////////////////////////////////////////////////////////////////
00277 //     Function: PNMImage::set_xel_val
00278 //       Access: Public
00279 //  Description: Changes all three color components at the indicated
00280 //               pixel to the same value.  The value is in the range
00281 //               0..maxval.
00282 ////////////////////////////////////////////////////////////////////
00283 INLINE void PNMImage::
00284 set_xel_val(int x, int y, xelval gray) {
00285   PPM_ASSIGN(row(y)[x], gray, gray, gray);
00286 }
00287 
00288 ////////////////////////////////////////////////////////////////////
00289 //     Function: PNMImage::get_red_val
00290 //       Access: Public
00291 //  Description: Returns the red component color at the indicated
00292 //               pixel.  The value returned is in the range 0..maxval.
00293 ////////////////////////////////////////////////////////////////////
00294 INLINE xelval PNMImage::
00295 get_red_val(int x, int y) const {
00296   return PPM_GETR(get_xel_val(x, y));
00297 }
00298 
00299 ////////////////////////////////////////////////////////////////////
00300 //     Function: PNMImage::get_green_val
00301 //       Access: Public
00302 //  Description: Returns the green component color at the indicated
00303 //               pixel.  The value returned is in the range 0..maxval.
00304 ////////////////////////////////////////////////////////////////////
00305 INLINE xelval PNMImage::
00306 get_green_val(int x, int y) const {
00307   return PPM_GETG(get_xel_val(x, y));
00308 }
00309 
00310 ////////////////////////////////////////////////////////////////////
00311 //     Function: PNMImage::get_blue_val
00312 //       Access: Public
00313 //  Description: Returns the blue component color at the indicated
00314 //               pixel.  The value returned is in the range 0..maxval.
00315 ////////////////////////////////////////////////////////////////////
00316 INLINE xelval PNMImage::
00317 get_blue_val(int x, int y) const {
00318   return PPM_GETB(get_xel_val(x, y));
00319 }
00320 
00321 ////////////////////////////////////////////////////////////////////
00322 //     Function: PNMImage::get_gray_val
00323 //       Access: Public
00324 //  Description: Returns the gray component color at the indicated
00325 //               pixel.  This only has a meaningful value for
00326 //               grayscale images; for other image types, this returns
00327 //               the value of the blue channel only.  However, also
00328 //               see the get_bright() function.  The value returned is
00329 //               in the range 0..maxval.
00330 ////////////////////////////////////////////////////////////////////
00331 INLINE xelval PNMImage::
00332 get_gray_val(int x, int y) const {
00333   return PPM_GETB(get_xel_val(x, y));
00334 }
00335 
00336 ////////////////////////////////////////////////////////////////////
00337 //     Function: PNMImage::get_alpha_val
00338 //       Access: Public
00339 //  Description: Returns the alpha component color at the indicated
00340 //               pixel.  It is an error to call this unless
00341 //               has_alpha() is true.  The value returned is in the
00342 //               range 0..maxval.
00343 ////////////////////////////////////////////////////////////////////
00344 INLINE xelval PNMImage::
00345 get_alpha_val(int x, int y) const {
00346   return alpha_row(y)[x];
00347 }
00348 
00349 ////////////////////////////////////////////////////////////////////
00350 //     Function: PNMImage::set_red_val
00351 //       Access: Public
00352 //  Description: Sets the red component color only at the indicated
00353 //               pixel.  The value given should be in the range
00354 //               0..maxval.
00355 ////////////////////////////////////////////////////////////////////
00356 INLINE void PNMImage::
00357 set_red_val(int x, int y, xelval r) {
00358   PPM_PUTR(row(y)[x], r);
00359 }
00360 
00361 ////////////////////////////////////////////////////////////////////
00362 //     Function: PNMImage::set_green_val
00363 //       Access: Public
00364 //  Description: Sets the green component color only at the indicated
00365 //               pixel.  The value given should be in the range
00366 //               0..maxval.
00367 ////////////////////////////////////////////////////////////////////
00368 INLINE void PNMImage::
00369 set_green_val(int x, int y, xelval g) {
00370   PPM_PUTG(row(y)[x], g);
00371 }
00372 
00373 ////////////////////////////////////////////////////////////////////
00374 //     Function: PNMImage::set_blue_val
00375 //       Access: Public
00376 //  Description: Sets the blue component color only at the indicated
00377 //               pixel.  The value given should be in the range
00378 //               0..maxval.
00379 ////////////////////////////////////////////////////////////////////
00380 INLINE void PNMImage::
00381 set_blue_val(int x, int y, xelval b) {
00382   PPM_PUTB(row(y)[x], b);
00383 }
00384 
00385 ////////////////////////////////////////////////////////////////////
00386 //     Function: PNMImage::set_gray_val
00387 //       Access: Public
00388 //  Description: Sets the gray component color at the indicated
00389 //               pixel.  This is only meaningful for grayscale images;
00390 //               for other image types, this simply sets the blue
00391 //               component color.  However, also see set_xel_val(),
00392 //               which can set all the component colors to the same
00393 //               grayscale level, and hence works correctly both for
00394 //               grayscale and color images.  The value given should
00395 //               be in the range 0..maxval.
00396 ////////////////////////////////////////////////////////////////////
00397 INLINE void PNMImage::
00398 set_gray_val(int x, int y, xelval gray) {
00399   PPM_PUTB(row(y)[x], gray);
00400 }
00401 
00402 ////////////////////////////////////////////////////////////////////
00403 //     Function: PNMImage::set_alpha_val
00404 //       Access: Public
00405 //  Description: Sets the alpha component color only at the indicated
00406 //               pixel.  It is an error to call this unless
00407 //               has_alpha() is true.  The value given should be in
00408 //               the range 0..maxval.
00409 ////////////////////////////////////////////////////////////////////
00410 INLINE void PNMImage::
00411 set_alpha_val(int x, int y, xelval a) {
00412   alpha_row(y)[x] = a;
00413 }
00414 
00415 ////////////////////////////////////////////////////////////////////
00416 //     Function: PNMImage::get_xel
00417 //       Access: Public
00418 //  Description: Returns the RGB color at the indicated pixel.  Each
00419 //               component is a double in the range 0..1.
00420 ////////////////////////////////////////////////////////////////////
00421 INLINE RGBColord PNMImage::
00422 get_xel(int x, int y) const {
00423   return RGBColord(from_val(get_red_val(x, y)),
00424                    from_val(get_green_val(x, y)),
00425                    from_val(get_blue_val(x, y)));
00426 }
00427 
00428 ////////////////////////////////////////////////////////////////////
00429 //     Function: PNMImage::set_xel
00430 //       Access: Public
00431 //  Description: Changes the RGB color at the indicated pixel.  Each
00432 //               component is a double in the range 0..1.
00433 ////////////////////////////////////////////////////////////////////
00434 INLINE void PNMImage::
00435 set_xel(int x, int y, const RGBColord &value) {
00436   set_xel_val(x, y, to_val(value[0]), to_val(value[1]), to_val(value[2]));
00437 }
00438 
00439 ////////////////////////////////////////////////////////////////////
00440 //     Function: PNMImage::set_xel
00441 //       Access: Public
00442 //  Description: Changes the RGB color at the indicated pixel.  Each
00443 //               component is a double in the range 0..1.
00444 ////////////////////////////////////////////////////////////////////
00445 INLINE void PNMImage::
00446 set_xel(int x, int y, double r, double g, double b) {
00447   set_xel_val(x, y, to_val(r), to_val(g), to_val(b));
00448 }
00449 
00450 ////////////////////////////////////////////////////////////////////
00451 //     Function: PNMImage::set_xel
00452 //       Access: Public
00453 //  Description: Changes all three color components at the indicated
00454 //               pixel to the same value.  The value is a double in
00455 //               the range 0..1.
00456 ////////////////////////////////////////////////////////////////////
00457 INLINE void PNMImage::
00458 set_xel(int x, int y, double gray) {
00459   set_xel_val(x, y, to_val(gray), to_val(gray), to_val(gray));
00460 }
00461 
00462 ////////////////////////////////////////////////////////////////////
00463 //     Function: PNMImage::get_red
00464 //       Access: Public
00465 //  Description: Returns the red component color at the indicated
00466 //               pixel.  The value returned is a double in the range
00467 //               0..1.
00468 ////////////////////////////////////////////////////////////////////
00469 INLINE double PNMImage::
00470 get_red(int x, int y) const {
00471   return from_val(get_red_val(x, y));
00472 }
00473 
00474 ////////////////////////////////////////////////////////////////////
00475 //     Function: PNMImage::get_green
00476 //       Access: Public
00477 //  Description: Returns the green component color at the indicated
00478 //               pixel.  The value returned is a double in the range
00479 //               0..1.
00480 ////////////////////////////////////////////////////////////////////
00481 INLINE double PNMImage::
00482 get_green(int x, int y) const {
00483   return from_val(get_green_val(x, y));
00484 }
00485 
00486 ////////////////////////////////////////////////////////////////////
00487 //     Function: PNMImage::get_blue
00488 //       Access: Public
00489 //  Description: Returns the blue component color at the indicated
00490 //               pixel.  The value returned is a double in the range
00491 //               0..1.
00492 ////////////////////////////////////////////////////////////////////
00493 INLINE double PNMImage::
00494 get_blue(int x, int y) const {
00495   return from_val(get_blue_val(x, y));
00496 }
00497 
00498 ////////////////////////////////////////////////////////////////////
00499 //     Function: PNMImage::get_gray
00500 //       Access: Public
00501 //  Description: Returns the gray component color at the indicated
00502 //               pixel.  This only has a meaningful value for
00503 //               grayscale images; for other image types, this returns
00504 //               the value of the blue channel only.  However, also
00505 //               see the get_bright() function.  The value returned is
00506 //               a double in the range 0..1.
00507 ////////////////////////////////////////////////////////////////////
00508 INLINE double PNMImage::
00509 get_gray(int x, int y) const {
00510   return from_val(get_gray_val(x, y));
00511 }
00512 
00513 ////////////////////////////////////////////////////////////////////
00514 //     Function: PNMImage::get_alpha
00515 //       Access: Public
00516 //  Description: Returns the alpha component color at the indicated
00517 //               pixel.  It is an error to call this unless
00518 //               has_alpha() is true.  The value returned is a double
00519 //               in the range 0..1.
00520 ////////////////////////////////////////////////////////////////////
00521 INLINE double PNMImage::
00522 get_alpha(int x, int y) const {
00523   return from_val(get_alpha_val(x, y));
00524 }
00525 
00526 ////////////////////////////////////////////////////////////////////
00527 //     Function: PNMImage::set_red
00528 //       Access: Public
00529 //  Description: Sets the red component color only at the indicated
00530 //               pixel.  The value given should be a double in the
00531 //               range 0..1.
00532 ////////////////////////////////////////////////////////////////////
00533 INLINE void PNMImage::
00534 set_red(int x, int y, double r) {
00535   set_red_val(x, y, to_val(r));
00536 }
00537 
00538 ////////////////////////////////////////////////////////////////////
00539 //     Function: PNMImage::set_green
00540 //       Access: Public
00541 //  Description: Sets the green component color only at the indicated
00542 //               pixel.  The value given should be a double in the
00543 //               range 0..1.
00544 ////////////////////////////////////////////////////////////////////
00545 INLINE void PNMImage::
00546 set_green(int x, int y, double r) {
00547   set_green_val(x, y, to_val(r));
00548 }
00549 
00550 ////////////////////////////////////////////////////////////////////
00551 //     Function: PNMImage::set_blue
00552 //       Access: Public
00553 //  Description: Sets the blue component color only at the indicated
00554 //               pixel.  The value given should be a double in the
00555 //               range 0..1.
00556 ////////////////////////////////////////////////////////////////////
00557 INLINE void PNMImage::
00558 set_blue(int x, int y, double r) {
00559   set_blue_val(x, y, to_val(r));
00560 }
00561 
00562 ////////////////////////////////////////////////////////////////////
00563 //     Function: PNMImage::set_gray
00564 //       Access: Public
00565 //  Description: Sets the gray component color at the indicated
00566 //               pixel.  This is only meaningful for grayscale images;
00567 //               for other image types, this simply sets the blue
00568 //               component color.  However, also see set_xel(), which
00569 //               can set all the component colors to the same
00570 //               grayscale level, and hence works correctly both for
00571 //               grayscale and color images.  The value given should
00572 //               be a double in the range 0..1.
00573 ////////////////////////////////////////////////////////////////////
00574 INLINE void PNMImage::
00575 set_gray(int x, int y, double r) {
00576   set_gray_val(x, y, to_val(r));
00577 }
00578 
00579 ////////////////////////////////////////////////////////////////////
00580 //     Function: PNMImage::set_alpha
00581 //       Access: Public
00582 //  Description: Sets the alpha component color only at the indicated
00583 //               pixel.  It is an error to call this unless
00584 //               has_alpha() is true.  The value given should be in
00585 //               the range 0..1.
00586 ////////////////////////////////////////////////////////////////////
00587 INLINE void PNMImage::
00588 set_alpha(int x, int y, double r) {
00589   set_alpha_val(x, y, to_val(r));
00590 }
00591 
00592 ////////////////////////////////////////////////////////////////////
00593 //     Function: PNMImage::get_channel
00594 //       Access: Public
00595 //  Description: Returns the nth component color at the indicated
00596 //               pixel.  The channel index should be in the range
00597 //               0..(get_num_channels()-1).  The channels are ordered B,
00598 //               G, R, A.  This is slightly less optimal than
00599 //               accessing the component values directly by named
00600 //               methods.  The value returned is a double in the range
00601 //               0..1.
00602 ////////////////////////////////////////////////////////////////////
00603 INLINE double PNMImage::
00604 get_channel(int x, int y, int channel) const {
00605   return from_val(get_channel_val(x, y, channel));
00606 }
00607 
00608 ////////////////////////////////////////////////////////////////////
00609 //     Function: PNMImage::set_channel_val
00610 //       Access: Public
00611 //  Description: Sets the nth component color at the indicated
00612 //               pixel.  The channel index should be in the range
00613 //               0..(get_num_channels()-1).  The channels are ordered B,
00614 //               G, R, A.  This is slightly less optimal than
00615 //               setting the component values directly by named
00616 //               methods.  The value given should be a double in the
00617 //               range 0..1.
00618 ////////////////////////////////////////////////////////////////////
00619 INLINE void PNMImage::
00620 set_channel(int x, int y, int channel, double value) {
00621   set_channel_val(x, y, channel, to_val(value));
00622 }
00623 
00624 ////////////////////////////////////////////////////////////////////
00625 //     Function: PNMImage::get_bright
00626 //       Access: Public
00627 //  Description: Returns the linear brightness of the given xel, as a
00628 //               double in the range 0..1.  This flavor of
00629 //               get_bright() returns the correct grayscale brightness
00630 //               level for both full-color and grayscale images.
00631 ////////////////////////////////////////////////////////////////////
00632 INLINE double PNMImage::
00633 get_bright(int x, int y) const {
00634   return get_bright(x, y, _default_rc, _default_gc, _default_bc);
00635 }
00636 
00637 ////////////////////////////////////////////////////////////////////
00638 //     Function: PNMImage::get_bright
00639 //       Access: Public
00640 //  Description: This flavor of get_bright() works correctly only for
00641 //               color images.  It returns a single brightness value
00642 //               for the RGB color at the indicated pixel, based on
00643 //               the supplied weights for each component.
00644 ////////////////////////////////////////////////////////////////////
00645 INLINE double PNMImage::
00646 get_bright(int x, int y, double rc, double gc, double bc) const {
00647   return from_val((int)(rc * get_red_val(x, y) +
00648                         gc * get_green_val(x, y) +
00649                         bc * get_blue_val(x, y)));
00650 }
00651 
00652 ////////////////////////////////////////////////////////////////////
00653 //     Function: PNMImage::get_bright
00654 //       Access: Public
00655 //  Description: This flavor of get_bright() works correctly only for
00656 //               four-channel images.  It returns a single brightness
00657 //               value for the RGBA color at the indicated pixel,
00658 //               based on the supplied weights for each component.
00659 ////////////////////////////////////////////////////////////////////
00660 INLINE double PNMImage::
00661 get_bright(int x, int y, double rc, double gc, double bc, double ac) const {
00662   return from_val((int)(rc * get_red_val(x, y) +
00663                         gc * get_green_val(x, y) +
00664                         bc * get_blue_val(x, y) +
00665                         ac * get_alpha_val(x, y)));
00666 }
00667 
00668 ////////////////////////////////////////////////////////////////////
00669 //     Function: PNMImage::blend
00670 //       Access: Public
00671 //  Description: Smoothly blends the indicated pixel value in with
00672 //               whatever was already in the image, based on the given
00673 //               alpha value.  An alpha of 1.0 is fully opaque and
00674 //               completely replaces whatever was there previously;
00675 //               alpha of 0.0 is fully transparent and does nothing.
00676 ////////////////////////////////////////////////////////////////////
00677 INLINE void PNMImage::
00678 blend(int x, int y, const RGBColord &val, double alpha) {
00679   blend(x, y, val[0], val[1], val[2], alpha);
00680 }
00681 
00682 ////////////////////////////////////////////////////////////////////
00683 //     Function: PNMImage::Array Operator
00684 //       Access: Public
00685 //  Description: Allows the PNMImage to appear to be a 2-d array of
00686 //               xels.
00687 ////////////////////////////////////////////////////////////////////
00688 INLINE xel *PNMImage::
00689 operator [] (int y) {
00690   return row(y);
00691 }
00692 
00693 ////////////////////////////////////////////////////////////////////
00694 //     Function: PNMImage::Array Operator
00695 //       Access: Public
00696 //  Description: Allows the PNMImage to appear to be a 2-d array of
00697 //               xels.
00698 ////////////////////////////////////////////////////////////////////
00699 INLINE const xel *PNMImage::
00700 operator [] (int y) const {
00701   return row(y);
00702 }
00703 
00704 ////////////////////////////////////////////////////////////////////
00705 //     Function: PNMImage::box_filter
00706 //       Access: Public
00707 //  Description: This flavor of box_filter() will apply the filter
00708 //               over the entire image without resizing or copying;
00709 //               the effect is that of a blur operation.
00710 ////////////////////////////////////////////////////////////////////
00711 INLINE void PNMImage::
00712 box_filter(double radius) {
00713   box_filter_from(radius, *this);
00714 }
00715 
00716 ////////////////////////////////////////////////////////////////////
00717 //     Function: PNMImage::gaussian_filter
00718 //       Access: Public
00719 //  Description: This flavor of gaussian_filter() will apply the filter
00720 //               over the entire image without resizing or copying;
00721 //               the effect is that of a blur operation.
00722 ////////////////////////////////////////////////////////////////////
00723 INLINE void PNMImage::
00724 gaussian_filter(double radius) {
00725   gaussian_filter_from(radius, *this);
00726 }
00727 
00728 
00729 ////////////////////////////////////////////////////////////////////
00730 //     Function: PNMImage::allocate_array
00731 //       Access: Private
00732 //  Description: Allocates the internal memory for the RGB or
00733 //               grayscale pixels in the image (except alpha).
00734 ////////////////////////////////////////////////////////////////////
00735 INLINE void PNMImage::
00736 allocate_array() {
00737   _array = new xel[_x_size * _y_size];
00738 }
00739 
00740 ////////////////////////////////////////////////////////////////////
00741 //     Function: PNMImage::allocate_alpha
00742 //       Access: Private
00743 //  Description: Allocates the internal memory for the alpha pixels in
00744 //               the image.
00745 ////////////////////////////////////////////////////////////////////
00746 INLINE void PNMImage::
00747 allocate_alpha() {
00748   _alpha = new xelval[_x_size * _y_size];
00749 }
00750 
00751 ////////////////////////////////////////////////////////////////////
00752 //     Function: PNMImage::row
00753 //       Access: Private
00754 //  Description: Returns an array of xels corresponding to the nth row
00755 //               of the image.
00756 ////////////////////////////////////////////////////////////////////
00757 INLINE xel *PNMImage::
00758 row(int y) const {
00759   return _array + y * _x_size;
00760 }
00761 
00762 ////////////////////////////////////////////////////////////////////
00763 //     Function: PNMImage::alpha_row
00764 //       Access: Private
00765 //  Description: Returns an array of xelvals corresponding to the nth
00766 //               row of the alpha channel.
00767 ////////////////////////////////////////////////////////////////////
00768 INLINE xelval *PNMImage::
00769 alpha_row(int y) const {
00770   return _alpha + y * _x_size;
00771 }

Generated on Fri May 2 00:43:09 2003 for Panda by doxygen1.3