import { clContext as nodenCLContext , OpenCLProgram , KernelParams } from 'nodencl' ; import { ClJobs , JobCB , JobID } from '../clJobQueue' ; export enum Interlace { Progressive = 0 , TopField = 1 , BottomField = 3 } export abstract class PackImpl { protected readonly name : string ; protected readonly width : number ; protected readonly height : number ; protected interlaced = false ; readonly kernel : string ; readonly programName : string ; numBits = 10 ; lumaBlack = 64 ; lumaWhite = 940 ; chromaRange = 896 ; protected isRGB = true ; protected numBytes : Array < number > = [ 0 ] ; protected globalWorkItems = 0 ; protected workItemsPerGroup = 0 ; constructor ( name , width , height , kernel , programName ) { this . name = name ; this . width = width ; this . height = height ; this . kernel = kernel ; this . programName = programName ; } getName ( ) { return this . name ; } getWidth ( ) { return this . width ; } getHeight ( ) { return this . height ; } getNumBytes ( ) { return this . numBytes ; } getNumBytesRGBA ( ) { return this . width * this . height * 4 * 4 ; } getIsRGB ( ) { return this . isRGB ; } getTotalBytes ( ) { return this . numBytes . reduce ( ( acc , n ) => acc + n , 0 ) ; } getGlobalWorkItems ( ) { return this . globalWorkItems ; } getWorkItemsPerGroup ( ) { return this . workItemsPerGroup ; } abstract getKernelParams ( params ) ; } export default abstract class Packer { protected readonly clContext : nodenCLContext ; protected readonly packImpl : PackImpl ; protected readonly clJobs : ClJobs ; protected program : OpenCLProgram | null = null ; constructor ( clContext , packImpl , clJobs ) { this . clContext = clContext ; this . packImpl = packImpl ; this . clJobs = clJobs ; } async init ( ) { this . program = await this . clContext . createProgram ( this . packImpl . kernel , { name : this . packImpl . programName , globalWorkItems : this . packImpl . getGlobalWorkItems ( ) , workItemsPerGroup : this . packImpl . getWorkItemsPerGroup ( ) } ) ; } abstract run ( params , id , cb ) ; }