Skip to content

Commit 3aac9c6

Browse files
zephyrtroniumgopherbot
authored andcommitted
draw: add fast paths for RGBA64Image
Go 1.17 added image.RGBA64Image and draw.RGBA64Image interfaces which use color.RGBA64 instead of color.Color in order to avoid heap allocations on pixel operations. Fast paths were added to image/draw for drawing with these images, but not to x/image/draw. This CL adds them. Fixes golang/go#62423 goos: windows goarch: amd64 pkg: golang.org/x/image/draw cpu: AMD Ryzen 9 7900X 12-Core Processor │ old.bench │ new.bench │ │ sec/op │ sec/op vs base │ SimpleScaleCopy-24 7.425µ ± 0% 7.581µ ± 0% +2.10% (p=0.000 n=20) SimpleTransformCopy-24 7.473µ ± 1% 7.678µ ± 1% +2.74% (p=0.000 n=20) SimpleTransformScale-24 440.7µ ± 0% 442.6µ ± 0% +0.44% (p=0.012 n=20) ScaleNNLargeDown-24 155.3µ ± 4% 156.9µ ± 2% ~ (p=0.495 n=20) ScaleABLargeDown-24 843.4µ ± 0% 850.7µ ± 1% +0.87% (p=0.000 n=20) ScaleBLLargeDown-24 102.7m ± 0% 102.7m ± 1% ~ (p=0.779 n=20) ScaleCRLargeDown-24 165.6m ± 0% 168.7m ± 1% +1.84% (p=0.000 n=20) ScaleNNDown-24 42.53µ ± 1% 43.00µ ± 1% +1.10% (p=0.000 n=20) ScaleABDown-24 149.3µ ± 0% 151.5µ ± 1% +1.52% (p=0.000 n=20) ScaleBLDown-24 1.347m ± 1% 1.367m ± 1% +1.43% (p=0.000 n=20) ScaleCRDown-24 2.635m ± 1% 2.663m ± 1% +1.09% (p=0.007 n=20) ScaleNNUp-24 2.108m ± 0% 2.128m ± 2% +0.93% (p=0.023 n=20) ScaleABUp-24 7.493m ± 0% 7.594m ± 1% +1.35% (p=0.000 n=20) ScaleBLUp-24 6.105m ± 3% 6.410m ± 3% +5.01% (p=0.001 n=20) ScaleCRUp-24 10.297m ± 9% 9.640m ± 3% ~ (p=0.121 n=20) ScaleNNSrcRGBA-24 111.3µ ± 1% 108.6µ ± 2% -2.37% (p=0.000 n=20) ScaleNNSrcUnif-24 1.410µ ± 1% 1.397µ ± 1% ~ (p=0.103 n=20) ScaleNNOverRGBA-24 174.0µ ± 1% 170.5µ ± 2% -1.98% (p=0.004 n=20) ScaleNNOverUnif-24 90.17µ ± 1% 90.12µ ± 1% ~ (p=0.490 n=20) TformNNSrcRGBA-24 103.4µ ± 1% 105.8µ ± 1% +2.25% (p=0.000 n=20) TformNNSrcUnif-24 38.61µ ± 1% 40.80µ ± 1% +5.69% (p=0.000 n=20) TformNNOverRGBA-24 150.3µ ± 0% 155.5µ ± 2% +3.49% (p=0.000 n=20) TformNNOverUnif-24 35.16µ ± 2% 34.75µ ± 2% -1.18% (p=0.015 n=20) ScaleABSrcGray-24 154.5µ ± 2% 151.8µ ± 1% -1.69% (p=0.006 n=20) ScaleABSrcNRGBA-24 482.0µ ± 1% 475.9µ ± 1% -1.26% (p=0.002 n=20) ScaleABSrcRGBA-24 418.2µ ± 0% 416.0µ ± 1% ~ (p=0.108 n=20) ScaleABSrcYCbCr-24 849.4µ ± 0% 845.6µ ± 1% -0.45% (p=0.015 n=20) ScaleABSrcRGBA64-24 1616.6µ ± 2% 467.8µ ± 2% -71.06% (p=0.000 n=20) ScaleABOverGray-24 152.0µ ± 1% 148.2µ ± 1% -2.51% (p=0.000 n=20) ScaleABOverNRGBA-24 511.8µ ± 1% 510.2µ ± 1% ~ (p=0.640 n=20) ScaleABOverRGBA-24 480.1µ ± 1% 475.5µ ± 0% -0.94% (p=0.000 n=20) ScaleABOverYCbCr-24 861.1µ ± 1% 843.2µ ± 0% -2.08% (p=0.000 n=20) ScaleABOverRGBA64-24 1723.2µ ± 2% 538.0µ ± 0% -68.78% (p=0.000 n=20) TformABSrcGray-24 148.6µ ± 1% 142.6µ ± 0% -4.01% (p=0.000 n=20) TformABSrcNRGBA-24 363.3µ ± 2% 356.2µ ± 0% -1.95% (p=0.000 n=20) TformABSrcRGBA-24 301.0µ ± 0% 296.5µ ± 0% -1.49% (p=0.000 n=20) TformABSrcYCbCr-24 415.1µ ± 0% 409.1µ ± 0% -1.45% (p=0.000 n=20) TformABSrcRGBA64-24 1068.9µ ± 2% 337.7µ ± 1% -68.41% (p=0.000 n=20) TformABOverGray-24 146.0µ ± 1% 143.2µ ± 0% -1.88% (p=0.000 n=20) TformABOverNRGBA-24 394.6µ ± 1% 389.0µ ± 0% -1.43% (p=0.000 n=20) TformABOverRGBA-24 341.0µ ± 1% 338.1µ ± 0% -0.83% (p=0.001 n=20) TformABOverYCbCr-24 414.4µ ± 1% 410.6µ ± 1% -0.91% (p=0.049 n=20) TformABOverRGBA64-24 1108.7µ ± 2% 389.4µ ± 1% -64.88% (p=0.000 n=20) ScaleCRSrcGray-24 4.065m ± 2% 3.979m ± 0% -2.12% (p=0.000 n=20) ScaleCRSrcNRGBA-24 13.66m ± 1% 13.41m ± 1% -1.79% (p=0.007 n=20) ScaleCRSrcRGBA-24 9.258m ± 3% 9.091m ± 1% -1.80% (p=0.002 n=20) ScaleCRSrcYCbCr-24 23.53m ± 0% 22.85m ± 1% -2.89% (p=0.000 n=20) ScaleCRSrcRGBA64-24 42.76m ± 2% 13.13m ± 1% -69.31% (p=0.000 n=20) ScaleCROverGray-24 4.110m ± 1% 3.973m ± 1% -3.33% (p=0.000 n=20) ScaleCROverNRGBA-24 14.74m ± 1% 13.50m ± 0% -8.41% (p=0.000 n=20) ScaleCROverRGBA-24 9.504m ± 1% 9.301m ± 1% -2.14% (p=0.000 n=20) ScaleCROverYCbCr-24 23.42m ± 1% 22.86m ± 0% -2.38% (p=0.000 n=20) ScaleCROverRGBA64-24 43.47m ± 1% 13.07m ± 1% -69.93% (p=0.000 n=20) TformCRSrcGray-24 1.253m ± 1% 1.225m ± 0% -2.24% (p=0.000 n=20) TformCRSrcNRGBA-24 2.141m ± 2% 2.050m ± 1% -4.24% (p=0.000 n=20) TformCRSrcRGBA-24 1.810m ± 1% 1.771m ± 0% -2.15% (p=0.002 n=20) TformCRSrcYCbCr-24 2.404m ± 1% 2.403m ± 1% ~ (p=0.698 n=20) TformCRSrcRGBA64-24 5.150m ± 1% 2.197m ± 1% -57.34% (p=0.000 n=20) TformCROverGray-24 1.251m ± 0% 1.223m ± 0% -2.23% (p=0.000 n=20) TformCROverNRGBA-24 2.081m ± 1% 2.037m ± 0% -2.13% (p=0.000 n=20) TformCROverRGBA-24 1.809m ± 1% 1.793m ± 2% ~ (p=0.149 n=20) TformCROverYCbCr-24 2.444m ± 0% 2.400m ± 1% -1.82% (p=0.000 n=20) TformCROverRGBA64-24 5.303m ± 2% 2.221m ± 1% -58.12% (p=0.000 n=20) geomean 930.7µ 804.7µ -13.54% │ old.bench │ new.bench │ │ B/op │ B/op vs base │ ScaleNNLargeDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABLargeDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleBLLargeDown-24 1.407Mi ± 0% 1.407Mi ± 0% ~ (p=0.283 n=20) ScaleCRLargeDown-24 2.010Mi ± 0% 2.345Mi ± 14% +16.67% (p=0.000 n=20) ScaleNNDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleBLDown-24 1.704Ki ± 1% 1.721Ki ± 3% ~ (p=0.109 n=20) ScaleCRDown-24 3.309Ki ± 2% 3.342Ki ± 2% ~ (p=0.568 n=20) ScaleNNUp-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABUp-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleBLUp-24 50.96Ki ± 2% 52.73Ki ± 4% +3.47% (p=0.002 n=20) ScaleCRUp-24 86.54Ki ± 14% 79.09Ki ± 2% ~ (p=0.061 n=20) ScaleNNSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNSrcUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNOverUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNSrcUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNOverUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcRGBA64-24 937.5Ki ± 0% 0.0Ki ± 0% -100.00% (p=0.000 n=20) ScaleABOverGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverRGBA64-24 937.5Ki ± 0% 0.0Ki ± 0% -100.00% (p=0.000 n=20) TformABSrcGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcRGBA64-24 600.8Ki ± 0% 0.0Ki ± 0% -100.00% (p=0.000 n=20) TformABOverGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverRGBA64-24 600.8Ki ± 0% 0.0Ki ± 0% -100.00% (p=0.000 n=20) ScaleCRSrcGray-24 16.51Ki ± 1% 15.97Ki ± 1% -3.32% (p=0.000 n=20) ScaleCRSrcNRGBA-24 59.33Ki ± 5% 57.21Ki ± 4% ~ (p=0.142 n=20) ScaleCRSrcRGBA-24 37.55Ki ± 2% 36.41Ki ± 2% -3.03% (p=0.001 n=20) ScaleCRSrcYCbCr-24 98.08Ki ± 2% 98.08Ki ± 2% ~ (p=0.952 n=20) ScaleCRSrcRGBA64-24 24624.95Ki ± 0% 55.21Ki ± 4% -99.78% (p=0.000 n=20) ScaleCROverGray-24 16.46Ki ± 1% 15.97Ki ± 1% -2.99% (p=0.000 n=20) ScaleCROverNRGBA-24 61.62Ki ± 3% 59.70Ki ± 5% -3.10% (p=0.015 n=20) ScaleCROverRGBA-24 38.76Ki ± 2% 37.55Ki ± 1% -3.12% (p=0.000 n=20) ScaleCROverYCbCr-24 98.08Ki ± 2% 98.08Ki ± 2% ~ (p=0.232 n=20) ScaleCROverRGBA64-24 24624.95Ki ± 0% 55.21Ki ± 2% -99.78% (p=0.000 n=20) TformCRSrcGray-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcNRGBA-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcRGBA-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcYCbCr-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcRGBA64-24 2396479.00 ± 0% 96.00 ± 0% -100.00% (p=0.000 n=20) TformCROverGray-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCROverNRGBA-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCROverRGBA-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCROverYCbCr-24 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=20) ¹ TformCROverRGBA64-24 2396479.00 ± 0% 96.00 ± 0% -100.00% (p=0.000 n=20) geomean ² ? ² ³ ¹ all samples are equal ² summaries must be >0 to compute geomean ³ ratios must be >0 to compute geomean │ old.bench │ new.bench │ │ allocs/op │ allocs/op vs base │ ScaleNNLargeDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABLargeDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleBLLargeDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCRLargeDown-24 0.000 ± 0% 1.000 ± ? ? (p=0.000 n=20) ScaleNNDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleBLDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCRDown-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNUp-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABUp-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleBLUp-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCRUp-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNSrcUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleNNOverUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNSrcUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformNNOverUnif-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABSrcRGBA64-24 120.0k ± 0% 0.0k ± 0% -100.00% (p=0.000 n=20) ScaleABOverGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleABOverRGBA64-24 120.0k ± 0% 0.0k ± 0% -100.00% (p=0.000 n=20) TformABSrcGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABSrcRGBA64-24 76.90k ± 0% 0.00k ± 0% -100.00% (p=0.000 n=20) TformABOverGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ TformABOverRGBA64-24 76.90k ± 0% 0.00k ± 0% -100.00% (p=0.000 n=20) ScaleCRSrcGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCRSrcNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCRSrcRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCRSrcYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCRSrcRGBA64-24 3.129M ± 0% 0.000M ± 0% -100.00% (p=0.000 n=20) ScaleCROverGray-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCROverNRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCROverRGBA-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCROverYCbCr-24 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ ScaleCROverRGBA64-24 3.129M ± 0% 0.000M ± 0% -100.00% (p=0.000 n=20) TformCRSrcGray-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcNRGBA-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcRGBA-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcYCbCr-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCRSrcRGBA64-24 299549.000 ± 0% 2.000 ± 0% -100.00% (p=0.000 n=20) TformCROverGray-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCROverNRGBA-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCROverRGBA-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCROverYCbCr-24 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=20) ¹ TformCROverRGBA64-24 299549.000 ± 0% 2.000 ± 0% -100.00% (p=0.000 n=20) geomean ² ? ² ¹ all samples are equal ² summaries must be >0 to compute geomean Change-Id: I37778e925cce13c4fec65c9e6d57e205440e2a06 Reviewed-on: https://go-review.googlesource.com/c/image/+/525255 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Nigel Tao <[email protected]> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent fa10be5 commit 3aac9c6

