Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitmaptools/Billie.bmp.license
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
# SPDX-FileCopyrightText: Copyright (c) 2018 Adafruit Industries
#
# SPDX-License-Identifier: MIT
# SPDX-License-Identifier: MIT
14 changes: 8 additions & 6 deletions bitmaptools/bitmaptools_rotate_bmp.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,23 +5,25 @@
Use bitmaptools.rotozoom() to rotate a bmp image.
"""
import math
import bitmaptools
import board
import displayio
import adafruit_imageload
import displayio
import bitmaptools

# use the builtin display
display = board.DISPLAY

# load bmp image into a Bitmap and Palette objects
source_bitmap, source_palette = adafruit_imageload.load("Billie.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
source_bitmap, source_palette = adafruit_imageload.load(
"Billie.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)
# Create a TileGrid to show the bitmap
source_tile_grid = displayio.TileGrid(source_bitmap, pixel_shader=source_palette)

# Create destination Bitmap object to hold the rotated image
dest_bitmap = displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))
dest_bitmap = displayio.Bitmap(
source_bitmap.height, source_bitmap.height, len(source_palette)
)

# Create a TileGrid to show the destination Bitmap with the rotated image in it
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
Expand Down
14 changes: 8 additions & 6 deletions bitmaptools/bitmaptools_rotate_bmp_animated.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,23 +5,25 @@
Use bitmaptools.rotozoom() to rotate a bmp image in a circle animated.
"""
import math
import bitmaptools
import board
import displayio
import adafruit_imageload
import bitmaptools
import displayio

# use the builtin display
display = board.DISPLAY

# load bmp image into a Bitmap and Palette objects
source_bitmap, source_palette = adafruit_imageload.load("Billie.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
source_bitmap, source_palette = adafruit_imageload.load(
"Billie.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)
# Create a TileGrid to show the bitmap
source_tile_grid = displayio.TileGrid(source_bitmap, pixel_shader=source_palette)

# Create destination Bitmap object to hold the rotated image
dest_bitmap = displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))
dest_bitmap = displayio.Bitmap(
source_bitmap.height, source_bitmap.height, len(source_palette)
)

# Create a TileGrid to show the destination Bitmap with the rotated image in it
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
Expand Down
78 changes: 78 additions & 0 deletions bitmaptools/bitmaptools_scale_bmp.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
#
# SPDX-License-Identifier: MIT
"""
Use bitmaptools.rotozoom() to scale a bmp image and show multiple sizes of it on the display.
"""
import board
import adafruit_imageload
import bitmaptools
import displayio

# use the builtin display
display = board.DISPLAY

# load bmp image into a Bitmap and Palette objects
source_bitmap, source_palette = adafruit_imageload.load(
"Billie.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)

# Create destination Bitmap object to hold the rotated image
dest_bitmap = displayio.Bitmap(
source_bitmap.height * 2, source_bitmap.height * 2, len(source_palette)
)

# Create a TileGrid to show the destination Bitmap with the rotated image in it
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)

# rotozoom() takes from source bitmap, puts into destination bitmap.
# clipping is not used so whole source image is put into the destination bitmap.
# scale argument accepts a float number that will multiply the size of the source bitmap times
# the scale factor.

# Big Billie
BIG_BILLIE_SCALE = 1.75
bitmaptools.rotozoom(
dest_bitmap,
source_bitmap,
ox=int(dest_bitmap.width - ((source_bitmap.width / 2) * BIG_BILLIE_SCALE)),
oy=int((source_bitmap.height / 2) * BIG_BILLIE_SCALE),
scale=BIG_BILLIE_SCALE,
)

# Normal sized Billie
NORMAL_BILLIE_SCALE = 1.0
bitmaptools.rotozoom(
dest_bitmap,
source_bitmap,
ox=int(dest_bitmap.width / 2) - 24,
oy=int((source_bitmap.height / 2) * NORMAL_BILLIE_SCALE),
scale=NORMAL_BILLIE_SCALE,
)

# Little Billie
LITTLE_BILLY_SCALE = 0.5
bitmaptools.rotozoom(
dest_bitmap,
source_bitmap,
ox=int((source_bitmap.width / 2) * LITTLE_BILLY_SCALE),
oy=int((source_bitmap.height / 2) * LITTLE_BILLY_SCALE),
scale=LITTLE_BILLY_SCALE,
)

# move the destination image out of the corner a little
dest_tile_grid.x = 10
dest_tile_grid.y = 10

# Create a Group to show the TileGrid
group = displayio.Group()

# Add the TileGrid to the Group
group.append(dest_tile_grid)

# Add the Group to the Display
display.show(group)

# Loop forever so you can enjoy your image
while True:
pass
73 changes: 73 additions & 0 deletions bitmaptools/bitmaptools_scale_bmp_animated.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
#
# SPDX-License-Identifier: MIT
"""
Use bitmaptools.rotozoom() to scale a bmp image and show multiple sizes of it on the display.
"""
import board
import adafruit_imageload
import bitmaptools
import displayio

# use the builtin display
display = board.DISPLAY

# load bmp image into a Bitmap and Palette objects
source_bitmap, source_palette = adafruit_imageload.load(
"Billie.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)

# Create destination Bitmap object to hold the rotated image
dest_bitmap = displayio.Bitmap(
source_bitmap.height * 2, source_bitmap.height * 2, len(source_palette)
)

# Create a TileGrid to show the destination Bitmap with the rotated image in it
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)

# rotozoom() takes from source bitmap, puts into destination bitmap.
# clipping is not used so whole source image is put into the destination bitmap.
# scale argument accepts a float number that will multiply the size of the source bitmap times
# the scale factor.
INITIAL_SCALE = 0.5
bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=INITIAL_SCALE)

# move the destination image out of the corner a little
dest_tile_grid.x = 10
dest_tile_grid.y = 10

# Create a Group to show the TileGrid
group = displayio.Group()

# Add the TileGrid to the Group
group.append(dest_tile_grid)

# Add the Group to the Display
display.show(group)

# we will manually refresh the display only after we make changes to our destination bitmap
display.auto_refresh = False

# Loop forever
while True:
# loop from 0.5 to 2.0 scale factors. step size 0.1
for scale in range(5, 21):
# empty the destination bitmap, clear out the previously drawn frame
dest_bitmap.fill(0)

# paste in billie at the current scale size from our loop
bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=scale / 10)

# refresh the display to draw our changes
display.refresh()

# loop from 2.0 to 0.5 scale factors. step size 0.1
for scale in range(20, 4, -1):
# empty the destination bitmap, clear out the previously drawn frame
dest_bitmap.fill(0)

# paste in billie at the current scale size from our loop
bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=scale / 10)

# refresh the display to draw our changes
display.refresh()