{"version":3,"file":"ai-model/workflows/image-preprocess.mjs","sources":["../../../../src/ai-model/workflows/image-preprocess.ts"],"sourcesContent":["import { paddingToMatchBlockByBase64 } from '@midscene/shared/img';\n\nexport interface ImagePreprocessPolicy {\n  padBlockSize?: number;\n}\n\nexport interface PreparedModelImage {\n  imageBase64: string;\n  /**\n   * Size of the image sent to the model after preprocessing. This can be larger\n   * than the original screenshot when padding is applied to satisfy model block\n   * size requirements.\n   */\n  preparedSize: {\n    width: number;\n    height: number;\n  };\n  /**\n   * Size of the real screenshot content inside the prepared image. Pixel bboxes\n   * are parsed against `preparedSize`, then clipped to `contentSize` so padding\n   * added for the model is not treated as valid UI content.\n   */\n  contentSize: {\n    width: number;\n    height: number;\n  };\n}\n\nexport async function prepareModelImage(options: {\n  imageBase64: string;\n  width: number;\n  height: number;\n  policy: ImagePreprocessPolicy;\n}): Promise<PreparedModelImage> {\n  const { imageBase64, width, height, policy } = options;\n  let preparedImageBase64 = imageBase64;\n  let modelWidth = width;\n  let modelHeight = height;\n\n  if (policy.padBlockSize !== undefined) {\n    const paddedResult = await paddingToMatchBlockByBase64(\n      imageBase64,\n      policy.padBlockSize,\n    );\n    preparedImageBase64 = paddedResult.imageBase64;\n    modelWidth = paddedResult.width;\n    modelHeight = paddedResult.height;\n  }\n\n  return {\n    imageBase64: preparedImageBase64,\n    preparedSize: {\n      width: modelWidth,\n      height: modelHeight,\n    },\n    contentSize: {\n      width,\n      height,\n    },\n  };\n}\n"],"names":["prepareModelImage","options","imageBase64","width","height","policy","preparedImageBase64","modelWidth","modelHeight","undefined","paddedResult","paddingToMatchBlockByBase64"],"mappings":";AA4BO,eAAeA,kBAAkBC,OAKvC;IACC,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAGJ;IAC/C,IAAIK,sBAAsBJ;IAC1B,IAAIK,aAAaJ;IACjB,IAAIK,cAAcJ;IAElB,IAAIC,AAAwBI,WAAxBJ,OAAO,YAAY,EAAgB;QACrC,MAAMK,eAAe,MAAMC,4BACzBT,aACAG,OAAO,YAAY;QAErBC,sBAAsBI,aAAa,WAAW;QAC9CH,aAAaG,aAAa,KAAK;QAC/BF,cAAcE,aAAa,MAAM;IACnC;IAEA,OAAO;QACL,aAAaJ;QACb,cAAc;YACZ,OAAOC;YACP,QAAQC;QACV;QACA,aAAa;YACXL;YACAC;QACF;IACF;AACF"}