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