import ArrayBufferSlice from "../../ArrayBufferSlice" ; import { GfxFormat } from "../platform/GfxPlatform" ; function setImageDataS8 ( dst , src ) { for ( let i = 0 ; i < src . length ; i ++ ) dst . data [ i ] = src [ i ] + 128 ; } function convertToImageData ( dst , buffer , format ) { if ( format === GfxFormat . U8_RGBA_NORM ) dst . data . set ( buffer . createTypedArray ( Uint8Array ) ) ; else if ( format === GfxFormat . S8_RGBA_NORM ) setImageDataS8 ( dst , buffer . createTypedArray ( Int8Array ) ) ; else throw "whoops" ; } export function convertToCanvasData ( canvas , buffer , format = GfxFormat . U8_RGBA_NORM ) { const ctx = canvas . getContext ( "2d" ) ! ; const imgData = ctx . createImageData ( canvas . width , canvas . height ) ; convertToImageData ( imgData , buffer , format ) ; ctx . putImageData ( imgData , 0 , 0 ) ; } export function convertToCanvas ( buffer , width , height , format = GfxFormat . U8_RGBA_NORM ) { const canvas = document . createElement ( "canvas" ) ; canvas . width = width ; canvas . height = height ; convertToCanvasData ( canvas , buffer , format ) ; return canvas ; }