Depth32Image.st
author Merge Script
Fri, 17 Jun 2016 07:02:11 +0200
branchjv
changeset 7393 04ffdb8eebcc
parent 7286 c3b4c3c664d4
child 7542 9e125aa140f9
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
     3
	      All Rights Reserved
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
    12
"{ Package: 'stx:libview' }"
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
    13
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
    14
"{ NameSpace: Smalltalk }"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
    15
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Image subclass:#Depth32Image
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    18
	classVariableNames:'RGBA_R_OFFSET_NET RGBA_G_OFFSET_NET RGBA_B_OFFSET_NET
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    19
		RGBA_A_OFFSET_NET'
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	category:'Graphics-Images'
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!Depth32Image class methodsFor:'documentation'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
copyright
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 COPYRIGHT (c) 1995 by Claus Gittinger
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
    29
	      All Rights Reserved
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 This software is furnished under a license and may be used
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 only in accordance with the terms of that license and with the
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 be provided or otherwise made available to, or used by, any
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 other person.  No title to or ownership of the software is
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 hereby transferred.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    this class represents 32 bit images.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    Only the minimum protocol is implemented here; much more is
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    needed for higher performance operations on depth32 images.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    (however, 32bit images are very seldom used, so falling back into the
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    slow general methods from Image should not hurt too much ..)
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    [author:]
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
    49
	Claus Gittinger
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    [see also:]
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
    52
	Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
    53
	ImageReader
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    57
!Depth32Image class methodsFor:'initialization'!
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    58
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    59
initialize
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    60
    RGBA_A_OFFSET_NET := 4.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    61
    RGBA_B_OFFSET_NET := 3.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    62
    RGBA_G_OFFSET_NET := 2.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    63
    RGBA_R_OFFSET_NET := 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    64
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    65
    "Created: / 28-02-2016 / 11:29:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    66
    "Modified: / 28-02-2016 / 14:36:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    67
! !
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    68
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
!Depth32Image class methodsFor:'queries'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    71
defaultPhotometric
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    72
    "return the default photometric pixel interpretation"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    73
5324
63a97775c5fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5297
diff changeset
    74
    ^ #rgb
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    75
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    76
    "Created: / 27-05-2007 / 14:03:59 / cg"
