[squeak-dev] The Trunk: Graphics-nice.79.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] The Trunk: Graphics-nice.79.mcz

commits-2
Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.79.mcz

==================== Summary ====================

Name: Graphics-nice.79
Author: nice
Time: 6 October 2009, 9:47:43 am
UUID: f58f29ca-1222-4b74-8595-091c02736122
Ancestors: Graphics-nice.78

Cosmetic clean-up from http://bugs.squeak.org/view.php?id=6878
method for detecting depth
- was inefficient
- would not protect against depth>32.

=============== Diff against Graphics-nice.78 ===============

Item was changed:
  ----- Method: BMPReadWriter>>nextPutImage: (in category 'writing') -----
  nextPutImage: aForm
  | bhSize rowBytes rgb data colorValues depth image ppw scanLineLen |
  depth := aForm depth.
+ depth := #(1 4 8 32 ) detect: [ :each | each >= depth].
- [#(1 4 8 32) includes: depth] whileFalse:[depth := depth + 1 asLargerPowerOfTwo].
  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: [
  1 to: biHeight do:[:i |
  data := (image copy: (0@(biHeight-i) extent: biWidth@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.!