Porównaj commity

...

14 Commity

Autor SHA1 Wiadomość Data
Ryan 7a01a5a797
Merge 3aa4f170a8 into f1ea35fbbf 2024-04-15 15:34:38 +01:00
Philip Howard f1ea35fbbf
Merge pull request #911 from pimoroni/patch-unicorn-brightness
G/S/C Unicorn: Fix get_brightness to use correct max value.
2024-04-11 17:45:48 +01:00
thirdr 3aa4f170a8 adding pngdec 2024-04-08 08:41:31 +01:00
thirdr 8bca73df5d fixed background colour 2024-04-04 16:18:22 +01:00
thirdr 06dba8c009 fixed background colour 2024-04-04 16:16:28 +01:00
thirdr 951ee18c42 offset palette example 2024-04-04 14:03:08 +01:00
thirdr 7cdf939a4c adjustment to scale and location 2024-04-04 09:49:57 +01:00
thirdr 19141cf89a png palette offset example 2024-04-04 09:48:53 +01:00
thirdr bd5624658e Changed the png used 2024-03-28 09:41:33 +00:00
thirdr 03c2a68e3f png decode example for tufty 2024-03-26 16:15:22 +00:00
thirdr 735cb1a058 png decode example for display pack 2024-03-26 15:31:42 +00:00
thirdr 3c2d710e2e Error handling 2024-03-26 13:29:51 +00:00
thirdr 4a65862858 pngdec example for inky 2024-03-26 12:35:40 +00:00
Phil Howard 964cf5eedf G/S/C Unicorn: Fix get_brightness to use correct max value.
Add a comment noting that 256 is the correct maximum brightness.
2024-03-11 21:14:43 +00:00
14 zmienionych plików z 271 dodań i 3 usunięć

Wyświetl plik

