import GraphicMode from './GraphicMode' ; import ColorMap from './ColorMap' ; export default class PixelImage { public colorMaps : ColorMap [ ] ; public mode : GraphicMode ; public pixelIndex : number [ ] [ ] ; constructor ( mode ) { this . mode = mode ; this . colorMaps = [ ] ; this . pixelIndex = [ ] ; for ( let y = 0 ; y < mode . height ; y += 1 ) { this . pixelIndex [ y ] = [ ] ; } } param x param y public peek ( x , y ) { const colorMapIndex = this . pixelIndex [ y ] [ x ] ; if ( colorMapIndex === undefined ) { return undefined ; } return this . colorMaps [ colorMapIndex ] . get ( x , y ) ; } public addColorMap ( resXVal = this . mode . width , resYVal = this . mode . height ) { this . colorMaps . push ( new ColorMap ( this . mode . width , this . mode . height , resXVal , resYVal ) ) ; } public mapPixelIndex ( x , y ) { if ( x >= this . mode . width || x < 0 ) { throw new Error ( `x value out of bounds: ${ x }` ) ; } if ( y >= this . mode . height || y < 0 ) { throw new Error ( `y value out of bounds: ${ y }` ) ; } return this . mode . indexMap [ this . pixelIndex [ y ] [ x ] ] ; } public extractAttributeData ( yOffset , callback ) { const result = new Uint8Array ( 1000 ) . fill ( 0 ) ; let index = 0 ; this . mode . forEachCell ( yOffset , ( x , y ) => { result [ index ] = x >= this . mode . fliBugSize ? callback ( x , y ) : 0 ; index += 1 ; } ) ; return result ; } public isHires ( ) { return this . mode . pixelWidth === 1 ; } public debugColorMaps ( ) { const result = [ ] ; this . colorMaps . forEach ( colorMap => { const pixelImage = new PixelImage ( this . mode ) ; pixelImage . colorMaps . push ( colorMap ) ; for ( let x = 0 ; x < this . mode . width ; x += 1 ) { for ( let y = 0 ; y < this . mode . height ; y += 1 ) { pixelImage . pixelIndex [ y ] [ x ] = 0 ; } } result . push ( pixelImage ) ; } ) ; return result ; } }