4790
652fca7eac26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
    77
    "Modified: / 06-06-2007 / 11:12:13 / cg"
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    78
!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    79
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
imageDepth
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    "return the depth of images represented by instances of
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
     this class - here we return 32"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    ^ 32
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    "Modified: 20.4.1996 / 23:40:01 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    90
!Depth32Image methodsFor:'accessing'!
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    91
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    92
bitsARGB32Into: buffer startingAt: first stride: stride
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    93
    "Store each pixel is a 32-bit quantity, with alpha in the upper 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    94
     8 bits, then red, then green, then blue. The 32-bit quantities are 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    95
     stored native-endian. Pre-multiplied alpha is used. (That is, 50% 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    96
     transparent red is 0x80800000, not 0x80ff0000.)
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    97
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    98
     IMPORTANT: The following code assumes that the data (`bytes` instvar)
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
    99
     are stored in network byte order with NON-premultiplied alpha. This is
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   100
     true for PNG data.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   101
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   102
     NOTE: This is a good candidate for C-level optimization.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   103
    "
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   104
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   105
    | base pixelIndex bufferIndex  a r g b |
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   106
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   107
    pixelFunction isNil ifTrue:[ 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   108
        photometric == #rgba ifTrue:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   109
            bitsPerSample = #(8 8 8 8) ifTrue:[ 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   110
                1 to: height do:[:y |  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   111
                    base := ((y - 1) * stride) + first - 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   112
                    1 to: width do:[:x |  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   113
                        pixelIndex := ((((y - 1) * width) + (x - 1)) * 4).
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   114
                        "/ Extract components...
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   115
                        a := bytes at: pixelIndex + RGBA_A_OFFSET_NET.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   116
                        r := bytes at: pixelIndex + RGBA_R_OFFSET_NET.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   117
                        g := bytes at: pixelIndex + RGBA_G_OFFSET_NET.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   118
                        b := bytes at: pixelIndex + RGBA_B_OFFSET_NET.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   119
                        "/ Pre-multiply
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   120
                        r := (r * a) // 255.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   121
                        g := (g * a) // 255.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   122
                        b := (b * a) // 255.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   123
                        "/ Assemble pixel
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   124
                        bufferIndex := base + ((x - 1) * 4).
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   125
                        buffer at: bufferIndex + ARGB_A_OFFSET_MACHINE put: a.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   126
                        buffer at: bufferIndex + ARGB_R_OFFSET_MACHINE put: r.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   127
                        buffer at: bufferIndex + ARGB_G_OFFSET_MACHINE put: g.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   128
                        buffer at: bufferIndex + ARGB_B_OFFSET_MACHINE put: b.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   129
                    ]
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   130
                ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   131
                ^ self.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   132
            ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   133
        ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   134
        photometric == #argb ifTrue:[ 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   135
            self notYetImplemented.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   136
            ^ self.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   137
        ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   138
    ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   139
    ^ super bitsARGB32Into: buffer startingAt: first stride: stride
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   140
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   141
    "Created: / 28-02-2016 / 06:54:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   142
    "Modified (comment): / 28-02-2016 / 14:44:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   143
! !
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
   144
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   145
!Depth32Image methodsFor:'accessing-pixels'!
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   147
colorAtX:x y:y
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   148
    "retrieve a pixel at x/y; return a color.
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   149
     Pixels start at x=0 , y=0 for upper left pixel, 
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   150
     end at x = width-1, y=height-1 for lower right pixel"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   151
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   152
    |index "{ Class: SmallInteger }"
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   153
     rVal gVal bVal aVal|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   154
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   155
    index := 1 + (((width * y) + x) * 4).
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   156
    photometric == #rgb ifTrue:[
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   157
        rVal := bytes at:(index).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   158
        gVal := bytes at:(index + 1).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   159
        bVal := bytes at:(index + 2).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   160
        ^ Color redByte:rVal greenByte:gVal blueByte:bVal
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   161
    ].
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   162
    photometric == #rgba ifTrue:[
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   163
        rVal := bytes at:(index).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   164
        gVal := bytes at:(index + 1).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   165
        bVal := bytes at:(index + 2).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   166
        aVal := bytes at:(index + 3).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   167
        ^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   168
    ].
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   169
    photometric == #argb ifTrue:[
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   170
        aVal := bytes at:(index).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   171
        rVal := bytes at:(index + 1).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   172
        gVal := bytes at:(index + 2).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   173
        bVal := bytes at:(index + 3).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   174
        ^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   175
    ].
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   176
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   177
    "/ the inherited method should handle all cases.
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   178
    ^ super colorAtX:x y:y. 
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   179
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   180
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   181
colorAtX:x y:y put:aColor
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   182
    "set the pixel at x/y to aColor.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   183
     Pixels start at x=0 , y=0 for upper left pixel, end at
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   184
     x = width-1, y=height-1 for lower right pixel."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   185
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   186
    |index "{ Class: SmallInteger }"|
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   187
7167
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   188
    ((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   189
        index := 1 + (((width * y) + x) * 4).
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   190
        bytes at:(index) put:(aColor redByte).
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   191
        bytes at:(index + 1) put:(aColor greenByte).
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   192
        bytes at:(index + 2) put:(aColor blueByte).
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   193
        bytes at:(index + 3) put:255.               "alpha channel"
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   194
        ^ self
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   195
    ].
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   196
    (photometric == #argb) ifTrue:[
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   197
        index := 1 + (((width * y) + x) * 4).
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   198
        bytes at:(index) put:255.                   "alpha channel"
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   199
        bytes at:(index + 1) put:(aColor redByte).
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   200
        bytes at:(index + 2) put:(aColor greenByte).
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   201
        bytes at:(index + 3) put:(aColor blueByte).             
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   202
        ^ self
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   203
    ].
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   204
7167
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   205
    super colorAtX:x y:y put:aColor. 
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   206
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   207
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
pixelAtX:x y:y
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    "retrieve a pixel at x/y; return a pixelValue.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
     Pixels start at x=0 , y=0 for upper left pixel, end at
7279
51d86b5b7883 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7274
diff changeset
   211
     x = width-1, y=height-1 for lower right pixel.
51d86b5b7883 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7274
diff changeset
   212
     The pixel value contains r/g/b/a in msb order (i.e. r at high, a at low bits)"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
1669
d156d2623f41 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1663
diff changeset
   214
    |pixelIndex "{ Class: SmallInteger }"|
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
7274
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   216
%{  /* NOCONTEXT */
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   217
    OBJ b = __INST(bytes);
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   218
    OBJ w = __INST(width);
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   219
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   220
    if (__isByteArrayLike(b)
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   221
     && __bothSmallInteger(x, y)
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   222
     && __isSmallInteger(w)
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   223
     && (__INST(pixelFunction)==nil) ) {
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   224
        int _idx;
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   225
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   226
        _idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4;
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   227
        if (((unsigned)(_idx+3)) < __byteArraySize(b)) {
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   228
            unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]);
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   229
            unsigned int _pix;
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   230
            _pix = (((((pPix[0]<<8)+pPix[1])<<8)+pPix[2])<<8)+pPix[3];
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   231
#if __POINTER_SIZE__ == 8
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   232
            RETURN( __MKSMALLINT(_pix) );
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   233
#else
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   234
            RETURN( __MKUINT(_pix) );
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   235
#endif
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   236
        }
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   237
    }
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   238
%}.
6302
d393dae43c28 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   239
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
d393dae43c28 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   240
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   241
    pixelIndex := 1 + (((width * y) + x) * 4).
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    "left pixel in high bits"
7225
0b34f9bae937 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7185
diff changeset
   244
    ^ bytes unsignedInt32At:pixelIndex MSB:true.
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    "Created: 24.4.1997 / 19:00:28 / cg"
1669
d156d2623f41 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1663
diff changeset
   247
    "Modified: 24.4.1997 / 23:11:05 / cg"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