File tree

3 files changed

+2515
-501
lines changed

3 files changed

+2515
-501
lines changed

draw/gen.go

Lines changed: 195 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"flag"
1313
"fmt"
1414
"go/format"
15-
"io/ioutil"
1615
"log"
1716
"os"
1817
"strings"
@@ -45,7 +44,7 @@ func main() {
4544
if err != nil {
4645
log.Fatal(err)
4746
}
48-
if err := ioutil.WriteFile("impl.go", out, 0660); err != nil {
47+
if err := os.WriteFile("impl.go", out, 0660); err != nil {
4948
log.Fatal(err)
5049
}
5150
}
@@ -62,7 +61,9 @@ var (
6261
{"*image.RGBA", "*image.NRGBA"},
6362
{"*image.RGBA", "*image.RGBA"},
6463
{"*image.RGBA", "*image.YCbCr"},
64+
{"*image.RGBA", "image.RGBA64Image"},
6565
{"*image.RGBA", "image.Image"},
66+
{"RGBA64Image", "image.RGBA64Image"},
6667
{"Image", "image.Image"},
6768
}
6869
dTypes, sTypes []string
@@ -234,13 +235,21 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
234235
return ";"
235236
case "Image":
236237
s := ""
237-
if d.sType == "image.Image" {
238+
if d.sType == "image.Image" || d.sType == "image.RGBA64Image" {
238239
s = "srcMask, smp := opts.SrcMask, opts.SrcMaskP\n"
239240
}
240241
return s +
241242
"dstMask, dmp := opts.DstMask, opts.DstMaskP\n" +
242243
"dstColorRGBA64 := &color.RGBA64{}\n" +
243244
"dstColor := color.Color(dstColorRGBA64)"
245+
case "RGBA64Image":
246+
s := ""
247+
if d.sType == "image.Image" || d.sType == "image.RGBA64Image" {
248+
s = "srcMask, smp := opts.SrcMask, opts.SrcMaskP\n"
249+
}
250+
return s +
251+
"dstMask, dmp := opts.DstMask, opts.DstMaskP\n" +
252+
"dstColorRGBA64 := color.RGBA64{}\n"
244253
}
245254

246255
case "preInner":
@@ -255,7 +264,7 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
255264
switch d.sType {
256265
default:
257266
return ";"
258-
case "image.Image":
267+
case "image.Image", "image.RGBA64Image":
259268
return "srcMask, smp := opts.SrcMask, opts.SrcMaskP"
260269
}
261270

@@ -334,6 +343,10 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
334343
"$0g := uint32($1g)\n"+
335344
"$0b := uint32($1b)",
336345
)
346+
case "image.RGBA64Image":
347+
return argf(args, ""+
348+
"$0 := color.RGBA64{uint16($1r), uint16($1g), uint16($1b), uint16($1a)}",
349+
)
337350
}
338351

