From 6f88d641bf54a8843180149c157e816753342429 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 19 Jan 2012 18:22:22 +0000 Subject: [PATCH] PNMImage::reverse_rows() --- panda/src/pnmimage/pnmImage.cxx | 28 ++++++++++++++++++++++++++++ panda/src/pnmimage/pnmImage.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/panda/src/pnmimage/pnmImage.cxx b/panda/src/pnmimage/pnmImage.cxx index 71dfca4360..a6c755fb5f 100644 --- a/panda/src/pnmimage/pnmImage.cxx +++ b/panda/src/pnmimage/pnmImage.cxx @@ -484,6 +484,34 @@ make_grayscale(double rc, double gc, double bc) { setup_rc(); } +//////////////////////////////////////////////////////////////////// +// Function: PNMImage::reverse_rows +// Access: Published +// Description: Performs an in-place reversal of the row (y) data. +//////////////////////////////////////////////////////////////////// +void PNMImage:: +reverse_rows() { + if (_array != NULL) { + xel *new_array = (xel *)PANDA_MALLOC_ARRAY(_x_size * _y_size * sizeof(xel)); + for (int y = 0; y < _y_size; y++) { + int new_y = _y_size - 1 - y; + memcpy(new_array + new_y * _x_size, _array + y * _x_size, _x_size * sizeof(xel)); + } + PANDA_FREE_ARRAY(_array); + _array = new_array; + } + + if (_alpha != NULL) { + xelval *new_alpha = (xelval *)PANDA_MALLOC_ARRAY(_x_size * _y_size * sizeof(xelval)); + for (int y = 0; y < _y_size; y++) { + int new_y = _y_size - 1 - y; + memcpy(new_alpha + new_y * _x_size, _alpha + y * _x_size, _x_size * sizeof(xelval)); + } + PANDA_FREE_ARRAY(_alpha); + _alpha = new_alpha; + } +} + //////////////////////////////////////////////////////////////////// // Function: PNMImage::set_maxval // Access: Published diff --git a/panda/src/pnmimage/pnmImage.h b/panda/src/pnmimage/pnmImage.h index 6e28f6a6bf..ce723e1e12 100644 --- a/panda/src/pnmimage/pnmImage.h +++ b/panda/src/pnmimage/pnmImage.h @@ -116,6 +116,8 @@ PUBLISHED: void make_grayscale(double rc, double gc, double bc); INLINE void make_rgb(); + BLOCKING void reverse_rows(); + BLOCKING void set_maxval(xelval maxval); // The *_val() functions return or set the color values in the range