[squeak-dev] The Trunk: Graphics-ar.163.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Dec 22 04:16:19 UTC 2010
Andreas Raab uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-ar.163.mcz
==================== Summary ====================
Name: Graphics-ar.163
Author: ar
Time: 21 December 2010, 8:14:37.207 pm
UUID: 60c65f7c-7f73-7d4c-a1ac-aef0bb1d7e89
Ancestors: Graphics-fbs.162
For some strange reasons the BMP read/write primitives weren't enabled. Probably an oversight on my behalf. The primitives improve performance by 10-20x.
=============== Diff against Graphics-fbs.162 ===============
Item was changed:
----- Method: BMPReadWriter>>nextPutImage: (in category 'writing') -----
nextPutImage: aForm
+ | bhSize rowBytes rgb data colorValues depth image ppw scanLineLen pixline |
- | bhSize rowBytes rgb data colorValues depth image ppw scanLineLen |
depth := aForm depth.
depth := #(1 4 8 32 ) detect: [ :each | each >= depth].
image := aForm asFormOfDepth: depth.
image unhibernate.
bhSize := 14. "# bytes in file header"
biSize := 40. "info header size in bytes"
biWidth := image width.
biHeight := image height.
biClrUsed := depth = 32 ifTrue: [0] ifFalse:[1 << depth]. "No. color table entries"
bfOffBits := biSize + bhSize + (4*biClrUsed).
rowBytes := ((depth min: 24) * biWidth + 31 // 32) * 4.
biSizeImage := biHeight * rowBytes.
"Write the file header"
stream position: 0.
stream nextLittleEndianNumber: 2 put: 19778. "bfType = BM"
stream nextLittleEndianNumber: 4 put: bfOffBits + biSizeImage. "Entire file size in bytes"
stream nextLittleEndianNumber: 4 put: 0. "bfReserved"
stream nextLittleEndianNumber: 4 put: bfOffBits. "Offset of bitmap data from start of hdr (and file)"
"Write the bitmap info header"
stream position: bhSize.
stream nextLittleEndianNumber: 4 put: biSize. "info header size in bytes"
stream nextLittleEndianNumber: 4 put: image width. "biWidth"
stream nextLittleEndianNumber: 4 put: image height. "biHeight"
stream nextLittleEndianNumber: 2 put: 1. "biPlanes"
stream nextLittleEndianNumber: 2 put: (depth min: 24). "biBitCount"
stream nextLittleEndianNumber: 4 put: 0. "biCompression"
stream nextLittleEndianNumber: 4 put: biSizeImage. "size of image section in bytes"
stream nextLittleEndianNumber: 4 put: 2800. "biXPelsPerMeter"
stream nextLittleEndianNumber: 4 put: 2800. "biYPelsPerMeter"
stream nextLittleEndianNumber: 4 put: biClrUsed.
stream nextLittleEndianNumber: 4 put: 0. "biClrImportant"
biClrUsed > 0 ifTrue: [
"write color map; this works for ColorForms, too"
colorValues := image colormapIfNeededForDepth: 32.
1 to: biClrUsed do: [:i |
rgb := colorValues at: i.
0 to: 24 by: 8 do: [:j | stream nextPut: (rgb >> j bitAnd: 16rFF)]]].
depth < 32 ifTrue: [
"depth = 1, 4 or 8."
data := image bits asByteArray.
ppw := 32 // depth.
scanLineLen := biWidth + ppw - 1 // ppw * 4. "# of bytes in line"
1 to: biHeight do: [:i |
stream next: scanLineLen putAll: data startingAt: (biHeight-i)*scanLineLen+1.
].
] ifFalse: [
+ data := image bits.
+ pixline := ByteArray new: (((biWidth * 3 + 3) // 4) * 4).
1 to: biHeight do:[:i |
+ self store24BitBmpLine: pixline from: data startingAt: (biHeight-i)*biWidth+1 width: biWidth.
+ stream nextPutAll: pixline.
- data := (image copy: (0@(biHeight-i) extent: biWidth at 1)) bits.
- 1 to: data size do: [:j | stream nextLittleEndianNumber: 3 put: (data at: j)].
- 1 to: (data size*3)+3//4*4-(data size*3) do: [:j | stream nextPut: 0 "pad to 32-bits"]
].
].
stream position = (bfOffBits + biSizeImage) ifFalse: [self error:'Write failure'].
stream close.!
Item was changed:
----- Method: BMPReadWriter>>read24BmpLine:into:startingAt:width: (in category 'reading') -----
read24BmpLine: pixelLine into: formBits startingAt: formBitsIndex width: width
+ "Swizzles the bytes in a 24bpp scanline and fills in the given 32bpp form bits.
+ Ensures that color black is represented as 16rFF000001 so that Form paint
+ works properly."
+
| pixIndex rgb bitsIndex |
+ <primitive: 'primitiveRead24BmpLine' module:'BMPReadWriterPlugin'>
pixIndex := 0. "pre-increment"
bitsIndex := formBitsIndex-1. "pre-increment"
1 to: width do: [:j |
rgb :=
(pixelLine at: (pixIndex := pixIndex+1)) +
((pixelLine at: (pixIndex := pixIndex+1)) bitShift: 8) +
((pixelLine at: (pixIndex := pixIndex+1)) bitShift: 16).
+ rgb = 0 ifTrue:[rgb := 16rFF000001] ifFalse:[rgb := rgb + 16rFF000000].
formBits at: (bitsIndex := bitsIndex+1) put: rgb.
].
!
Item was added:
+ ----- Method: BMPReadWriter>>store24BitBmpLine:from:startingAt:width: (in category 'writing') -----
+ store24BitBmpLine: pixelLine from: formBits startingAt: formBitsIndex width: width
+ "Stores a single scanline containing 32bpp RGBA values in a 24bpp scanline.
+ Swizzles the bytes as needed."
+
+ | pixIndex rgb bitsIndex |
+ <primitive: 'primitiveWrite24BmpLine' module:'BMPReadWriterPlugin'>
+ pixIndex := 0. "pre-increment"
+ bitsIndex := formBitsIndex-1. "pre-increment"
+ 1 to: width do: [:j |
+ rgb := (formBits at: (bitsIndex := bitsIndex+1)) bitAnd: 16rFFFFFF.
+ pixelLine at: (pixIndex := pixIndex+1) put: (rgb bitAnd: 255).
+ pixelLine at: (pixIndex := pixIndex+1) put: ((rgb bitShift: -8) bitAnd: 255).
+ pixelLine at: (pixIndex := pixIndex+1) put: ((rgb bitShift: -16) bitAnd: 255).
+ ].
+ !
More information about the Squeak-dev
mailing list
|