|
| 1 | +Sizes |
| 2 | + extensions [ bitmap ] |
| 3 | + globals [ image ] |
| 4 | + O> set image bitmap:import "extensions/bitmap/test-images/BitmapTest.jpg" |
| 5 | + bitmap:width image => 1024 |
| 6 | + bitmap:height image => 768 |
| 7 | + |
| 8 | +Base64 |
| 9 | + extensions [ bitmap ] |
| 10 | + globals [ base64 image pcolors ] |
| 11 | + O> set image bitmap:import "extensions/bitmap/test-images/BitmapTest.jpg" |
| 12 | + O> set image bitmap:scaled image 64 48 |
| 13 | + O> bitmap:copy-to-pcolors image true |
| 14 | + O> set pcolors map [ p -> [pcolor] of p ] (sort patches) |
| 15 | + O> set base64 bitmap:to-base64 image |
| 16 | + substring base64 0 49 => "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAwCAYAAAChS3wfAAAnc" |
| 17 | + O> set image bitmap:from-base64 base64 |
| 18 | + O> bitmap:copy-to-pcolors image true |
| 19 | + pcolors = map [ p -> [pcolor] of p ] (sort patches) => true |
| 20 | + |
| 21 | +AverageColor |
| 22 | + extensions [ bitmap ] |
| 23 | + globals [ image ] |
| 24 | + O> set image bitmap:import "extensions/bitmap/test-images/BitmapTest.jpg" |
| 25 | + bitmap:average-color image => [139.44314320882162 94.44454701741536 88.15065892537434] |
| 26 | + |
| 27 | +FromView |
| 28 | + extensions [ bitmap ] |
| 29 | + globals [ image1 image2 ] |
| 30 | + O> set image1 bitmap:import "extensions/bitmap/test-images/BitmapTest.jpg" |
| 31 | + O> bitmap:copy-to-drawing image1 0 0 |
| 32 | + O> set image1 bitmap:from-view |
| 33 | + O> set image2 bitmap:import "extensions/bitmap/test-images/BitmapTest-view-0x0.png" |
| 34 | + bitmap:to-base64 image1 = bitmap:to-base64 image2 => true |
| 35 | + O> clear-drawing |
| 36 | + O> bitmap:copy-to-drawing image1 50 50 |
| 37 | + O> set image1 bitmap:from-view |
| 38 | + O> set image2 bitmap:import "extensions/bitmap/test-images/BitmapTest-view-50x50.png" |
| 39 | + bitmap:to-base64 image1 = bitmap:to-base64 image2 => true |
| 40 | + |
| 41 | +DifferenceRgb |
| 42 | + extensions [ bitmap ] |
| 43 | + globals [ image1 image2 ] |
| 44 | + O> set image1 bitmap:import "extensions/bitmap/test-images/BitmapTest-view-0x0.png" |
| 45 | + O> random-seed 12315 |
| 46 | + O> create-turtles 30 [ set color red pen-down forward 30 ] |
| 47 | + O> set image2 bitmap:from-view |
| 48 | + O> set image2 bitmap:difference-rgb image1 image2 |
| 49 | + O> bitmap:export image2 "../huh-rgb.png" |
| 50 | + O> set image1 bitmap:import "extensions/bitmap/test-images/BitmapTest-difference-rgb.png" |
| 51 | + bitmap:to-base64 image1 = bitmap:to-base64 image2 => true |
| 52 | + |
| 53 | +Channel |
| 54 | + extensions [ bitmap ] |
| 55 | + globals [ image1 image2 image3 ] |
| 56 | + O> set image1 bitmap:import "extensions/bitmap/test-images/BitmapTest.jpg" |
| 57 | + |
| 58 | + O> set image2 bitmap:channel image1 0 |
| 59 | + O> set image3 bitmap:import "extensions/bitmap/test-images/BitmapTest-alpha.png" |
| 60 | + bitmap:to-base64 image2 = bitmap:to-base64 image3 => true |
| 61 | + |
| 62 | + O> set image2 bitmap:channel image1 1 |
| 63 | + O> set image3 bitmap:import "extensions/bitmap/test-images/BitmapTest-red.png" |
| 64 | + bitmap:to-base64 image2 = bitmap:to-base64 image3 => true |
| 65 | + |
| 66 | + O> set image2 bitmap:channel image1 2 |
| 67 | + O> set image3 bitmap:import "extensions/bitmap/test-images/BitmapTest-green.png" |
| 68 | + bitmap:to-base64 image2 = bitmap:to-base64 image3 => true |
| 69 | + |
| 70 | + O> set image2 bitmap:channel image1 3 |
| 71 | + O> set image3 bitmap:import "extensions/bitmap/test-images/BitmapTest-blue.png" |
| 72 | + bitmap:to-base64 image2 = bitmap:to-base64 image3 => true |
| 73 | + |
| 74 | +ToGrayscale |
| 75 | + extensions [ bitmap ] |
| 76 | + globals [ image1 image2 image3 ] |
| 77 | + O> set image1 bitmap:import "extensions/bitmap/test-images/BitmapTest.jpg" |
| 78 | + |
| 79 | + O> set image2 bitmap:to-grayscale image1 |
| 80 | + O> set image3 bitmap:import "extensions/bitmap/test-images/BitmapTest-grayscale.png" |
| 81 | + bitmap:to-base64 image2 = bitmap:to-base64 image3 => true |
0 commit comments