339352
case "outputu":
@@ -364,14 +377,62 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
364377
"dstColorRGBA64.A = uint16(qa*$2a1/0xffff + $2a)\n"+
365378
"dst.Set($0, $1, dstColor)",
366379
)
380+
case "RGBA64Image":
381+
switch d.sType {
382+
default:
383+
return argf(args, ""+
384+
"q := dst.RGBA64At($0, $1)\n"+
385+
"if dstMask != nil {\n"+
386+
" _, _, _, ma := dstMask.At(dmp.X + $0, dmp.Y + $1).RGBA()\n"+
387+
" $2r = $2r * ma / 0xffff\n"+
388+
" $2g = $2g * ma / 0xffff\n"+
389+
" $2b = $2b * ma / 0xffff\n"+
390+
" $2a = $2a * ma / 0xffff\n"+
391+
"}\n"+
392+
"$2a1 := 0xffff - $2a\n"+
393+
"dstColorRGBA64.R = uint16(uint32(q.R)*$2a1/0xffff + $2r)\n"+
394+
"dstColorRGBA64.G = uint16(uint32(q.G)*$2a1/0xffff + $2g)\n"+
395+
"dstColorRGBA64.B = uint16(uint32(q.B)*$2a1/0xffff + $2b)\n"+
396+
"dstColorRGBA64.A = uint16(uint32(q.A)*$2a1/0xffff + $2a)\n"+
397+
"dst.Set($0, $1, dstColorRGBA64)",
398+
)
399+
case "image.RGBA64Image":
400+
return argf(args, ""+
401+
"q := dst.RGBA64At($0, $1)\n"+
402+
"if dstMask != nil {\n"+
403+
" _, _, _, ma := dstMask.At(dmp.X + $0, dmp.Y + $1).RGBA()\n"+
404+
" $2.R = uint16(uint32($2.R) * ma / 0xffff)\n"+
405+
" $2.G = uint16(uint32($2.G) * ma / 0xffff)\n"+
406+
" $2.B = uint16(uint32($2.B) * ma / 0xffff)\n"+
407+
" $2.A = uint16(uint32($2.A) * ma / 0xffff)\n"+
408+
"}\n"+
409+
"$2a1 := 0xffff - uint32($2.A)\n"+
410+
"dstColorRGBA64.R = uint16(uint32(q.R)*$2a1/0xffff + uint32($2.R))\n"+
411+
"dstColorRGBA64.G = uint16(uint32(q.G)*$2a1/0xffff + uint32($2.G))\n"+
412+
"dstColorRGBA64.B = uint16(uint32(q.B)*$2a1/0xffff + uint32($2.B))\n"+
413+
"dstColorRGBA64.A = uint16(uint32(q.A)*$2a1/0xffff + uint32($2.A))\n"+
414+
"dst.Set($0, $1, dstColorRGBA64)",
415+
)
416+
}
367417
case "*image.RGBA":
368-
return argf(args, ""+
369-
"$2a1 := (0xffff - $2a) * 0x101\n"+
370-
"dst.Pix[d+0] = uint8((uint32(dst.Pix[d+0])*$2a1/0xffff + $2r) >> 8)\n"+
371-
"dst.Pix[d+1] = uint8((uint32(dst.Pix[d+1])*$2a1/0xffff + $2g) >> 8)\n"+
372-
"dst.Pix[d+2] = uint8((uint32(dst.Pix[d+2])*$2a1/0xffff + $2b) >> 8)\n"+
373-
"dst.Pix[d+3] = uint8((uint32(dst.Pix[d+3])*$2a1/0xffff + $2a) >> 8)",
374-
)
418+
switch d.sType {
419+
default:
420+
return argf(args, ""+
421+
"$2a1 := (0xffff - $2a) * 0x101\n"+
422+
"dst.Pix[d+0] = uint8((uint32(dst.Pix[d+0])*$2a1/0xffff + $2r) >> 8)\n"+
423+
"dst.Pix[d+1] = uint8((uint32(dst.Pix[d+1])*$2a1/0xffff + $2g) >> 8)\n"+
424+
"dst.Pix[d+2] = uint8((uint32(dst.Pix[d+2])*$2a1/0xffff + $2b) >> 8)\n"+
425+
"dst.Pix[d+3] = uint8((uint32(dst.Pix[d+3])*$2a1/0xffff + $2a) >> 8)",
426+
)
427+
case "image.RGBA64Image":
428+
return argf(args, ""+
429+
"$2a1 := (0xffff - uint32($2.A)) * 0x101\n"+
430+
"dst.Pix[d+0] = uint8((uint32(dst.Pix[d+0])*$2a1/0xffff + uint32($2.R)) >> 8)\n"+
431+
"dst.Pix[d+1] = uint8((uint32(dst.Pix[d+1])*$2a1/0xffff + uint32($2.G)) >> 8)\n"+
432+
"dst.Pix[d+2] = uint8((uint32(dst.Pix[d+2])*$2a1/0xffff + uint32($2.B)) >> 8)\n"+
433+
"dst.Pix[d+3] = uint8((uint32(dst.Pix[d+3])*$2a1/0xffff + uint32($2.A)) >> 8)",
434+
)
435+
}
375436
}
376437

