Skip to content

Commit e600026

Browse files
committed
doc what i can doc
1 parent 46649b3 commit e600026

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

source/utils/fakeBlurhash.bs

+11-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function decode83(str as string) as integer
3838
end function
3939

4040
function isBlurhashValid(blurhash as string) as boolean
41-
4241
if blurhash = invalid or len(blurhash) < 6
4342
print "The blurhash string must be at least 6 characters"
4443
return false
@@ -120,16 +119,19 @@ end function
120119
' the images in the fs are named with a hash of the blurhash string
121120
' so that items which already exist are not rendered twice
122121
function renderFakeBlurhash(blurhash as string, width as integer, height as integer, punch = 1 as float)
123-
bhfn = CreateObject("roByteArray")
124-
bhfn.FromAsciiString(blurhash)
122+
' determine the file name
123+
' create the hasher and the bytestring for the hasher
124+
blurhashByteArray = CreateObject("roByteArray")
125+
blurhashByteArray.FromAsciiString(blurhash)
125126
digest = CreateObject("roEVPDigest")
126127
digest.Setup("md5")
127-
digest.Update(bhfn)
128-
fn = digest.Final()
128+
digest.Update(blurhashByteArray)
129+
filename = digest.Final()
129130
localFileSystem = CreateObject("roFileSystem")
130-
if localFileSystem.Exists("tmp://" + fn + ".bmp")
131-
return "tmp://" + fn + ".bmp"
131+
if localFileSystem.Exists("tmp://" + filename + ".bmp")
132+
return "tmp://" + filename + ".bmp"
132133
end if
134+
' doesn't exist in fs. render it.
133135
if isBlurhashValid(blurhash) = false then return invalid
134136
sizeFlag = decode83(Mid(blurhash, 1, 1))
135137
numY = Fix(sizeFlag / 9) + 1
@@ -175,6 +177,6 @@ function renderFakeBlurhash(blurhash as string, width as integer, height as inte
175177
pixels.push(pixel)
176178
end for
177179
ba = bitmapImageByteArray(numX, numY, pixels)
178-
ba.WriteFile("tmp://" + fn + ".bmp")
179-
return "tmp://" + fn + ".bmp"
180+
ba.WriteFile("tmp://" + filename + ".bmp")
181+
return "tmp://" + filename + ".bmp"
180182
end function

0 commit comments

Comments
 (0)