pixelAtX:x y:y put:aPixelValue
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    "set the pixel at x/y to aPixelValue.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
     Pixels start at x=0 , y=0 for upper left pixel, end at
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
     x = width-1, y=height-1 for lower right pixel"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
1669
d156d2623f41 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1663
diff changeset
   255
    |pixelIndex "{ Class: SmallInteger }"|
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   257
    pixelIndex := 1 + (((width * y) + x) * 4).
4790
652fca7eac26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   258
    bytes isNil ifTrue:[
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   259
        self createPixelStore
4790
652fca7eac26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   260
    ].
7225
0b34f9bae937 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7185
diff changeset
   261
    bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
4790
652fca7eac26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   263
    "Created: / 24-04-1997 / 19:00:28 / cg"
652fca7eac26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   264
    "Modified: / 06-06-2007 / 12:20:57 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   265
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   266
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   267
rowAt:y putAll:pixelArray startingAt:startIndex
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   268
    "store a single rows bits from bits in the pixelArray argument;
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   269
     Return the pixelArray.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   270
     Notice: row coordinate starts at 0."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   271
6846
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   272
    |bytes dstIdx pixel 
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   273
     w "{ Class: SmallInteger }"|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   274
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   275
    bytes := self bits.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   276
    dstIdx := (y * self bytesPerRow) + 1.
6846
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   277
    w := width - 1.
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   278
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   279
    0 to:w do:[:col |
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   280
        pixel := pixelArray at:(startIndex + col).
7225
0b34f9bae937 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7185
diff changeset
   281
        bytes unsignedInt32At:dstIdx put:pixel MSB:true.
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   282
        dstIdx := dstIdx + 4.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   283
    ].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   284
    ^ pixelArray
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   287
!Depth32Image methodsFor:'converting rgb images'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   288
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   289
rgbImageAsTrueColorFormOn:aDevice
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   290
    "return a truecolor form from the rgba or argb-picture."
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   291
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   292
    |bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   293
     myDepth form imageBits padd
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   294
     rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue|
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   295
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   296
    bytes := self bits.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   297
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   298
    bestFormat := self bestSupportedImageFormatFor:aDevice.
