mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2026-07-27 20:05:52 +00:00
Add Doxygen-ready headers throughout. Add GFXcanvas4 (untested). Delete Adafruit_SPITFT_Macros.h
Latter will require updating several libraries (Adafruit_ILI9341, etc.) to remove their dependency on this file (which was actually empty, but kept around to avoid this step for a while).
This commit is contained in:
+47
-30
@@ -1,34 +1,51 @@
|
||||
/*
|
||||
This is the core graphics library for all our displays, providing a common
|
||||
set of graphics primitives (points, lines, circles, etc.). It needs to be
|
||||
paired with a hardware-specific library for each display device we carry
|
||||
(to handle the lower-level functions).
|
||||
|
||||
Adafruit invests time and resources providing this open source code, please
|
||||
support Adafruit & open-source hardware by purchasing products from Adafruit!
|
||||
|
||||
Copyright (c) 2013 Adafruit Industries. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
* @file Adafruit_GFX.cpp
|
||||
*
|
||||
* @mainpage Arduino library underlying most Adafruit graphics displays.
|
||||
* Contains code common to all displays; not tied to specific hardware.
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* Adafruit_GFX is the core graphics library for most Adafruit displays,
|
||||
* providing a common set of graphics primitives (points, lines, circles,
|
||||
* etc.). This is not tied to any specific display device...it must be
|
||||
* paired with another library (unique to each screen type) to address
|
||||
* vendor-specific functionality.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* Copyright (c) 2013 Adafruit Industries. All rights reserved.
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file Adafruit_GFX.h
|
||||
*
|
||||
* Main header file for Adafruit's GFX graphics library, providing a base
|
||||
* class for various small bitmapped displays.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if ARDUINO >= 100
|
||||
@@ -247,6 +263,8 @@ protected:
|
||||
GFXfont *gfxFont; ///< Pointer to special font
|
||||
};
|
||||
|
||||
#include "Adafruit_GFX_Button.h"
|
||||
#include "GFXcanvas1.h"
|
||||
#include "GFXcanvas16.h"
|
||||
#include "GFXcanvas4.h"
|
||||
#include "GFXcanvas8.h"
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file Adafruit_GFX_Button.cpp
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a basic UI button
|
||||
* class for touchscreen displays.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#include "Adafruit_GFX_Button.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file Adafruit_GFX_Button.h
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a basic UI button
|
||||
* class for touchscreen displays.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* @file Adafruit_GrayOLED.cpp
|
||||
*
|
||||
* This is documentation for Adafruit's generic library for grayscale
|
||||
* Part of Adafruit's GFX graphics library. Provides support for grayscale
|
||||
* OLED displays: http://www.adafruit.com/category/63_98
|
||||
*
|
||||
* These displays use I2C or SPI to communicate. I2C requires 2 pins
|
||||
@@ -13,6 +13,10 @@
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*!
|
||||
* @file Adafruit_GrayOLED.h
|
||||
*
|
||||
* This is part of for Adafruit's GFX library, supplying generic support
|
||||
* for grayscale OLED displays: http://www.adafruit.com/category/63_98
|
||||
* Part of Adafruit's GFX graphics library. Provides support for grayscale
|
||||
* OLED displays: http://www.adafruit.com/category/63_98
|
||||
*
|
||||
* These displays use I2C or SPI to communicate. I2C requires 2 pins
|
||||
* (SCL+SDA) and optionally a RESET pin. SPI requires 4 pins (MOSI, SCK,
|
||||
@@ -13,12 +13,10 @@
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries, with
|
||||
* contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text above, and the splash screen header file,
|
||||
* must be included in any redistribution.
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
/*!
|
||||
* @file Adafruit_SPITFT.cpp
|
||||
*
|
||||
* @mainpage Adafruit SPI TFT Displays (and some others)
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Originally this class was
|
||||
* written to handle a range of color TFT displays connected via SPI,
|
||||
* but over time this library and some display-specific subclasses have
|
||||
@@ -14,20 +10,10 @@
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
|
||||
* @section dependencies Dependencies
|
||||
*
|
||||
* This library depends on <a href="https://github.com/adafruit/Adafruit_GFX">
|
||||
* Adafruit_GFX</a> being present on your system. Please make sure you have
|
||||
* installed the latest version before using this library.
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
|
||||
@@ -255,9 +255,9 @@ public:
|
||||
uint16_t read16(void); // Read single 16-bit value
|
||||
|
||||
// Most of these low-level functions were formerly macros in
|
||||
// Adafruit_SPITFT_Macros.h. Some have been made into inline functions
|
||||
// to avoid macro mishaps. Despite the addition of code for a parallel
|
||||
// display interface, the names have been kept for backward
|
||||
// Adafruit_SPITFT_Macros.h (file since removed). Some have been made into
|
||||
// inline functions to avoid macro mishaps. Despite the addition of code
|
||||
// for a parallel display interface, the names have been kept for backward
|
||||
// compatibility (some subclasses may be invoking these):
|
||||
void SPI_WRITE16(uint16_t w); // Not inline
|
||||
void SPI_WRITE32(uint32_t l); // Not inline
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// THIS FILE INTENTIONALLY LEFT BLANK.
|
||||
|
||||
// Macros previously #defined here have been made into (mostly) inline
|
||||
// functions in the Adafruit_SPITFT class. Other libraries might still
|
||||
// contain code trying to #include this header file, so until everything's
|
||||
// updated this file still exists (but doing nothing) to avoid trouble.
|
||||
+16
-17
@@ -1,21 +1,20 @@
|
||||
#include "GFXcanvas1.h"
|
||||
/*!
|
||||
* @file GFXcanvas1.cpp
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 1-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
// GFXcanvas1, GFXcanvas8 and GFXcanvas16 (currently a WIP, don't get too
|
||||
// comfy with the implementation) provide 1-, 8- and 16-bit offscreen
|
||||
// canvases, the address of which can be passed to drawBitmap() or
|
||||
// pushColors() (the latter appears only in a couple of GFX-subclassed TFT
|
||||
// libraries at this time). This is here mostly to help with the recently-
|
||||
// added proportionally-spaced fonts; adds a way to refresh a section of the
|
||||
// screen without a massive flickering clear-and-redraw...but maybe you'll
|
||||
// find other uses too. VERY RAM-intensive, since the buffer is in MCU
|
||||
// memory and not the display driver...GXFcanvas1 might be minimally useful
|
||||
// on an Uno-class board, but this and the others are much more likely to
|
||||
// require at least a Mega or various recent ARM-type boards (recommended,
|
||||
// as the text+bitmap draw can be pokey). GFXcanvas1 requires 1 bit per
|
||||
// pixel (rounded up to nearest byte per scanline), GFXcanvas8 is 1 byte
|
||||
// per pixel (no scanline pad), and GFXcanvas16 uses 2 bytes per pixel (no
|
||||
// scanline pad).
|
||||
// NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND.
|
||||
#include "GFXcanvas1.h"
|
||||
|
||||
#ifdef __AVR__
|
||||
// Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file GFXcanvas1.h
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 1-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file GFXcanvas16.cpp
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 16-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#include "GFXcanvas16.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file GFXcanvas16.h
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 16-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
/*!
|
||||
* @file GFXcanvas4.cpp
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 4-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#include "GFXcanvas4.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instatiate a 4-bit graphics canvas.
|
||||
@param w Canvas width, in pixels
|
||||
@param h Canvas height, in pixels
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GFXcanvas4::GFXcanvas4(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
|
||||
uint16_t bytes = ((w + 1) / 2) * h; // Scanlines are byte-aligned
|
||||
if ((buffer = (uint8_t *)malloc(bytes))) {
|
||||
memset(buffer, 0, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Delete the canvas, free memory
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GFXcanvas4::~GFXcanvas4(void) {
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Draw a pixel to the canvas framebuffer
|
||||
@param x x coordinate
|
||||
@param y y coordinate
|
||||
@param color 4-bit color to set pixel
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GFXcanvas4::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if (buffer) {
|
||||
if ((x < 0) || (y < 0) || (x >= _width) || (y >= _height))
|
||||
return;
|
||||
|
||||
int16_t t;
|
||||
switch (rotation) {
|
||||
case 1:
|
||||
t = x;
|
||||
x = WIDTH - 1 - y;
|
||||
y = t;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - 1 - x;
|
||||
y = HEIGHT - 1 - y;
|
||||
break;
|
||||
case 3:
|
||||
t = x;
|
||||
x = y;
|
||||
y = HEIGHT - 1 - t;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t *ptr = &buffer[(x / 2) + y * ((WIDTH + 1) / 2)];
|
||||
if (x & 1) { // Odd column - lower nybble
|
||||
*ptr = (*ptr & 0xF0) | (color & 0xF);
|
||||
} else { // Even column - upper nybble
|
||||
*ptr = (*ptr & 0x0F) | (color << 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GFXcanvas4::getPixel(int16_t x, int16_t y) const {
|
||||
int16_t t;
|
||||
switch (rotation) {
|
||||
case 1:
|
||||
t = x;
|
||||
x = WIDTH - 1 - y;
|
||||
y = t;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - 1 - x;
|
||||
y = HEIGHT - 1 - y;
|
||||
break;
|
||||
case 3:
|
||||
t = x;
|
||||
x = y;
|
||||
y = HEIGHT - 1 - t;
|
||||
break;
|
||||
}
|
||||
return getRawPixel(x, y);
|
||||
}
|
||||
|
||||
bool GFXcanvas4::getRawPixel(int16_t x, int16_t y) const {
|
||||
if ((x < 0) || (y < 0) || (x >= WIDTH) || (y >= HEIGHT))
|
||||
return 0;
|
||||
if (buffer) {
|
||||
uint8_t *ptr = &buffer[(x / 2) + y * ((WIDTH + 1) / 2)];
|
||||
if (x & 1) { // Odd column - lower nybble
|
||||
return *ptr & 0xF;
|
||||
} else { // Even column - upper nybble
|
||||
return *ptr >> 4;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Fill the framebuffer completely with one color
|
||||
@param color Binary (on or off) color to fill with
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GFXcanvas4::fillScreen(uint16_t color) {
|
||||
if (buffer) {
|
||||
memset(buffer, (color & 0xF) * 0x11, ((WIDTH + 1) / 2) * HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Speed optimized vertical line drawing
|
||||
@param x Line horizontal start point
|
||||
@param y Line vertical start point
|
||||
@param h Height of vertical line to draw, including first point
|
||||
@param color Color to fill with
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GFXcanvas4::drawFastVLine(int16_t x, int16_t y, int16_t h,
|
||||
uint16_t color) {
|
||||
|
||||
if (h < 0) { // Convert negative heights to positive equivalent
|
||||
h *= -1;
|
||||
y -= h - 1;
|
||||
if (y < 0) {
|
||||
h += y;
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Edge rejection (no-draw if totally off canvas)
|
||||
if ((x < 0) || (x >= width()) || (y >= height()) || ((y + h - 1) < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (y < 0) { // Clip top
|
||||
h += y;
|
||||
y = 0;
|
||||
}
|
||||
if (y + h > height()) { // Clip bottom
|
||||
h = height() - y;
|
||||
}
|
||||
|
||||
if (getRotation() == 0) {
|
||||
drawFastRawVLine(x, y, h, color);
|
||||
} else if (getRotation() == 1) {
|
||||
int16_t t = x;
|
||||
x = WIDTH - 1 - y;
|
||||
y = t;
|
||||
x -= h - 1;
|
||||
drawFastRawHLine(x, y, h, color);
|
||||
} else if (getRotation() == 2) {
|
||||
x = WIDTH - 1 - x;
|
||||
y = HEIGHT - 1 - y;
|
||||
|
||||
y -= h - 1;
|
||||
drawFastRawVLine(x, y, h, color);
|
||||
} else if (getRotation() == 3) {
|
||||
int16_t t = x;
|
||||
x = y;
|
||||
y = HEIGHT - 1 - t;
|
||||
drawFastRawHLine(x, y, h, color);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Speed optimized horizontal line drawing
|
||||
@param x Line horizontal start point
|
||||
@param y Line vertical start point
|
||||
@param w Width of horizontal line to be drawn, including first point
|
||||
@param color Color to fill with
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GFXcanvas4::drawFastHLine(int16_t x, int16_t y, int16_t w,
|
||||
uint16_t color) {
|
||||
if (w < 0) { // Convert negative widths to positive equivalent
|
||||
w *= -1;
|
||||
x -= w - 1;
|
||||
if (x < 0) {
|
||||
w += x;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Edge rejection (no-draw if totally off canvas)
|
||||
if ((y < 0) || (y >= height()) || (x >= width()) || ((x + w - 1) < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < 0) { // Clip left
|
||||
w += x;
|
||||
x = 0;
|
||||
}
|
||||
if (x + w >= width()) { // Clip right
|
||||
w = width() - x;
|
||||
}
|
||||
|
||||
if (getRotation() == 0) {
|
||||
drawFastRawHLine(x, y, w, color);
|
||||
} else if (getRotation() == 1) {
|
||||
int16_t t = x;
|
||||
x = WIDTH - 1 - y;
|
||||
y = t;
|
||||
drawFastRawVLine(x, y, w, color);
|
||||
} else if (getRotation() == 2) {
|
||||
x = WIDTH - 1 - x;
|
||||
y = HEIGHT - 1 - y;
|
||||
|
||||
x -= w - 1;
|
||||
drawFastRawHLine(x, y, w, color);
|
||||
} else if (getRotation() == 3) {
|
||||
int16_t t = x;
|
||||
x = y;
|
||||
y = HEIGHT - 1 - t;
|
||||
y -= w - 1;
|
||||
drawFastRawVLine(x, y, w, color);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Speed optimized vertical line drawing into the raw canvas buffer
|
||||
@param x Line horizontal start point
|
||||
@param y Line vertical start point
|
||||
@param h length of vertical line to be drawn, including first point
|
||||
@param color Color to fill with
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GFXcanvas4::drawFastRawVLine(int16_t x, int16_t y, int16_t h,
|
||||
uint16_t color) {
|
||||
// x & y already in raw (rotation 0) coordinates, no need to transform.
|
||||
int16_t row_bytes = ((WIDTH + 1) / 2);
|
||||
uint8_t *ptr = &buffer[(x / 2) + y * row_bytes];
|
||||
uint8_t mask;
|
||||
|
||||
if (x & 1) { // Odd column - lower nybble
|
||||
color &= 0xF;
|
||||
mask = 0xF0;
|
||||
} else { // Even column - upper nybble
|
||||
color = (color & 0xF) << 4;
|
||||
mask = 0x0F;
|
||||
}
|
||||
for (int16_t i = 0; i < h; i++) {
|
||||
*ptr = (*ptr & mask) | color;
|
||||
ptr += row_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Speed optimized horizontal line drawing into the raw canvas buffer
|
||||
@param x Line horizontal start point
|
||||
@param y Line vertical start point
|
||||
@param w length of horizontal line to be drawn, including first point
|
||||
@param color Binary (on or off) color to fill with
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GFXcanvas4::drawFastRawHLine(int16_t x, int16_t y, int16_t w,
|
||||
uint16_t color) {
|
||||
// x & y already in raw (rotation 0) coordinates, no need to transform.
|
||||
int16_t rowBytes = ((WIDTH + 1) / 2);
|
||||
uint8_t *ptr = &buffer[(x / 2) + y * rowBytes];
|
||||
color &= 0xF;
|
||||
|
||||
// check to see if first byte needs to be partially filled
|
||||
if ((x & 1) > 0) { // If starting in odd column...
|
||||
// Set lower nybble of first byte
|
||||
*ptr = (*ptr & 0xF0) | color;
|
||||
w--; // Subtract 1 pixel from width
|
||||
ptr++; // Advance pixel pointer to next byte
|
||||
}
|
||||
|
||||
if (w > 0) {
|
||||
// Fill remaining whole bytes...
|
||||
memset(ptr, color * 0x11, w / 2);
|
||||
// And upper nybble of last byte, if required...
|
||||
if (w & 1) {
|
||||
ptr += w / 2;
|
||||
*ptr = (*ptr * 0x0F) | (color << 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*!
|
||||
* @file GFXcanvas4.h
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 4-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
|
||||
/// A GFX 4-bit canvas context for graphics
|
||||
class GFXcanvas4 : public Adafruit_GFX {
|
||||
public:
|
||||
GFXcanvas4(uint16_t w, uint16_t h);
|
||||
~GFXcanvas4(void);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
void fillScreen(uint16_t color);
|
||||
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
/*!
|
||||
@brief Get the pixel color value at a given coordinate
|
||||
@param x x coordinate
|
||||
@param y y coordinate
|
||||
@returns The pixel's color value, 0 to 15
|
||||
*/
|
||||
bool getPixel(int16_t x, int16_t y) const;
|
||||
/*!
|
||||
@brief Get a pointer to the internal buffer memory
|
||||
@returns A pointer to the allocated buffer
|
||||
*/
|
||||
uint8_t *getBuffer(void) const { return buffer; }
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@brief Get the pixel color value at a given, unrotated coordinate.
|
||||
This method is intended for hardware drivers to get pixel value
|
||||
in native physical coordinates.
|
||||
@param x x coordinate
|
||||
@param y y coordinate
|
||||
@returns The pixel's color value, 0 to 15
|
||||
*/
|
||||
bool getRawPixel(int16_t x, int16_t y) const;
|
||||
void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
|
||||
private:
|
||||
uint8_t *buffer;
|
||||
};
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file GFXcanvas8.cpp
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 8-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#include "GFXcanvas8.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*!
|
||||
* @file GFXcanvas8.h
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Provides a 8-bit in-RAM
|
||||
* offscreen drawing canvas.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
|
||||
+19
-5
@@ -1,8 +1,22 @@
|
||||
// Font structures for newer Adafruit_GFX (1.1 and later).
|
||||
// Example fonts are included in 'Fonts' directory.
|
||||
// To use a font in your Arduino sketch, #include the corresponding .h
|
||||
// file and pass address of GFXfont struct to setFont(). Pass NULL to
|
||||
// revert to 'classic' fixed-space bitmap font.
|
||||
/*!
|
||||
* @file gfxfont.h
|
||||
*
|
||||
* Part of Adafruit's GFX graphics library. Contains font structures
|
||||
* used in library versions >= 1.1. Example fonts are included in 'Fonts'
|
||||
* directory.
|
||||
* To use a font in your Arduino sketch, include the corresponding .h
|
||||
* file and pass address of GFXfont struct to setFont(). Pass NULL to
|
||||
* revert to 'classic' fixed-space bitmap font.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries,
|
||||
* with contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
Reference in New Issue
Block a user