Skip to content
Open
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
12 changes: 6 additions & 6 deletions js/thumbhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function rgbaToThumbHash(w, h, rgba) {
* @param hash The bytes of the ThumbHash.
* @returns The width, height, and pixels of the rendered placeholder image.
*/
export function thumbHashToRGBA(hash) {
export function thumbHashToRGBA(hash, maxPixel) {
let { PI, min, max, cos, round } = Math

// Read the constants
Expand Down Expand Up @@ -135,8 +135,8 @@ export function thumbHashToRGBA(hash) {

// Decode using the DCT into RGB
let ratio = thumbHashToApproximateAspectRatio(hash)
let w = round(ratio > 1 ? 32 : 32 * ratio)
let h = round(ratio > 1 ? 32 / ratio : 32)
let w = round(ratio > 1 ? maxPixel : maxPixel * ratio)
let h = round(ratio > 1 ? maxPixel / ratio : maxPixel)
let rgba = new Uint8Array(w * h * 4), fx = [], fy = []
for (let y = 0, i = 0; y < h; y++) {
for (let x = 0; x < w; x++, i += 4) {
Expand Down Expand Up @@ -282,7 +282,7 @@ export function rgbaToDataURL(w, h, rgba) {
* @param hash The bytes of the ThumbHash.
* @returns A data URL containing a PNG for the rendered ThumbHash.
*/
export function thumbHashToDataURL(hash) {
let image = thumbHashToRGBA(hash)
export function thumbHashToDataURL(hash, maxPixel = 32) {
let image = thumbHashToRGBA(hash, maxPixel)
return rgbaToDataURL(image.w, image.h, image.rgba)
}
}