4763
69afd837e817 leftover halt:
Claus Gittinger <cg@exept.de>
parents: 4761
diff changeset
   299
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   300
    usedDeviceDepth := bestFormat at:#depth.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   301
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   302
    usedDevicePadding := bestFormat at:#padding.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   303
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   304
    rightShiftR := (8 - aDevice bitsRed).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   305
    rightShiftG := (8 - aDevice bitsGreen).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   306
    rightShiftB := (8 - aDevice bitsBlue).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   307
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   308
    shiftRed := aDevice shiftRed.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   309
    shiftGreen := aDevice shiftGreen.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   310
    shiftBlue := aDevice shiftBlue.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   311
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   312
    "/
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   313
    "/ for now, only a few formats are supported
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   314
    "/
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   315
    myDepth := self bitsPerPixel.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   316
    usedDeviceBitsPerPixel == 24 ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   317
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   318
        "/ 24 bit/pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   319
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   320
        imageBits := ByteArray uninitializedNew:(width * height * 3).
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   321
        usedDevicePadding := 8.
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   322
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   323
        "/ now, walk over the image and compose 24bit values from the r/g/b/a triples
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   324
%{
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   325
        unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   326
        unsigned char *dstPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   327
        int redOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   328
        int greenOffs = 1;  
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   329
        int blueOffs = 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   330
        int alphaOffs = 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   331
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   332
        if (__INST(photometric) == @symbol(argb)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   333
            redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   334
        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   335
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   336
        if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   337
            srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   338
        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   339
            if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   340
                srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   341
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   342
        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   343
        if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   344
            dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   345
        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   346
            if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   347
                dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   348
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   349
        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   350
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   351
        if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   352
         && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   353
         && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   354
         && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   355
         && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   356
         && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   357
            int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   358
                rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   359
                rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   360
                lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   361
                lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   362
                lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   363
            int x, y, w;
5297
e1e2793072ad 32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   364
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   365
            w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   366
            if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   367
                if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   368
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   369
                        for (x=w; x > 0; x--) {                        
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   370
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   371
                            dstPtr[0] = srcPtr[redOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   372
                            dstPtr[1] = srcPtr[greenOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   373
                            dstPtr[2] = srcPtr[blueOffs];
5297
e1e2793072ad 32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   374
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   375
                            dstPtr[0] = srcPtr[blueOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   376
                            dstPtr[1] = srcPtr[greenOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   377
                            dstPtr[2] = srcPtr[redOffs];
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   378
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   379
                            dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   380
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   381
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   382
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   383
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   384
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   385
                        for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   386
                            unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   387
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   388
                            v = srcPtr[redOffs] << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   389
                            v |= (srcPtr[greenOffs] << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   390
                            v |= (srcPtr[blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   391
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   392
                            dstPtr[0] = (v) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   393
                            dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   394
                            dstPtr[2] = (v>>16) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   395
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   396
                            dstPtr[0] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   397
                            dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   398
                            dstPtr[2] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   399
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   400
                            dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   401
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   402
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   403
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   404
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   405
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   406
                for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   407
                    for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   408
                        unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   409
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   410
                        r = srcPtr[redOffs] >> rShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   411
                        g = srcPtr[greenOffs] >> rShGreen;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   412
                        b = srcPtr[blueOffs] >> rShBlue;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   413
                        v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   414
                        v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   415
                        v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   416
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   417
                        dstPtr[0] = (v) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   418
                        dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   419
                        dstPtr[2] = (v>>16) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   420
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   421
                        dstPtr[0] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   422
                        dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   423
                        dstPtr[2] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   424
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   425
                        dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   426
                        srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   427
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   428
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   429
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   430
        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   431
%}.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   432
    ] ifFalse:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   433
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   434
        "/ 8, 16 or 32 bit/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   435
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   436
        (usedDeviceBitsPerPixel == 16) ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   437
            padd := width \\ (usedDevicePadding // 16).
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   438
            imageBits := ByteArray uninitializedNew:((width + padd) * height * 2).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   439
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   440
            "/ now, walk over the image and compose 16bit values from the r/g/b triples
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   441
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   442
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   443
            unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   444
            unsigned char *dstPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   445
            int redOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   446
            int greenOffs = 1;  
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   447
            int blueOffs = 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   448
            int alphaOffs = 3;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   449
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   450
            if (__INST(photometric) == @symbol(argb)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   451
                redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   452
            }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   453
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   454
            if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   455
                srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   456
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   457
                if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   458
                    srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   459
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   460
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   461
            if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   462
                dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   463
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   464
                if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   465
                    dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   466
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   467
            }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   468
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   469
            if (__bothSmallInteger(__INST(height),__INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   470
             && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   471
             && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   472
             && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   473
             && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   474
             && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   475
                int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   476
                    rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   477
                    rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   478
                    lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   479
                    lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   480
                    lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   481
                int x, y, w;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   482
                int p;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   483
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   484
                w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   485
                p = __intVal(padd) * 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   486
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   487
                if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   488
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   489
                        for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   490
                            unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   491
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   492
                            v = srcPtr[redOffs] << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   493
                            v |= (srcPtr[greenOffs] << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   494
                            v |= (srcPtr[blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   495
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   496
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   497
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   498
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   499
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   500
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   501
                            dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   502
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   503
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   504
                        dstPtr += p;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   505
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   506
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   507
                    if (p == 0) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   508
                        int n = __intVal(__INST(height)) * w;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   509
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   510
                        while (n >= 2) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   511
                            unsigned w, r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   512
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   513
                            n -= 2;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   514
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   515
                            r = srcPtr[redOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   516
                            g = srcPtr[greenOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   517
                            b = srcPtr[blueOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   518
                            v = (r >> rShRed) << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   519
                            v |= ((g >> rShGreen) << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   520
                            v |= ((b >> rShBlue) << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   521
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   522
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   523
# else
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   524
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   525
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   526
# endif /* not MSB */
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   527
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   528
                            r = srcPtr[3+redOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   529
                            g = srcPtr[3+greenOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   530
                            b = srcPtr[3+blueOffs];
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   531
                            v = (r >> rShRed) << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   532
                            v |= ((g >> rShGreen) << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   533
                            v |= ((b >> rShBlue) << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   534
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   535
                            ((short *)dstPtr)[1] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   536
# else
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   537
                            dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   538
                            dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   539
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   540
                            dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   541
                            srcPtr += 8;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   542
                        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   543
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   544
                        while (n--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   545
                            unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   546
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   547
                            r = srcPtr[redOffs] >> rShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   548
                            g = srcPtr[greenOffs] >> rShGreen;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   549
                            b = srcPtr[blueOffs] >> rShBlue;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   550
                            v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   551
                            v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   552
                            v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   553
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   554
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   555
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   556
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   557
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   558
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   559
                            dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   560
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   561
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   562
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   563
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   564
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   565
                                unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   566
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   567
                                r = srcPtr[redOffs] >> rShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   568
                                g = srcPtr[greenOffs] >> rShGreen;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   569
                                b = srcPtr[blueOffs] >> rShBlue;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   570
                                v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   571
                                v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   572
                                v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   573
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   574
                                ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   575
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   576
                                dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   577
                                dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   578
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   579
                                dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   580
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   581
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   582
                            dstPtr += p;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   583
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   584
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   585
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   586
            }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   587
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   588
        ] ifFalse:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   589
            "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   590
            "/ 32 or 8 bits/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   591
            "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   592
            (usedDeviceBitsPerPixel == 32) ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   593
                usedDevicePadding := 8.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   594
                imageBits := ByteArray uninitializedNew:(width * height * 4).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   595
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   596
                "/ now, walk over the image and compose 32bit values from the r/g/b triples
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   597
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   598
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   599
                unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   600
                unsigned char *dstPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   601
                int redOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   602
                int greenOffs = 1;  
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   603
                int blueOffs = 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   604
                int alphaOffs = 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   605
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   606
                if (__INST(photometric) == @symbol(argb)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   607
                    redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   608
                }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   609
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   610
                if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   611
                    srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   612
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   613
                    if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   614
                        srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   615
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   616
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   617
                if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   618
                    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   619
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   620
                    if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   621
                        dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   622
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   623
                }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   624
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   625
                if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   626
                 && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   627
                 && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   628
                 && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   629
                 && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   630
                 && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   631
                    int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   632
                        rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   633
                        rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   634
                        lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   635
                        lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   636
                        lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   637
                    int x, y, w;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   638
                    
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   639
                    w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   640
                    if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   641
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   642
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   643
                                unsigned v;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   644
                                
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   645
                                v = srcPtr[redOffs] << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   646
                                v |= (srcPtr[greenOffs] << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   647
                                v |= (srcPtr[blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   648
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   649
                                ((int *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   650
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   651
                                dstPtr[0] = (v>>24) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   652
                                dstPtr[1] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   653
                                dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   654
                                dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   655
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   656
                                dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   657
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   658
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   659
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   660
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   661
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   662
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   663
                                unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   664
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   665
                                r = srcPtr[redOffs] >> rShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   666
                                g = srcPtr[greenOffs] >> rShGreen;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   667
                                b = srcPtr[blueOffs] >> rShBlue;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   668
                                v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   669
                                v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   670
                                v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   671
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   672
                                ((int *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   673
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   674
                                dstPtr[0] = (v>>24) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   675
                                dstPtr[1] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   676
                                dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   677
                                dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   678
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   679
                                dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   680
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   681
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   682
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   683
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   684
                }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   685
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   686
            ] ifFalse:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   687
                "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   688
                "/ 8 bits/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   689
                "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   690
                (usedDeviceBitsPerPixel == 8) ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   691
                    usedDevicePadding := 8.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   692
                    imageBits := ByteArray uninitializedNew:(width * height).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   693
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   694
                    "/ now, walk over the image and compose 8bit values from the r/g/b triples
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   695
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   696
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   697
                    unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   698
                    unsigned char *dstPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   699
                    int redOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   700
                    int greenOffs = 1;  
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   701
                    int blueOffs = 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   702
                    int alphaOffs = 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   703
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   704
                    if (__INST(photometric) == @symbol(argb)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   705
                        redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   706
                    }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   707
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   708
                    if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   709
                        srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   710
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   711
                        if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   712
                            srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   713
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   714
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   715
                    if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   716
                        dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   717
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   718
                        if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   719
                            dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   720
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   721
                    }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   722
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   723
                    if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   724
                     && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   725
                     && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   726
                     && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   727
                     && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   728
                     && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   729
                        int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   730
                            rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   731
                            rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   732
                            lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   733
                            lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   734
                            lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   735
                        int x, y, w;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   736
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   737
                        w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   738
                        if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   739
                            for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   740
                                for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   741
                                    unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   742
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   743
                                    v = srcPtr[redOffs] << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   744
                                    v |= (srcPtr[greenOffs] << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   745
                                    v |= (srcPtr[blueOffs] << lShBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   746
                                    dstPtr[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   747
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   748
                                    dstPtr += 1;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   749
                                    srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   750
                                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   751
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   752
                        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   753
                            for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   754
                                for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   755
                                    unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   756
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   757
                                    r = srcPtr[redOffs] >> rShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   758
                                    g = srcPtr[greenOffs] >> rShGreen;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   759
                                    b = srcPtr[blueOffs] >> rShBlue;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   760
                                    v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   761
                                    v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   762
                                    v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   763
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   764
                                    dstPtr[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   765
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   766
                                    dstPtr += 1;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   767
                                    srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   768
                                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   769
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   770
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   771
                    }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   772
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   773
                ]
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   774
            ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   775
        ]
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   776
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   777
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   778
    imageBits isNil ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   779
        'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   780
        usedDeviceBitsPerPixel errorPrintCR.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   781
        ^ self asMonochromeFormOn:aDevice
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   782
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   783
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   784
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   785
    form isNil ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   786
        'Depth32Image [warning]: display bitmap creation failed' errorPrintCR.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   787
        ^ nil
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   788
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   789
    form initGC.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   790
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   791
    form
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   792
        copyBitsFrom:imageBits
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   793
        bitsPerPixel:usedDeviceBitsPerPixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   794
        depth:usedDeviceDepth
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   795
        padding:usedDevicePadding
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   796
        width:width height:height
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   797
        x:0 y:0 toX:0 y:0.
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   798
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   799
    ^ form
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   800
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   801
    "Created: / 27-05-2007 / 16:54:19 / cg"
4763
69afd837e817 leftover halt:
Claus Gittinger <cg@exept.de>
parents: 4761
diff changeset
   802
    "Modified: / 29-05-2007 / 12:19:04 / cg"
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   803
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   804
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   805
!Depth32Image methodsFor:'image manipulations'!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   806
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   807
negative
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   808
    |bytes index newImage newBytes nBytes r g b|
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   809
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   810
    photometric ~~ #rgb ifTrue:[
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   811
        ^ super negative.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   812
    ].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   813
    bytes := self bits.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   814
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   815
    newImage := self copy.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   816
    nBytes := bytes size.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   817
    newImage bits:(newBytes := ByteArray new:nBytes).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   818
    index := 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   819
    [index < nBytes] whileTrue:[
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   820
        r := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   821
        newBytes at:index put:(255-r).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   822
        index := index + 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   823
        g := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   824
        newBytes at:index put:(255-g).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   825
        index := index + 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   826
        b := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   827
        newBytes at:index put:(255-b).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   828
        index := index + 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   829
        b := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   830
        newBytes at:index put:b.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   831
        index := index + 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   832
    ].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   833
    ^ newImage
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   834
! !
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   835
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   836
!Depth32Image methodsFor:'initialization'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   837
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   838
initialize
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   839
    super initialize.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   840
    samplesPerPixel := 4.
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   841
    bitsPerSample := #(8 8 8 8).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   842
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   843
    "Created: / 27-05-2007 / 14:09:16 / cg"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   844
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   845
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   846
!Depth32Image methodsFor:'magnification'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   847
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   848
magnifyRowFrom:srcBytes offset:srcStart
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   849
	  into:dstBytes offset:dstStart factor:mX
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   850
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   851
    "magnify a single pixel row - can only magnify by integer factors"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   852
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   853
%{
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   854
    unsigned char *srcP, *dstP;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   855
    int _mag;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   856
    REGISTER int i;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   857
    REGISTER unsigned char byte1, byte2, byte3, byte4;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   858
    int _pixels;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   859
    OBJ w = __INST(width);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   860
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   861
    if (__bothSmallInteger(srcStart, dstStart)
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   862
     && __bothSmallInteger(w, mX)
5474
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
   863
     && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   864
	_mag = __intVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   865
	srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   866
	dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   867
	_pixels = __intVal(w);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   868
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   869
	while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   870
	    byte1 = *srcP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   871
	    byte2 = *(srcP+1);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   872
	    byte3 = *(srcP+2);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   873
	    byte4 = *(srcP+3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   874
	    srcP += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   875
	    for (i=_mag; i>0; i--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   876
		*dstP = byte1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   877
		*(dstP+1) = byte2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   878
		*(dstP+2) = byte3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   879
		*(dstP+3) = byte4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   880
		dstP += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   881
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   882
	}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   883
	RETURN (self);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   884
    }
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   885
%}.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   886
    super
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   887
	magnifyRowFrom:srcBytes offset:srcStart
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   888
	into:dstBytes offset:dstStart factor:mX
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   889
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   890
    "Created: / 28-05-2007 / 15:20:52 / cg"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   891
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   892
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
!Depth32Image methodsFor:'queries'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   895
alphaBitsOf:pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   896
    "given a pixel-value, return the alpha component as byteValue (0..255)"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   897
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   898
    photometric == #rgba ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   899
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   900
        ^ pixel bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   901
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   902
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   903
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   904
        ^ (pixel bitShift:-24) bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   905
    ].
7167
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   906
    photometric == #rgb ifTrue:[
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   907
        ^ 0
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   908
    ].
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   909
    self error:'unsupported photometric'
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   910
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   911
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   912
alphaComponentOf:pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   913
    "given a pixel-value, return the alpha component in percent (0..100)"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   914
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   915
    ^ (self alphaBitsOf:pixel) * (100.0 / 255.0)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   916
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   917
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   918
alphaMaskForPixelValue
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   919
    "return the mask used with translation from pixelValues to alphaBits"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   920
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   921
    ^ 16rFF
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   922
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   923
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   924
alphaShiftForPixelValue
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   925
    "return the shift amount used with translation from pixelValues to alphaBits"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   926
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   927
    photometric == #rgba ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   928
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   929
        ^ 0
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   930
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   931
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   932
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   933
        ^ -24.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   934
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   935
    self error:'unsupported photometric'
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   936
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   937
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
bitsPerPixel
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
    "return the number of bits per pixel"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
    ^ 32
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
bitsPerRow
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
    "return the number of bits in one scanline of the image"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   948
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
   949
    ^ width * 32
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   950
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   951
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   954
bitsPerSample
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   955
    "return the number of bits per sample.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   956
     The return value is an array of bits-per-plane."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   957
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   958
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   959
    ^ #(8 8 8 8)
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   960
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   961
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   962
blueBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   963
    "given a pixel-value, return the blue component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   964
7185
9e6c2cec949b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7167
diff changeset
   965
    ((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   966
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   967
        ^ (pixel bitShift:-8) bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   968
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   969
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   970
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   971
        ^ pixel bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   972
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   973
    self error:'unsupported photometric'
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   974
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   975
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   976
blueComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   977
    "given a pixel-value, return the blue component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   978
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   979
    ^ (self blueBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   980
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   981
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   982
blueMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   983
    "return the mask used with translation from pixelValues to blueBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   984
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   985
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   986
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   987
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   988
blueShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   989
    "return the shift amount used with translation from pixelValues to blueBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   990
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   991
    photometric == #rgba ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   992
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   993
        ^ -8
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   994
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   995
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   996
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   997
        ^ 0.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   998
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   999
    self error:'unsupported photometric'
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1000
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1001
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
bytesPerRow
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
    "return the number of bytes in one scanline of the image"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
    ^ width * 4.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1007
    "Created: 24.4.1997 / 19:00:28 / cg"
5327
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1008
!
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1009
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1010
greenBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1011
    "given a pixel-value, return the green component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1012
7185
9e6c2cec949b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7167
diff changeset
  1013
    ((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1014
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1015
        ^ (pixel bitShift:-16) bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1016
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1017
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1018
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1019
        ^ (pixel bitShift:-8) bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1020
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1021
    self error:'unsupported photometric'
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1022
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1023
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1024
greenComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1025
    "given a pixel-value, return the green component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1026
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1027
    ^ (self greenBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1028
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1029
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1030
greenMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1031
    "return the mask used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1032
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1033
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1034
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1035
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1036
greenShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1037
    "return the shift amount used with translation from pixelValues to greenBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1038
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1039
    photometric == #rgba ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1040
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1041
        ^ -16
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1042
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1043
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1044
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1045
        ^ -8.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1046
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1047
    self error:'unsupported photometric'
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1048
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1049
5327
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1050
hasAlphaChannel
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1051
    ^ true
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1052
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1053
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1054
redBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1055
    "given a pixel-value, return the red component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1056
7185
9e6c2cec949b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7167
diff changeset
  1057
    ((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1058
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1059
        ^ (pixel bitShift:-24) bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1060
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1061
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1062
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1063
        ^ (pixel bitShift:-16) bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1064
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1065
    self error:'unsupported photometric'
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1066
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1067
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1068
redComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1069
    "given a pixel-value, return the red component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1070
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1071
    ^ (self redBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1072
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1073
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1074
redMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1075
    "return the mask used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1076
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1077
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1078
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1079
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1080
redShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1081
    "return the shift amount used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1082
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1083
    photometric == #rgba ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1084
        "r,g,b,a"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1085
        ^ -24
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1086
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1087
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1088
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1089
        ^ -16.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1090
    ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1091
    self error:'unsupported photometric'
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1092
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1093
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1094
rgbFromValue:pixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1095
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB)."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1096
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1097
    ^ pixelValue rightShift:8     "lsb is alpha channel"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1098
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1099
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1100
samplesPerPixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1101
    "return the number of samples per pixel in the image."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1102
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1103
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1104
    ^ 4
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1105
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1106
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1107
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1108
    ^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:255
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
!Depth32Image class methodsFor:'documentation'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1112
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1113
version
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1114
    ^ '$Header$'
5474
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1115
!
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1116
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1117
version_CVS
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1118
    ^ '$Header$'
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1119
! !
6302
d393dae43c28 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
  1120
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
  1121
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7167
diff changeset
  1122
Depth32Image initialize!