{
  "sourceKind": "separate production-editor working copy; not a public GitHub commit",
  "reviewedAt": "2026-10-22",
  "excerpts": [
    {
      "file": "app/studio/precision-raster.ts",
      "start": 5,
      "end": 12,
      "code": "export type PrecisionSpace='RGB'|'CMYK'|'Lab'|'Gray';export type PrecisionDepth=8|16|32;\nexport type PrecisionRaster={width:number;height:number;space:PrecisionSpace;depth:PrecisionDepth;data:Float32Array;profile?:Uint8Array};\nexport type PackedPrecision={version:1;width:number;height:number;space:PrecisionSpace;depth:PrecisionDepth;data:string;profile?:string};\nexport const precisionChannels=(space:PrecisionSpace)=>space==='CMYK'?4:space==='Gray'?1:3;\nexport function validatePrecision(r:PrecisionRaster){const n=precisionChannels(r.space);if(!['RGB','CMYK','Lab','Gray'].includes(r.space)||![8,16,32].includes(r.depth)||r.depth===32&&!['RGB','Gray'].includes(r.space)||!Number.isInteger(r.width)||!Number.isInteger(r.height)||r.width<1||r.height<1||r.width>16384||r.height>16384||r.width*r.height>16000000||r.data.length!==r.width*r.height*(n+1))throw Error('Invalid precision raster or unsupported size (16 MP maximum).');for(let i=0;i<r.data.length;i++)if(!Number.isFinite(r.data[i])||Math.abs(r.data[i])>65504||i%(n+1)===n&&(r.data[i]<0||r.data[i]>1))throw Error('Invalid high-precision pixel.');if(r.profile){if(r.profile.length<132||r.profile.length>16*1024*1024)throw Error('Invalid ICC profile size.');const v=new DataView(r.profile.buffer,r.profile.byteOffset,r.profile.byteLength),sig=(at:number)=>String.fromCharCode(...r.profile!.subarray(at,at+4));if(sig(36)!=='acsp'||v.getUint32(0)!==r.profile.length||sig(16)!==({RGB:'RGB ',CMYK:'CMYK',Lab:'Lab ',Gray:'GRAY'})[r.space])throw Error('ICC profile does not match the pixel color mode.');}}\nconst encode=(bytes:Uint8Array)=>{let s='';for(let i=0;i<bytes.length;i+=8192)s+=String.fromCharCode(...bytes.subarray(i,i+8192));return btoa(s);};const decode=(s:string)=>Uint8Array.from(atob(s),c=>c.charCodeAt(0));\nconst cache=new WeakMap<PackedPrecision,PrecisionRaster>();\nexport function packPrecision(r:PrecisionRaster):PackedPrecision{validatePrecision(r);const result:PackedPrecision={version:1,width:r.width,height:r.height,space:r.space,depth:r.depth,data:encode(deflate(new Uint8Array(r.data.buffer,r.data.byteOffset,r.data.byteLength))),...(r.profile?{profile:encode(r.profile)}:{})};cache.set(result,{...r,data:r.data.slice()});return result;}",
      "ref": "working-copy-2026-10-22",
      "sha256": "11f562b76d03f90b298d2c61d5bba7f554eba43d7b82bfd7e01f6706f57da1f3"
    },
    {
      "file": "app/studio/precision-raster.ts",
      "start": 14,
      "end": 18,
      "code": "const decodeRGB=(x:number)=>x<=.04045?x/12.92:((x+.055)/1.055)**2.4,encodeRGB=(x:number)=>x<=.0031308?12.92*x:1.055*Math.pow(x,1/2.4)-.055;\nexport type PrecisionAdjustment={exposure:number;gamma:number;offset:number;channels:{gain:number;offset:number}[]};\nexport function adjustPrecision(r:PrecisionRaster,a:PrecisionAdjustment,selection?:ArrayLike<number>){validatePrecision(r);const n=precisionChannels(r.space),stride=n+1;if(!Number.isFinite(a.exposure)||Math.abs(a.exposure)>20||!Number.isFinite(a.gamma)||a.gamma<.01||a.gamma>10||!Number.isFinite(a.offset)||Math.abs(a.offset)>1||a.channels.length!==n||a.channels.some(c=>!Number.isFinite(c.gain)||c.gain<0||c.gain>8||!Number.isFinite(c.offset)||Math.abs(c.offset)>1)||selection&&selection.length!==r.width*r.height)throw Error('Invalid precision adjustment.');const out={...r,data:r.data.slice()};for(let i=0;i<out.data.length;i+=stride){const amount=selection?Math.max(0,Math.min(1,selection[i/stride]/255)):1;if(!amount)continue;for(let c=0;c<n;c++){const original=r.data[i+c];let v=original;if(r.space==='RGB'&&r.depth!==32)v=decodeRGB(v);if(r.space!=='Lab'||c===0){const value=v*2**a.exposure+a.offset;v=Math.sign(value)*Math.pow(Math.abs(value),1/a.gamma);}if(r.space==='RGB'&&r.depth!==32)v=encodeRGB(v);v=v*a.channels[c].gain+a.channels[c].offset;if(r.depth!==32)v=Math.max(0,Math.min(1,v));out.data[i+c]=original+(v-original)*amount;}}validatePrecision(out);return out;}\nexport async function convertPrecision(r:PrecisionRaster,space:PrecisionSpace,depth:PrecisionDepth,profile?:Uint8Array,wasmBinary?:Uint8Array,options:{intent?:0|1|2|3;blackPoint?:boolean}={}):Promise<PrecisionRaster>{validatePrecision(r);if(options.intent!==undefined&&![0,1,2,3].includes(options.intent))throw Error('Invalid color rendering intent.');if(depth===32&&!['RGB','Gray'].includes(space))throw Error('32-bit editing supports RGB and Grayscale.');if(r.space===space&&(r.profile===profile||r.profile&&profile&&r.profile.length===profile.length&&r.profile.every((v,i)=>v===profile[i]))){const out={...r,depth,data:r.data.slice()};if(['RGB','Gray'].includes(r.space)&&!r.profile&&r.depth!==depth&&(r.depth===32||depth===32)){const n=precisionChannels(r.space)+1;for(let i=0;i<out.data.length;i++)if(i%n!==n-1)out.data[i]=depth===32?decodeRGB(out.data[i]):encodeRGB(out.data[i]);}if(depth!==32)for(let i=0;i<out.data.length;i++)out.data[i]=Math.max(0,Math.min(1,out.data[i]));return out;}\n if(r.space==='CMYK'&&!r.profile){const data=new Float32Array(r.width*r.height*4);for(let i=0;i<r.width*r.height;i++){for(let c=0;c<3;c++)data[i*4+c]=(1-r.data[i*5+c])*(1-r.data[i*5+3]);data[i*4+3]=r.data[i*5+4];}return convertPrecision({...r,space:'RGB',data},space,depth,profile,wasmBinary,options);}",
      "ref": "working-copy-2026-10-22",
      "sha256": "11f562b76d03f90b298d2c61d5bba7f554eba43d7b82bfd7e01f6706f57da1f3"
    },
    {
      "file": "app/studio/precision-psd.ts",
      "start": 6,
      "end": 10,
      "code": "export function decodePrecisionPlane(data:Uint8Array,compression:number,width:number,height:number,depth:PrecisionDepth,large=false,inflated=false){const bytes=depth/8,size=width*height;if(size>16000000||!Number.isInteger(size)||width<0||height<0)throw Error('Invalid precision channel dimensions.');let raw:Uint8Array;if(compression===0){if(data.length<size*bytes)throw Error('Truncated precision channel.');raw=data.slice(0,size*bytes);}else if(compression===1)raw=decodePlane(data,1,width*bytes,height,large);else if((compression===2||compression===3)&&inflated){if(data.length!==size*bytes)throw Error('Invalid inflated precision plane.');raw=data.slice();}else if(compression===2||compression===3){raw=new Uint8Array(size*bytes);let offset=0;const stream=new Inflate();stream.onData=(chunk:Uint8Array)=>{if(offset+chunk.length>raw.length)throw Error('Oversized compressed precision channel.');raw.set(chunk,offset);offset+=chunk.length;};stream.push(data,true);if(stream.err||offset!==raw.length)throw Error('Invalid compressed precision channel length.');}else throw Error('Unsupported precision compression.');const out=new Float32Array(size),v=new DataView(raw.buffer,raw.byteOffset,raw.byteLength);if(compression===3&&depth===32){for(let y=0;y<height;y++){const start=y*width*4;for(let i=1;i<width*4;i++)raw[start+i]=(raw[start+i]+raw[start+i-1])&255;const tmp=new Uint8Array(width*4);for(let x=0;x<width;x++)for(let b=0;b<4;b++)tmp[x*4+b]=raw[start+b*width+x];raw.set(tmp,start);}}for(let y=0;y<height;y++){let previous=0;for(let x=0;x<width;x++){const i=y*width+x;let value=depth===8?raw[i]:depth===16?v.getUint16(i*2):v.getFloat32(i*4);if(compression===3&&depth!==32){value=(value+previous)%(depth===8?256:65536);previous=value;}out[i]=depth===32?value:value/(depth===16?65535:255);}}return out;}\nexport function precisionLayerPixels(layer:any,space:PrecisionSpace,depth:PrecisionDepth,profile?:Uint8Array):PrecisionRaster|undefined{const width=(layer.right??0)-(layer.left??0),height=(layer.bottom??0)-(layer.top??0);if(!width||!height||!layer.rawData)return;const n=precisionChannels(space),data=new Float32Array(width*height*(n+1));for(let i=n;i<data.length;i+=n+1)data[i]=1;for(const channel of layer.rawData.channels){const id=channel.id;if(!channel.data||id< -1||id>=n)continue;const plane=decodePrecisionPlane(channel.data,channel.compression,width,height,depth,!!layer.rawData.large),index=id===-1?n:id;for(let i=0;i<plane.length;i++)data[i*(n+1)+index]=space==='CMYK'&&id>=0?1-plane[i]:plane[i];}const result:PrecisionRaster={width,height,space,depth,data,...(profile?{profile}:{})};validatePrecision(result);return result;}\nexport function readPrecisionPSD(bytes:Uint8Array){const view=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength),mode=view.getUint16(24),space=({1:'Gray',3:'RGB',4:'CMYK',9:'Lab'} as const)[mode as 1|3|4|9],depth=view.getUint16(22) as PrecisionDepth;if(!space||![8,16,32].includes(depth)||depth===32&&!['RGB','Gray'].includes(space))throw Error('Unsupported native document color mode.');if(!ag.supportedColorModes.includes(mode))ag.supportedColorModes.push(mode);const psd=ag.readPsd(bytes,{useRawData:true,skipCompositeImageData:true,skipThumbnail:true,totalMemoryLimit:768*1024*1024}),profile=readResource(bytes,1039);return {psd,space,depth,profile};}\nconst join=(parts:Uint8Array[])=>{const out=new Uint8Array(parts.reduce((n,b)=>n+b.length,0));let at=0;for(const b of parts){out.set(b,at);at+=b.length;}return out;},word=(n:number,bytes=4)=>{const b=new Uint8Array(bytes),v=new DataView(b.buffer);if(bytes===8)v.setBigUint64(0,BigInt(n));else if(bytes===2)v.setUint16(0,n);else v.setUint32(0,n);return b;};\nexport function channelBytes(r:PrecisionRaster,id:number){const n=precisionChannels(r.space),stride=n+1,bpp=r.depth/8,bytes=new Uint8Array(r.width*r.height*bpp),view=new DataView(bytes.buffer);for(let i=0;i<r.width*r.height;i++){let v=r.data[i*stride+(id===-1?n:id)];if(r.space==='CMYK'&&id>=0)v=1-v;if(r.depth===32)view.setFloat32(i*4,v);else if(r.depth===16)view.setUint16(i*2,Math.round(Math.max(0,Math.min(1,v))*65535));else bytes[i]=Math.round(Math.max(0,Math.min(1,v))*255);}return bytes;}",
      "ref": "working-copy-2026-10-22",
      "sha256": "8790a9751d9d79957daa769a0e2b914164b38e239c87a6328fb6f0fb2acb56dc"
    },
    {
      "file": "app/studio/precision-document.ts",
      "start": 40,
      "end": 41,
      "code": "export async function convertDocumentPrecision(doc:StudioDoc,space:PrecisionSpace,depth:PrecisionDepth,profile?:Uint8Array,wasmBinary?:Uint8Array){if(doc.duotone){const c=await composite(doc,true);doc={...doc,duotone:undefined,precision:undefined,groups:undefined,artboards:undefined,layers:[makeLayer({kind:'image',name:'Converted Duotone',width:doc.width,height:doc.height,src:c.toDataURL()})]};}const working:PrecisionDocument={space,depth,profile:profileString(profile)},layers:Layer[]=[];for(const l of doc.layers){if(l.kind==='adjustment'){layers.push(l);continue;}const source=doc.precision&&!(space==='RGB'&&depth===8&&l.raw)?await precisionLayer(l,doc.precision,{masks:false,wasmBinary}):floatCanvas(await layerSurface({...l,mask:undefined,vectorMask:undefined})),pixels=await convertPrecision(source,space,depth,profile,wasmBinary),src=(await precisionCanvas(pixels,wasmBinary)).toDataURL();layers.push(bakedPrecisionLayer(l,pixels,src));}const next:StudioDoc={...doc,version:6 as const,precision:working,layers};if(space==='RGB'&&depth===8&&!profile){next.precision=undefined;next.layers=layers.map(l=>({...l,precision:undefined,precisionSource:undefined}));}else await compositePrecisionDocument(next,wasmBinary);return next;}\nexport async function adjustPrecisionLayer(doc:StudioDoc,l:Layer,a:PrecisionAdjustment,wasmBinary?:Uint8Array){if(!doc.precision)throw Error('Choose Image > Color Mode and Precision first.');const r=await precisionLayer(l,doc.precision,{masks:false,wasmBinary}),selection=doc.selection?selectionForLayer(doc.selection,l):undefined,edited=adjustPrecision(r,a,selection?.alpha),src=(await precisionCanvas(edited,wasmBinary)).toDataURL();return{...doc,layers:doc.layers.map(x=>x.id===l.id?bakedPrecisionLayer(x,edited,src):x)};}",
      "ref": "working-copy-2026-10-22",
      "sha256": "1cb4542a3a674c09aedb4f71167539b0fef90846e5d899acea72eabc0f97b481"
    }
  ],
  "productionUI": {
    "episode": 30,
    "checkedAt": "2026-10-22",
    "input": "AI-generated adult portrait, 8-bit PNG; conversion cannot restore missing source detail",
    "rgb32": {
      "precision": {
        "space": "RGB",
        "depth": 32
      },
      "plus1ExposureGainMaxError": 0,
      "valuesAboveOne": 350081,
      "maximum": 1.964501142501831,
      "alphaUnchanged": true,
      "psdHeader": {
        "version": 1,
        "height": 1024,
        "width": 1536,
        "depth": 32,
        "mode": 3
      },
      "psdReopenMaxError": 0,
      "minus1AfterPSDReopenMaxError": 0
    },
    "lab16": {
      "precision": {
        "space": "Lab",
        "depth": 16
      },
      "psdHeader": {
        "version": 1,
        "height": 1024,
        "width": 1536,
        "depth": 16,
        "mode": 9
      },
      "psdReopenMaxError": 7.62939453125e-06,
      "psdReopenMeanError": 2.8743736493197503e-06
    },
    "passed": true
  },
  "historicalReports": [
    {
      "file": "precision-integrated-native-results.json",
      "sha256": "c9ea83d56b7bb4a112c37313abddaeddc9d47b31ba4e0f47a727f40eb3e46ed5",
      "results": {
        "passed": true,
        "checks": [
          {
            "name": "tiff-ui-rgb16.psd",
            "space": "RGB",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "tiff-ui-rgb32.psd",
            "space": "RGB",
            "depth": 32,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "tiff-ui-cmyk16.psd",
            "space": "CMYK",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "tiff-ui-lab16.psd",
            "space": "Lab",
            "depth": 16,
            "maxError": 1.531839370727539e-05,
            "iccPreserved": true
          },
          {
            "name": "precision-linked-rgb16.psd",
            "space": "RGB",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "precision-linked-rgb32.psd",
            "space": "RGB",
            "depth": 32,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "precision-linked-cmyk16.psd",
            "space": "CMYK",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "precision-linked-lab16.psd",
            "space": "Lab",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "precision-apply-rgb16.psd",
            "space": "RGB",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "precision-apply-rgb32.psd",
            "space": "RGB",
            "depth": 32,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "precision-apply-cmyk16.psd",
            "space": "CMYK",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          },
          {
            "name": "precision-apply-lab16.psd",
            "space": "Lab",
            "depth": 16,
            "maxError": 0,
            "iccPreserved": true
          }
        ],
        "nativeEditableSmartContents": [
          "PASS precision-smart-rgb16.psd editable native contents",
          "PASS precision-smart-rgb16.psb editable native contents",
          "PASS precision-smart-rgb32.psd editable native contents",
          "PASS precision-smart-rgb32.psb editable native contents"
        ]
      },
      "freshRun": false
    },
    {
      "file": "precision-raster-render-results.json",
      "sha256": "750dd0658b1452a467a54918957100c5100c34fe8e90ca7f1ea04ffc7f8c8b5b",
      "results": {
        "passed": true,
        "checks": [
          "Float32 lossless persistence and more than 900 distinct adjusted 16-bit values",
          "HDR values above 1 and below 0 survive exposure/compositing/persistence",
          "Float ICC RGB/Lab roundtrip",
          "Native CMYK component edits retain sub-8-bit precision",
          "Oversized compressed payload rejected"
        ],
        "labRoundtripMaxError": 8.66129994392395e-07
      },
      "freshRun": false
    }
  ]
}