//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
// one that was being worked on.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

/** @file  pmMaskBadPixels.h
 *
 *  @brief Given an input image, a bad pixel mask, a corresponding value in the bad pixel mask to mask, a
 *  saturation level, and a growing radius, mask in the input image those pixels in the bad pixel mask that
 *  match the value to mask.
 *
 *  Given an input image, in, a bad pixel mask, a corresponding value in the bad pixel mask to mask in the
 *  input image, maskVal, a saturation level, and a growing radius, pmMaskBadPixels shall mask in the input
 *  image those pixels in the bad pixel mask that match the value to mask. Note that the input image, in, is
 *  modified in-place. All pixels in the mask which satisfy the maskVal shall have their corresponding pixels
 *  masked in the input image, in. All pixels which satisfy the growVal shall have their corresponding
 *  pixels, along with all pixels within the grow radius masked. Pixels which have flux greater than sat shall
 *  also be masked, but not grown. Note that the input image, in, and the mask need not be the same size,
 *  since the input image may already have been trimmed (following overscan subtraction), but the function
 *  shall use the offsets in the image (in->x0 and in->y0) to determine the appropriate offsets to obtain the
 *  correct pixel on the mask. In the event that the mask image is too small (i.e., pixels on the input image
 *  refer to pixels outside the range of the mask image), the function shall generate an error.
 *
 *  @author Ross Harman, MHPCC
 *
 *  @version $Revision: 1.2.12.2 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2006-04-19 06:31:55 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 */

#include "pslib.h"
#include "pmFPA.h"

// these defines are necessary to yield 8-bit results (use instead of ~)
# define NOT_U8(A)(UCHAR_MAX-(A))
# define NOT_U16(A)(USHORT_MAX-(A))

/** Mask values */
typedef enum {
    PM_MASK_CLEAR   = 0x00,   ///< The pixel is a charge trap.
    PM_MASK_TRAP    = 0x01,   ///< The pixel is a charge trap.
    PM_MASK_BADCOL  = 0x02,   ///< The pixel is a bad column.
    PM_MASK_SAT     = 0x04,   ///< The pixel is saturated.
    PM_MASK_BAD     = 0x08,   ///< The pixel is low
    PM_MASK_FLAT    = 0x10,   ///< The pixel is non-positive in the flat-field.
    PM_MASK_MARK    = 0x20,   ///< The pixel is marked as temporarily ignored
    PM_MASK_EXT1    = 0x40,   ///< This mask value is not used
    PM_MASK_EXT2    = 0x80,   ///< This mask value is not used
} pmMaskValue;

bool pmReadoutSetMask(pmReadout *readout // Readout for which to set mask
                     );
bool pmReadoutSetWeight(pmReadout *readout // Readout for which to set weight
                       );
bool pmCellSetMaskWeight(pmCell *cell // Cell for which to set weights
                        );

/** Execute bad pixels module.
 *
 *  Given an input image, a bad pixel mask, a corresponding value in the bad pixel mask to mask, a
 *  saturation level, and a growing radius, mask in the input image those pixels in the bad pixel mask that
 *  match the value to mask.
 *
 *  @return  bool: True or false for success or failure
 */
bool pmMaskBadPixels(
    pmReadout *in,          ///< Readout containing input image data.
    const psImage *mask,    ///< Mask data to be added to readout mask data.
    unsigned int maskVal,   ///< Mask value to determine what to add to input mask.
    float sat,              ///< Saturation limit to mask bad pixels.
    unsigned int growVal,   ///< Mask data to determine if a circurlar area should be masked.
    int grow                ///< Radius of mask to apply around pixel.
);

