/**
 * A specific Graphic Mode.
 * Includes a factory for creating new PixelImages in this mode.
 */ export default class GraphicMode { public id : string ; public width : number ; public height : number ; public pixelWidth = 1 ; public pixelHeight = 1 ; public rowsPerCell = 8 ; public bytesPerCellRow = 1 ; public fliBugSize = 0 ; public indexMap = { 0 : 0 , 1 : 1 , 2 : 2 , 3 : 3 } ; constructor ( id , width , height ) { this . id = id ; this . width = width ; this . height = height ; } public pixelsPerByte ( ) { return 8 / this . pixelWidth ; } public pixelsPerCellRow ( ) { return this . bytesPerCellRow * this . pixelsPerByte ( ) ; } param cellY param callback public forEachCellRow ( cellY , callback ) { for ( let rowY = cellY ; rowY < cellY + this . rowsPerCell ; rowY += 1 ) { callback ( rowY ) ; } } param yOffset param callback public forEachCell ( yOffset = 0 , callback ) { const pixelsPerCellRow = this . pixelsPerCellRow ( ) ; for ( let y = yOffset ; y < this . height ; y += this . rowsPerCell ) { for ( let x = 0 ; x < this . width ; x += pixelsPerCellRow ) { callback ( x , y ) ; } } } public forEachByte ( cellX , callback ) { const pixelsPerByte = this . pixelsPerByte ( ) ; for ( let byteX = cellX ; byteX < cellX + this . bytesPerCellRow * pixelsPerByte ; byteX += pixelsPerByte ) { callback ( byteX ) ; } } public forEachPixel ( byteX , callback ) { const pixelsPerByte = this . pixelsPerByte ( ) ; for ( let pixelX = 0 ; pixelX < pixelsPerByte ; pixelX += 1 ) { const shiftTimes = ( pixelsPerByte - 1 - pixelX ) * this . pixelWidth ; callback ( byteX + pixelX , shiftTimes ) ; } } }