Skip to content

Commit

Permalink
Bitmap rename (#5983)
Browse files Browse the repository at this point in the history
* rename namespace bitmap to bitmaps

* fix up namespaces

* fix some more

* update shims
  • Loading branch information
tballmsft authored Oct 9, 2024
1 parent 8f79305 commit b800871
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 30 deletions.
6 changes: 3 additions & 3 deletions libs/arcadeshield/_locales/arcadeshield-jsdoc-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"Bitmap.setRows": "Copy row(s) of pixel from buffer to bitmap.",
"Bitmap.transposed": "Returns a transposed bitmap (with X/Y swapped)",
"Bitmap.width": "Get the width of the bitmap",
"bitmap.create": "Create new empty (transparent) bitmap",
"bitmap.doubledIcon": "Double the size of an icon",
"bitmap.ofBuffer": "Create new bitmap with given content"
"bitmaps.create": "Create new empty (transparent) bitmap",
"bitmaps.doubledIcon": "Double the size of an icon",
"bitmaps.ofBuffer": "Create new bitmap with given content"
}
3 changes: 2 additions & 1 deletion libs/arcadeshield/_locales/arcadeshield-strings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"bitmap|block": "bitmap",
"bitmaps|block": "bitmaps",
"{id:category}Bitmap": "Bitmap",
"{id:category}Bitmaps": "Bitmaps",
"{id:category}__screenhelpers": "__screenhelpers"
}
14 changes: 10 additions & 4 deletions libs/arcadeshield/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@


