Skip to content

Commit 4d547d0

Browse files
committed
Fixes for logos, diorite, and iOS.
Signed-off-by: Katharine Berry <[email protected]>
1 parent a4d19ba commit 4d547d0

File tree

5 files changed

+52
-25
lines changed

5 files changed

+52
-25
lines changed

app/src/c/converse/segments/widgets/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void prv_layer_update(Layer *layer, GContext *ctx) {
9494
graphics_fill_circle(ctx, center, 6);
9595
graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorDarkGray, GColorBlack));
9696
graphics_draw_circle(ctx, center, 6);
97-
graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorBlue, GColorDarkGray));
97+
graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorBlue, GColorBlack));
9898
graphics_fill_circle(ctx, center, 4);
9999
}
100100
} else {

app/src/pkjs/widgets/map.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,44 @@
1616

1717
var imageManager = require('../lib/image_transfer').sharedManager;
1818

19+
var atob = window.atob;
20+
21+
// We don't get atob on iOS, so provide our own implementation.
22+
// This code was generated by Google Search, in response to the query "atob in pure javascript".
23+
// It seems to work.
24+
if (!atob) {
25+
atob = function(encoded) {
26+
const base64 =
27+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
28+
var str = "";
29+
var bytes = 0;
30+
var bits = 0;
31+
for (var i = 0; i < encoded.length; i++) {
32+
const char = encoded.charAt(i);
33+
if (char === "=") {
34+
break;
35+
}
36+
var value = base64.indexOf(char);
37+
if (value < 0) {
38+
continue;
39+
}
40+
bytes = (bytes << 6) | value;
41+
bits += 6;
42+
if (bits >= 8) {
43+
str += String.fromCharCode((bytes >>> (bits - 8)) & 255);
44+
bits -= 8;
45+
}
46+
}
47+
return str;
48+
}
49+
}
50+
1951
exports.map = function(session, params) {
2052
console.log(JSON.stringify(params));
2153
var base64pbi = params['image'];
2254
var width = params['width'];
2355
var height = params['height'];
24-
var pbi = atob(base64pbi); // TODO: this doesn't work on iOS!
56+
var pbi = atob(base64pbi);
2557
var imageData = new Array(pbi.length);
2658
for (var i = 0; i < pbi.length; i++) {
2759
imageData[i] = pbi.charCodeAt(i);
1.47 KB
Loading
397 Bytes
Loading

service/assistant/widgets/map.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import (
2424
var googleLogo2BitBytes []byte
2525
var googleLogo2Bit image.Image
2626

27+
//go:embed google1bit.png
28+
var googleLogo1BitBytes []byte
29+
var googleLogo1Bit image.Image
30+
2731
var mapClient *gmaps.Client
2832

2933
func init() {
@@ -37,6 +41,10 @@ func init() {
3741
if err != nil {
3842
panic(err)
3943
}
44+
googleLogo1Bit, err = png.Decode(bytes.NewReader(googleLogo1BitBytes))
45+
if err != nil {
46+
panic(err)
47+
}
4048
}
4149

4250
type MapWidget struct {
@@ -53,6 +61,7 @@ func mapWidget(ctx context.Context, markerString, includeLocationString string)
5361
markers := make(map[string]util.Coords)
5462
threadContext := query.ThreadContextFromContext(ctx)
5563
poiInfo := threadContext.ContextStorage.POIs
64+
// Sometimes the model decides to quote random parts of the string, I don't know.
5665
markerString = strings.ReplaceAll(markerString, "\"", "")
5766
for _, marker := range strings.Split(markerString, ",") {
5867
parts := strings.Split(marker, ":")
@@ -191,6 +200,7 @@ func monochrome(img image.Image) image.Image {
191200
}
192201
}
193202
}
203+
stampLogo(newImg, googleLogo1Bit)
194204
return newImg
195205
}
196206

@@ -207,13 +217,17 @@ func lowColour(img image.Image) image.Image {
207217
}
208218
}
209219
}
210-
// slap the 2-bit version of the Google logo over the existing one
211-
topCorner := image.Pt(8, newImg.Bounds().Max.Y-16)
212-
targetImageRect := image.Rect(topCorner.X, topCorner.Y, topCorner.X+googleLogo2Bit.Bounds().Dx(), topCorner.Y+googleLogo2Bit.Bounds().Dy())
213-
draw.Draw(newImg, targetImageRect, googleLogo2Bit, image.Point{0, 0}, draw.Over)
220+
stampLogo(newImg, googleLogo2Bit)
214221
return newImg
215222
}
216223

224+
func stampLogo(img *image.Paletted, logo image.Image) {
225+
// slap the black and white version of the Google logo over the existing one
226+
topCorner := image.Pt(7, img.Bounds().Max.Y-17)
227+
targetImageRect := image.Rect(topCorner.X, topCorner.Y, topCorner.X+googleLogo2Bit.Bounds().Dx(), topCorner.Y+googleLogo2Bit.Bounds().Dy())
228+
draw.Draw(img, targetImageRect, logo, image.Point{0, 0}, draw.Over)
229+
}
230+
217231
func greyTo2BitGrey(c color.Color) color.Color {
218232
y := color.GrayModel.Convert(c).(color.Gray).Y
219233
switch {
@@ -228,20 +242,6 @@ func greyTo2BitGrey(c color.Color) color.Color {
228242
}
229243
}
230244

231-
func colourToMonochrome(c color.Color) color.Color {
232-
isBlack := color.Gray16Model.Convert(c).(color.Gray16).Y <= 0xEFFF
233-
if isBlack {
234-
return color.Black
235-
} else {
236-
return color.White
237-
}
238-
}
239-
240-
func closeToWhite(c color.Color) bool {
241-
r, g, b, _ := c.RGBA()
242-
return r > 0x7FFF && g > 0x7FFF && b > 0x7FFF
243-
}
244-
245245
func closeToBlack(c color.Color) bool {
246246
r, _, _, _ := c.RGBA()
247247
return r <= 0x8FFF
@@ -251,8 +251,3 @@ func shouldDither(c color.Color) bool {
251251
r, g, b, _ := c.RGBA()
252252
return r == 42148 && g == 43176 && b == 43690
253253
}
254-
255-
func isGrey(c color.Color) bool {
256-
r, g, b, _ := c.RGBA()
257-
return r == g && g == b
258-
}

0 commit comments

Comments
 (0)