377438
case "Src":
@@ -401,6 +462,51 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
401462
" dst.Set($0, $1, dstColor)\n"+
402463
"}",
403464
)
465+
case "RGBA64Image":
466+
switch d.sType {
467+
default:
468+
return argf(args, ""+
469+
"if dstMask != nil {\n"+
470+
" q := dst.RGBA64At($0, $1)\n"+
471+
" _, _, _, ma := dstMask.At(dmp.X + $0, dmp.Y + $1).RGBA()\n"+
472+
" pr = pr * ma / 0xffff\n"+
473+
" pg = pg * ma / 0xffff\n"+
474+
" pb = pb * ma / 0xffff\n"+
475+
" pa = pa * ma / 0xffff\n"+
476+
" $2a1 := 0xffff - ma\n"+ // Note that this is ma, not $2a.
477+
" dstColorRGBA64.R = uint16(uint32(q.R)*$2a1/0xffff + $2r)\n"+
478+
" dstColorRGBA64.G = uint16(uint32(q.G)*$2a1/0xffff + $2g)\n"+
479+
" dstColorRGBA64.B = uint16(uint32(q.B)*$2a1/0xffff + $2b)\n"+
480+
" dstColorRGBA64.A = uint16(uint32(q.A)*$2a1/0xffff + $2a)\n"+
481+
" dst.Set($0, $1, dstColorRGBA64)\n"+
482+
"} else {\n"+
483+
" dstColorRGBA64.R = uint16($2r)\n"+
484+
" dstColorRGBA64.G = uint16($2g)\n"+
485+
" dstColorRGBA64.B = uint16($2b)\n"+
486+
" dstColorRGBA64.A = uint16($2a)\n"+
487+
" dst.Set($0, $1, dstColorRGBA64)\n"+
488+
"}",
489+
)
490+
case "image.RGBA64Image":
491+
return argf(args, ""+
492+
"if dstMask != nil {\n"+
493+
" q := dst.RGBA64At($0, $1)\n"+
494+
" _, _, _, ma := dstMask.At(dmp.X + $0, dmp.Y + $1).RGBA()\n"+
495+
" p.R = uint16(uint32(p.R) * ma / 0xffff)\n"+
496+
" p.G = uint16(uint32(p.G) * ma / 0xffff)\n"+
497+
" p.B = uint16(uint32(p.B) * ma / 0xffff)\n"+
498+
" p.A = uint16(uint32(p.A) * ma / 0xffff)\n"+
499+
" $2a1 := 0xffff - ma\n"+ // Note that this is ma, not $2a.
500+
" dstColorRGBA64.R = uint16(uint32(q.R)*$2a1/0xffff + uint32($2.R))\n"+
501+
" dstColorRGBA64.G = uint16(uint32(q.G)*$2a1/0xffff + uint32($2.G))\n"+
502+
" dstColorRGBA64.B = uint16(uint32(q.B)*$2a1/0xffff + uint32($2.B))\n"+
503+
" dstColorRGBA64.A = uint16(uint32(q.A)*$2a1/0xffff + uint32($2.A))\n"+
504+
" dst.Set($0, $1, dstColorRGBA64)\n"+
505+
"} else {\n"+
506+
" dst.Set($0, $1, $2)\n"+
507+
"}",
508+
)
509+
}
404510
case "*image.RGBA":
405511
switch d.sType {
406512
default:
@@ -425,6 +531,13 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
425531
"dst.Pix[d+2] = uint8($2b >> 8)\n"+
426532
"dst.Pix[d+3] = 0xff",
427533
)
534+
case "image.RGBA64Image":
535+
return argf(args, ""+
536+
"dst.Pix[d+0] = uint8($2.R >> 8)\n"+
537+
"dst.Pix[d+1] = uint8($2.G >> 8)\n"+
538+
"dst.Pix[d+2] = uint8($2.B >> 8)\n"+
539+
"dst.Pix[d+3] = uint8($2.A >> 8)",
540+
)
428541
}
429542
}
430543
}
@@ -462,6 +575,27 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
462575
"dstColorRGBA64.A = uint16(qa*$3a1/0xffff + $3a0)\n"+
463576
"dst.Set($0, $1, dstColor)",
464577
)
578+
case "RGBA64Image":
579+
ret = argf(args, ""+
580+
"q := dst.RGBA64At($0, $1)\n"+
581+
"$3r0 := uint32($2($3r * $4))\n"+
582+
"$3g0 := uint32($2($3g * $4))\n"+
583+
"$3b0 := uint32($2($3b * $4))\n"+
584+
"$3a0 := uint32($2($3a * $4))\n"+
585+
"if dstMask != nil {\n"+
586+
" _, _, _, ma := dstMask.At(dmp.X + $0, dmp.Y + $1).RGBA()\n"+
587+
" $3r0 = $3r0 * ma / 0xffff\n"+
588+
" $3g0 = $3g0 * ma / 0xffff\n"+
589+
" $3b0 = $3b0 * ma / 0xffff\n"+
590+
" $3a0 = $3a0 * ma / 0xffff\n"+
591+
"}\n"+
592+
"$3a1 := 0xffff - $3a0\n"+
593+
"dstColorRGBA64.R = uint16(uint32(q.R)*$3a1/0xffff + $3r0)\n"+
594+
"dstColorRGBA64.G = uint16(uint32(q.G)*$3a1/0xffff + $3g0)\n"+
595+
"dstColorRGBA64.B = uint16(uint32(q.B)*$3a1/0xffff + $3b0)\n"+
596+
"dstColorRGBA64.A = uint16(uint32(q.A)*$3a1/0xffff + $3a0)\n"+
597+
"dst.SetRGBA64($0, $1, dstColorRGBA64)",
598+
)
465599
case "*image.RGBA":
466600
ret = argf(args, ""+
467601
"$3r0 := uint32($2($3r * $4))\n"+
@@ -503,6 +637,29 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
503637
" dst.Set($0, $1, dstColor)\n"+
504638
"}",
505639
)
640+
case "RGBA64Image":
641+
ret = argf(args, ""+
642+
"if dstMask != nil {\n"+
643+
" q := dst.RGBA64At($0, $1)\n"+
644+
" _, _, _, ma := dstMask.At(dmp.X + $0, dmp.Y + $1).RGBA()\n"+
645+
" pr := uint32($2($3r * $4)) * ma / 0xffff\n"+
646+
" pg := uint32($2($3g * $4)) * ma / 0xffff\n"+
647+
" pb := uint32($2($3b * $4)) * ma / 0xffff\n"+
648+
" pa := uint32($2($3a * $4)) * ma / 0xffff\n"+
649+
" pa1 := 0xffff - ma\n"+ // Note that this is ma, not pa.
650+
" dstColorRGBA64.R = uint16(uint32(q.R)*pa1/0xffff + pr)\n"+
651+
" dstColorRGBA64.G = uint16(uint32(q.G)*pa1/0xffff + pg)\n"+
652+
" dstColorRGBA64.B = uint16(uint32(q.B)*pa1/0xffff + pb)\n"+
653+
" dstColorRGBA64.A = uint16(uint32(q.A)*pa1/0xffff + pa)\n"+
654+
" dst.SetRGBA64($0, $1, dstColorRGBA64)\n"+
655+
"} else {\n"+
656+
" dstColorRGBA64.R = $2($3r * $4)\n"+
657+
" dstColorRGBA64.G = $2($3g * $4)\n"+
658+
" dstColorRGBA64.B = $2($3b * $4)\n"+
659+
" dstColorRGBA64.A = $2($3a * $4)\n"+
660+
" dst.SetRGBA64($0, $1, dstColorRGBA64)\n"+
661+
"}",
662+
)
506663
case "*image.RGBA":
507664
switch d.sType {
508665
default:
@@ -560,7 +717,7 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
560717
"%sr%s, %sg%s, %sb%s, %sa%s := src.At(%s, %s).RGBA()\n",
561718
lhs, tmp, lhs, tmp, lhs, tmp, lhs, tmp, args[0], args[1],
562719
)
563-
if d.dType == "" || d.dType == "Image" {
720+
if d.dType == "" || d.dType == "Image" || d.dType == "RGBA64Image" {
564721
fmt.Fprintf(buf, ""+
565722
"if srcMask != nil {\n"+
566723
" _, _, _, ma := srcMask.At(smp.X+%s, smp.Y+%s).RGBA()\n"+
@@ -576,6 +733,24 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
576733
lhs, tmp, lhs, tmp,
577734
)
578735
}
736+
case "image.RGBA64Image":
737+
fmt.Fprintf(buf, ""+
738+
"%s%s := src.RGBA64At(%s, %s)\n",
739+
lhs, tmp, args[0], args[1],
740+
)
741+
if d.dType == "" || d.dType == "Image" || d.dType == "RGBA64Image" {
742+
fmt.Fprintf(buf, ""+
743+
"if srcMask != nil {\n"+
744+
" _, _, _, ma := srcMask.At(smp.X+%[1]s, smp.Y+%[2]s).RGBA()\n"+
745+
" %[3]s%[4]s.R = uint16(uint32(%[3]s%[4]s.R) * ma / 0xffff)\n"+
746+
" %[3]s%[4]s.G = uint16(uint32(%[3]s%[4]s.G) * ma / 0xffff)\n"+
747+
" %[3]s%[4]s.B = uint16(uint32(%[3]s%[4]s.B) * ma / 0xffff)\n"+
748+
" %[3]s%[4]s.A = uint16(uint32(%[3]s%[4]s.A) * ma / 0xffff)\n"+
749+
"}\n",
750+
args[0], args[1],
751+
lhs, tmp,
752+
)
753+
}
579754
case "*image.Gray":
580755
fmt.Fprintf(buf, ""+
581756
"%si := %s\n"+
@@ -647,6 +822,14 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
647822
lhs, eqOp, lhs, extra,
648823
lhs, eqOp, lhs, extra,
649824
)
825+
case "image.RGBA64Image":
826+
fmt.Fprintf(buf, ""+
827+
"%[1]sr %[2]s float64(%[3]su.R)%[4]s\n"+
828+
"%[1]sg %[2]s float64(%[3]su.G)%[4]s\n"+
829+
"%[1]sb %[2]s float64(%[3]su.B)%[4]s\n"+
830+
"%[1]sa %[2]s float64(%[3]su.A)%[4]s\n",
831+
lhs, eqOp, lhs, extra,
832+
)
650833
}
651834
}
652835

0 commit comments

Comments
 (0)