declare interface Bitmap {
/**
* Get underlying buffer
*/
//% property shim=BitmapMethods::__buffer
__buffer: Buffer;

/**
* Get the width of the bitmap
*/
Expand Down Expand Up @@ -129,24 +135,24 @@ declare interface Bitmap {
//% shim=BitmapMethods::overlapsWith
overlapsWith(other: Bitmap, x: int32, y: int32): boolean;
}
declare namespace bitmap {
declare namespace bitmaps {

/**
* Create new bitmap with given content
*/
//% shim=bitmap::ofBuffer
//% shim=bitmaps::ofBuffer
function ofBuffer(buf: Buffer): Bitmap;

/**
* Create new empty (transparent) bitmap
*/
//% shim=bitmap::create
//% shim=bitmaps::create
function create(width: int32, height: int32): Bitmap;

/**
* Double the size of an icon
*/
//% shim=bitmap::doubledIcon
//% shim=bitmaps::doubledIcon
function doubledIcon(icon: Buffer): Buffer;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/arcadeshield/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ basic.showNumber(present ? 1 : 0)
// set palette before creating screen, which initializes the display
__screenhelpers.setPalette(hex`000000ffffffff2121ff93c4ff8135fff609249ca378dc52003fad87f2ff8e2ec4a4839f5c406ce5cdc491463d000000`)

const screen = bitmap.create(
const screen = bitmaps.create(
__screenhelpers.displayWidth(),
__screenhelpers.displayHeight()
)
Expand Down
6 changes: 3 additions & 3 deletions libs/bitmap/_locales/bitmap-jsdoc-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"Bitmap.setRows": "Copy row(s) of pixel from buffer to bitmap.",
"Bitmap.transposed": "Returns a transposed bitmap (with X/Y swapped)",
"Bitmap.width": "Get the width of the bitmap",
"bitmap.create": "Create new empty (transparent) bitmap",
"bitmap.doubledIcon": "Double the size of an icon",
"bitmap.ofBuffer": "Create new bitmap with given content",
"bitmaps.create": "Create new empty (transparent) bitmap",
"bitmaps.doubledIcon": "Double the size of an icon",
"bitmaps.ofBuffer": "Create new bitmap with given content",
"helpers.imageRotated": "Returns an image rotated by 90, 180, 270 deg clockwise"
}
3 changes: 2 additions & 1 deletion libs/bitmap/_locales/bitmap-strings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"bitmap|block": "bitmap",
"bitmaps|block": "bitmaps",
"helpers|block": "helpers",
"{id:category}Bitmap": "Bitmap",
"{id:category}Bitmaps": "Bitmaps",
"{id:category}Helpers": "Helpers"
}
6 changes: 3 additions & 3 deletions libs/bitmap/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ void _fillPolygon4(Bitmap_ img, pxt::RefCollection *args) {

} // namespace BitmapMethods

namespace bitmap {
namespace bitmaps {
/**
* Create new bitmap with given content
*/
Expand All @@ -1480,7 +1480,7 @@ Bitmap_ ofBuffer(Buffer buf) {
}
}

namespace bitmap {
namespace bitmaps {
/**
* Create new empty (transparent) bitmap
*/
Expand Down Expand Up @@ -1509,7 +1509,7 @@ Buffer doubledIcon(Buffer icon) {
return t->buffer;
}

} // namespace bitmap
} // namespace bitmaps

// This is 6.5x faster than standard on word-aligned copy
// probably should move to codal
Expand Down
4 changes: 2 additions & 2 deletions libs/bitmap/bitmap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type color = number

namespace bitmap {
namespace bitmaps {
export function repeatY(count: number, image: Bitmap) {
let arr = [image]
while (--count > 0)
Expand All @@ -15,7 +15,7 @@ namespace bitmap {
w = Math.max(img.width, w)
h += img.height
}
let r = bitmap.create(w, h)
let r = bitmaps.create(w, h)
let y = 0
for (let img of images) {
let x = (w - img.width) >> 1
Expand Down
8 changes: 4 additions & 4 deletions libs/bitmap/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,24 @@ declare interface Bitmap {
//% shim=BitmapMethods::overlapsWith
overlapsWith(other: Bitmap, x: int32, y: int32): boolean;
}
declare namespace bitmap {
declare namespace bitmaps {

/**
* Create new bitmap with given content
*/
//% shim=bitmap::ofBuffer
//% shim=bitmaps::ofBuffer
function ofBuffer(buf: Buffer): Bitmap;

/**
* Create new empty (transparent) bitmap
*/
//% shim=bitmap::create
//% shim=bitmaps::create
function create(width: int32, height: int32): Bitmap;

/**
* Double the size of an icon
*/
//% shim=bitmap::doubledIcon
//% shim=bitmaps::doubledIcon
function doubledIcon(icon: Buffer): Buffer;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/fonts/font12.jres

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pxtarget.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
"dockerImage": "pext/yotta:gcc5"
},
"multiVariants": [
"mbdal",
"mbcodal"
],
"alwaysMultiVariant" : true,
Expand Down
11 changes: 5 additions & 6 deletions sim/state/bitmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,13 @@ namespace pxsim.BitmapMethods {

export function drawIcon(img: RefImage, icon: RefBuffer, x: number, y: number, color: number) {
const src: Uint8Array = icon.data
if (!bitmap.isValidImage(icon))
if (!bitmaps.isValidImage(icon))
return
if (src[1] != 1)
return // only mono
let width = bitmap.bufW(src)
let height = bitmap.bufH(src)
let byteH = bitmap.byteHeight(height, 1)
let width = bitmaps.bufW(src)
let height = bitmaps.bufH(src)
let byteH = bitmaps.byteHeight(height, 1)

x |= 0
y |= 0
Expand Down Expand Up @@ -940,7 +940,7 @@ namespace pxsim.BitmapMethods {
}


namespace pxsim.bitmap {
namespace pxsim.bitmaps {
export function byteHeight(h: number, bpp: number) {
if (bpp == 1)
return h * bpp + 7 >> 3
Expand Down Expand Up @@ -997,7 +997,6 @@ namespace pxsim.bitmap {
return new RefImage(w, h, 4)
}

// TODO: move to image namespace
export function ofBuffer(buf: RefBuffer): RefImage {
const src: Uint8Array = buf.data

Expand Down

0 comments on commit b800871

Please sign in to comment.