@ -494,11 +494,14 @@ namespace pimoroni {
void CosmicUnicorn::set_brightness(float value) {
value = value < 0.0f ? 0.0f : value;
value = value > 1.0f ? 1.0f : value;
// Max brightness is - in fact - 256 since it's applied with:
// result = (channel * brightness) >> 8
// eg: (255 * 256) >> 8 == 255
this->brightness = floor(value * 256.0f);
}
float CosmicUnicorn::get_brightness() {
return this->brightness / 255.0f;
return this->brightness / 256.0f;
}
void CosmicUnicorn::adjust_brightness(float delta) {

Wyświetl plik

@ -488,11 +488,14 @@ namespace pimoroni {
void GalacticUnicorn::set_brightness(float value) {
value = value < 0.0f ? 0.0f : value;
value = value > 1.0f ? 1.0f : value;
// Max brightness is - in fact - 256 since it's applied with:
// result = (channel * brightness) >> 8
// eg: (255 * 256) >> 8 == 255
this->brightness = floor(value * 256.0f);
}
float GalacticUnicorn::get_brightness() {
return this->brightness / 255.0f;
return this->brightness / 256.0f;
}
void GalacticUnicorn::adjust_brightness(float delta) {

Wyświetl plik

@ -485,11 +485,14 @@ namespace pimoroni {
void StellarUnicorn::set_brightness(float value) {
value = value < 0.0f ? 0.0f : value;
value = value > 1.0f ? 1.0f : value;
// Max brightness is - in fact - 256 since it's applied with:
// result = (channel * brightness) >> 8
// eg: (255 * 256) >> 8 == 255
this->brightness = floor(value * 256.0f);
}
float StellarUnicorn::get_brightness() {
return this->brightness / 255.0f;
return this->brightness / 256.0f;
}
void StellarUnicorn::adjust_brightness(float delta) {

Wyświetl plik

@ -0,0 +1,36 @@
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
import pngdec
# Create a PicoGraphics instance
graphics = PicoGraphics(DISPLAY)
WIDTH, HEIGHT = graphics.get_bounds()
# Set the font
graphics.set_font("bitmap8")
# Create an instance of the PNG Decoder
png = pngdec.PNG(graphics)
# Clear the screen
graphics.set_pen(1)
graphics.clear()
graphics.set_pen(0)
# Few lines of text.
graphics.text("PNG Pencil", 70, 100, WIDTH, 3)
# Open our PNG File from flash. In this example we're using a cartoon pencil.
# You can use Thonny to transfer PNG Images to your Inky Frame.
try:
png.open_file("pencil_256x256.png")
# Decode our PNG file and set the X and Y
png.decode(200, 100)
except OSError:
graphics.text("Unable to find PNG file! Copy 'pencil_256x256.png' to your Inky Frame using Thonny :)", 10, 70, WIDTH, 3)
# Start the screen update
graphics.update()

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 5.4 KiB

Wyświetl plik

@ -0,0 +1,40 @@
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_RGB332
import pngdec
# Create a PicoGraphics instance
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332)
# Set the backlight so we can see it!
display.set_backlight(1.0)
# Create an instance of the PNG Decoder
png = pngdec.PNG(display)
# Create some pens for use later.
BG = display.create_pen(200, 200, 200)
TEXT = display.create_pen(0, 0, 0)
# Clear the screen
display.set_pen(BG)
display.clear()
display.set_pen(TEXT)
display.text("PNG Pencil", 15, 80)
try:
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
# You can use Thonny to transfer PNG Images to your Pico.
png.open_file("pencil.png")
# Decode our PNG file and set the X and Y
png.decode(20, 100, scale=3)
# Handle the error if the image doesn't exist on the flash.
except OSError:
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
display.update()
# We're not doing anything else with the display now but we want to keep the program running!
while True:
pass

Wyświetl plik

@ -0,0 +1,54 @@
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8
import pngdec
# Create a PicoGraphics instance
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8, rotate=270)
# Set the backlight so we can see it!
display.set_backlight(1.0)
# Create an instance of the PNG Decoder
png = pngdec.PNG(display)
# Create some pens for use later.
BG = display.create_pen(200, 200, 200)
# 16 Reds
for i in range(16):
display.create_pen(i * 16, 0, 0)
# 16 Greens
for i in range(16):
display.create_pen(0, i * 16, 0)
# 16 Blues
for i in range(16):
display.create_pen(0, 0, i * 16)
# Adding in an white background colour at the beginning of each offset.
for i in range(3):
display.update_pen(i * 16, 200, 200, 200)
# Clear the screen
display.set_pen(BG)
display.clear()
try:
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
# You can use Thonny to transfer PNG Images to your Pico.
png.open_file("pencil_gray.png")
# Decode our PNG file and set the X and Y
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
# Handle the error if the image doesn't exist on the flash.
except OSError:
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
display.update()
# We're not doing anything else with the display now but we want to keep the program running!
while True:
pass

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 1.1 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 497 B

Wyświetl plik

@ -0,0 +1,36 @@
from picographics import PicoGraphics, DISPLAY_TUFTY_2040
import pngdec
display = PicoGraphics(display=DISPLAY_TUFTY_2040)
# Create an instance of the PNG Decoder
png = pngdec.PNG(display)
# Create some pens for use later.
BG = display.create_pen(200, 200, 200)
TEXT = display.create_pen(0, 0, 0)
# Clear the screen
display.set_pen(BG)
display.clear()
display.set_pen(TEXT)
display.text("PNG Pencil", 105, 80)
try:
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
# You can use Thonny to transfer PNG Images to your Pico.
png.open_file("pencil.png")
# Decode our PNG file and set the X and Y
png.decode(140, 100)
# Handle the error if the image doesn't exist on the flash.
except OSError:
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
display.update()
# We're not doing anything else with the display now but we want to keep the program running!
while True:
pass

Wyświetl plik

@ -0,0 +1,54 @@
from picographics import PicoGraphics, DISPLAY_TUFTY_2040, PEN_P8
import pngdec
display = PicoGraphics(display=DISPLAY_TUFTY_2040, pen_type=PEN_P8)
# Create an instance of the PNG Decoder
png = pngdec.PNG(display)
# Create some pens for use later.
BG = display.create_pen(200, 200, 200)
TEXT = display.create_pen(0, 0, 0)
# 16 Reds
for i in range(15):
display.create_pen(i * 16, 0, 0)
# 16 Greens
for i in range(16):
display.create_pen(0, i * 16, 0)
# 16 Blues
for i in range(15):
display.create_pen(0, 0, i * 16)
# Adding in an white background colour at the beginning of each offset.
for i in range(3):
display.update_pen(i * 16, 200, 200, 200)
# Clear the screen
display.set_pen(BG)
display.clear()
display.set_pen(TEXT)
display.text("PNG Pencil \n& Offset Palette", 125, 115)
try:
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
# You can use Thonny to transfer PNG Images to your Pico.
png.open_file("pencil_gray.png")
# Decode our PNG file and set the X and Y
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
# Handle the error if the image doesn't exist on the flash.
except OSError:
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
display.update()
# We're not doing anything else with the display now but we want to keep the program running!
while True:
pass

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 1.1 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 497 B

Wyświetl plik

@ -583,3 +583,42 @@ The arguments for `decode` are as follows:
2. Decode Y
3. Flags - one of `JPEG_SCALE_FULL`, `JPEG_SCALE_HALF`, `JPEG_SCALE_QUARTER` or `JPEG_SCALE_EIGHTH`
4. If you want to turn off dither altogether, try `dither=False`. This is useful if you want to [pre-dither your images](https://ditherit.com/) or for artsy posterization effects.
### PNG Files
We've included BitBank's PNGDEC - https://github.com/bitbank2/PNGDEC - so you can display PNG files on your LCDs.
Eg:
```python
import picographics
import pngdec
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332)
# Create a new PNG decoder for our PicoGraphics
png = pngdec.PNG(display)
# Open the PNG file
png.open_file("filename.jpeg")
# Decode the PNG
png.decode(0, 0)
# Display the result
display.update()
```
PNG files must be small enough to load into RAM for decoding.
PNGDEC Supports the following PNG types:
1. True Colour
2. True Colour (with Alpha)
3. Indexed
4. Grayscale
The arguments for `decode` are as follows:
1. Decode X - where to place the decoded JPEG on screen
2. Decode Y