Maxim Integrated / Mbed OS MAXREFDES155#

Dependencies:   MaximInterface

Bitmap.hpp

Committer:
IanBenzMaxim
Date:
2017-04-10
Revision:
10:71359af61af8
Parent:
0:33d4e66780c0
Child:
11:989eabe2a376

File content as of revision 10:71359af61af8:

/*******************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*******************************************************************************/

#ifndef BITMAP_HPP
#define BITMAP_HPP

#include <stddef.h>
#include <stdint.h>
#include <vector>

/// Stores a black and white bitmap image for display on the LCD.
class Bitmap
{
public:
    typedef std::vector<uint8_t> SegmentBuffer;
    
    /// Format specifier used when loading image from raw bytes.
    enum Format
    {
        NativeFormat, ///< Native format used by LCD.
        ScanLineFormat ///< Traditional left to right scan line format.
    };
    
    /// Number of pixels contained in a segment.
    static const int pixelsPerSegment = 8;
    
    /// Construct a bitmap with specified dimensions and optionally load from byte array.
    /// @param width Width in pixels that is >= 1.
    /// @param height Height in pixels that is >= 1.
    /// @param data Image data to load. Data size must match the dimensions of the bitmap.
    ///     May be set to NULL to disable loading.
    /// @param format Format of the image data to load.
    Bitmap(int width, int height, const uint8_t * data = NULL, Format format = NativeFormat);

    /// Load image data from a byte array.
    /// @param data Image data to load. Data size must match the dimensions of the bitmap.
    /// @param format Format of the image data to load.
    void load(const uint8_t * data, Format format);
    
    int width() const { return m_width; } ///< Width in pixels.
    int height() const { return m_height; } ///< Height in pixels.
    const SegmentBuffer & data() const { return m_data; } ///< Image data ready for loading into LCD.
    
    /// Check if a pixel is enabled (black).
    /// @returns True if the pixel is enabled. Returns false if the coordinate is out of range.
    bool pixelEnabled(int x, int y) const;
    /// Enable or disable a pixel.
    /// @param True to set to black. False to set to white.
    void setPixelEnabled(int x, int y, bool enabled);
    
    /// Overlay another bitmap on top of this bitmap.
    /// @param src Bitmap to overlay.
    /// @param srcX x-coordinate location to overlay.
    /// @param srcY y-coordinate location to overlay.
    void overlay(const Bitmap & src, int srcX, int srcY);
    
    /// Reset to initial state.
    void clear();
    
    /// Reset region to initial state.
    /// @param x,y Coordinates to begin clearing at.
    /// @param width,height Dimensions of the cleared region.
    void clear(int x, int y, int width, int height);
    
private:
    int m_width;
    int m_height;
    SegmentBuffer m_data;
};

#endif