Depth16Image.st
author Claus Gittinger <cg@exept.de>
Tue, 29 Apr 2003 20:45:23 +0200
changeset 3866 c01473a90934
parent 3263 bd92a12c9316
child 3868 e47cf114c824
permissions -rw-r--r--
eliminated most references to bytes (will be replaced by pixelAccessor soon)

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

"{ Package: 'stx:libview' }"

Image subclass:#Depth16Image
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Graphics-Images'
!

!Depth16Image class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    this class represents 16 bit images.
    Only the minimum protocol is implemented here; much more is
    needed for higher performance operations on depth16 images.
    (however, 16bit images are seldom used, so falling back into the
    slow general methods from Image should not hurt too much ..)

    [author:]
        Claus Gittinger

    [see also:]
        Depth1Image Depth2Image Depth4Image Depth8Image Depth24Image
        ImageReader
"
! !

!Depth16Image class methodsFor:'queries'!

imageDepth
    "return the depth of images represented by instances of
     this class - here we return 16"

    ^ 16

    "Modified: 20.4.1996 / 23:40:01 / cg"
! !

!Depth16Image methodsFor:'accessing-pixels'!

pixelAtX:x y:y
    "retrieve a pixel at x/y; return a pixelValue.
     Pixels start at x=0 , y=0 for upper left pixel, end at
     x = width-1, y=height-1 for lower right pixel"

    |lineIndex "{ Class: SmallInteger }"|

    lineIndex := (width * 2 * y) + 1.

    "left pixel in high bits"
    ^ bytes wordAt:(lineIndex + (x * 2)) MSB:true.

    "Created: 24.4.1997 / 16:06:19 / cg"
!

pixelAtX:x y:y put:aPixelValue
    "set the pixel at x/y to aPixelValue.
     Pixels start at x=0 , y=0 for upper left pixel, end at
     x = width-1, y=height-1 for lower right pixel"

    |lineIndex "{ Class: SmallInteger }"|

    lineIndex := (width * 2 * y) + 1.

    bytes wordAt:(lineIndex + (x * 2)) put:aPixelValue MSB:true

    "Created: 24.4.1997 / 17:06:21 / cg"
!

rowAt:rowIndex putAll:pixelArray startingAt:startIndex
    "store a single rows bits from bits in the pixelArray argument;
     Return the pixelArray.
     Notice: row indexing starts at 0."

    |dstIdx "{ Class: SmallInteger }"
     pixel
     bytes|

    bytes := self bits.
    dstIdx := (width * 2 * rowIndex) + 1.
    1 to:width do:[:col |
        pixel := pixelArray at:(startIndex + col - 1).
        bytes at:dstIdx put:((pixel bitShift:-8) bitAnd:16rFF).
        bytes at:dstIdx+1 put:(pixel bitAnd:16rFF).
        dstIdx := dstIdx + 2.
    ].
    ^ pixelArray

    "Created: 24.4.1997 / 15:50:27 / cg"
! !

!Depth16Image methodsFor:'queries'!

bitsPerPixel
    "return the number of bits per pixel"

    ^ 16
!

bitsPerRow
    "return the number of bits in one scanline of the image"

    ^  width * 16
!

bytesPerRow
    "return the number of bytes in one scanline of the image"

    ^ width * 2.
! !

!Depth16Image class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview/Depth16Image.st,v 1.10 2003-04-29 18:45:13 cg Exp $'
! !