Depth32Image.st
author mawalch
Mon, 20 Nov 2017 20:11:24 +0100
changeset 8221 fe07baca2fee
parent 8201 d8a475e6e994
child 8262 a9845a7cad69
permissions -rw-r--r--
#DOCUMENTATION by mawalch class: SimpleView comment/format in: #activateMenu
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
%}.
8201
d8a475e6e994 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8166
diff changeset
   264
    bytes isNil ifTrue:[ self createPixelStore ].
d8a475e6e994 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8166
diff changeset
   265
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   266
    pixelIndex := 1 + (((width * y) + x) * 4).
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   267
    bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true.
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
4790
652fca7eac26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   269
    "Created: / 24-04-1997 / 19:00:28 / cg"
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   270
    "Modified: / 22-08-2017 / 18:21:47 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   271
!
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
rowAt:y putAll:pixelArray startingAt:startIndex
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   274
    "store a single rows bits from bits in the pixelArray argument;
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   275
     Return the pixelArray.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   276
     Notice: row coordinate starts at 0."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   277
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   278
    |bytes pixel
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   279
     dstIdx "{ Class: SmallInteger }" 
6846
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   280
     w "{ Class: SmallInteger }"|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   281
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   282
    bytes := self bits.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   283
    dstIdx := (y * self bytesPerRow) + 1.
6846
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   284
    w := width - 1.
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   285
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   286
    0 to:w do:[:col |
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   287
        pixel := pixelArray at:(startIndex + col).
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   288
        bytes unsignedInt32At:dstIdx put:pixel MSB:true.
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   289
        dstIdx := dstIdx + 4.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   290
    ].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   291
    ^ pixelArray
7917
fb1dcd2edc4e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7903
diff changeset
   292
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   293
    "Modified (comment): / 21-02-2017 / 15:03:24 / cg"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   296
!Depth32Image methodsFor:'converting rgb images'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   297
7492
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   298
computeAlphaValuesFromMask:aMaskImage
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   299
    "convert a mask into alpha values;
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   300
     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
   301
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   302
    |alphaMask|
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   303
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   304
    alphaMask := (self alphaMaskForPixelValue bitShift:self alphaShiftForPixelValue).
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   305
    self 
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   306
        valuesFromX:0 y:0 toX:(width-1) y:(height-1)
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   307
        do:[:x :y :pixelValue |
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   308
            (aMaskImage pixelAtX:x y:y) ~~ 0 ifTrue:[
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   309
                self pixelAtX:x y:y put:(pixelValue bitOr:alphaMask).
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   310
            ] ifFalse:[
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   311
                self pixelAtX:x y:y put:(pixelValue bitClear:alphaMask).
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   312
            ].
7492
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   313
        ].
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   314
    photometric := #rgba
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   315
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   316
    "Modified: / 21-02-2017 / 16:41:02 / cg"
7492
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   317
!
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   318
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   319
rgbImageAsTrueColorFormOn:aDevice
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   320
    "return a truecolor form from the rgba or argb-picture."
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   321
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   322
    |bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   323
     myDepth form imageBits padd
8000
62ea15884e2b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7922
diff changeset
   324
     rightShiftR rightShiftG rightShiftB
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   325
     shiftRed shiftGreen shiftBlue
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   326
     redOffs greenOffs blueOffs alphaOffs|
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   327
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   328
    bytes := self bits.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   329
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   330
    bestFormat := self bestSupportedImageFormatFor:aDevice.
4763
69afd837e817 leftover halt:
Claus Gittinger <cg@exept.de>
parents: 4761
diff changeset
   331
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   332
    usedDeviceDepth := bestFormat at:#depth.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   333
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   334
    usedDevicePadding := bestFormat at:#padding.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   335
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   336
    rightShiftR := (8 - aDevice bitsRed).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   337
    rightShiftG := (8 - aDevice bitsGreen).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   338
    rightShiftB := (8 - aDevice bitsBlue).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   339
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   340
    shiftRed := aDevice shiftRed.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   341
    shiftGreen := aDevice shiftGreen.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   342
    shiftBlue := aDevice shiftBlue.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   343
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   344
    redOffs := 0.
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   345
    greenOffs := 1.  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   346
    blueOffs := 2.
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   347
    alphaOffs := 3.
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   348
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   349
    ((photometric == #argb) or:[ photometric == #rgb ]) ifTrue:[
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   350
        redOffs := 1. greenOffs := 2. blueOffs := 3. alphaOffs := 0.
8114
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   351
    ] ifFalse:[
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   352
        (photometric == #rgba) ifFalse:[
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   353
            ^ self anyImageAsTrueColorFormOn:aDevice
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   354
        ].    
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   355
    ].    
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   356
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   357
    "/
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   358
    "/ for now, only a few formats are supported
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   359
    "/
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   360
    myDepth := self bitsPerPixel.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   361
    usedDeviceBitsPerPixel == 24 ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   362
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   363
        "/ 24 bit/pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   364
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   365
        imageBits := ByteArray uninitializedNew:(width * height * 3).
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   366
        usedDevicePadding := 8.
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   367
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   368
        "/ 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
   369
%{
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   370
        unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   371
        unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   372
        int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   373
        int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   374
        int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   375
        // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   376
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   377
        if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   378
            srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   379
        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   380
            if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   381
                srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   382
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   383
        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   384
        if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   385
            dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   386
        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   387
            if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   388
                dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   389
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   390
        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   391
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   392
        if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   393
         && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   394
         && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   395
         && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   396
         && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   397
         && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   398
            int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   399
                rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   400
                rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   401
                lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   402
                lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   403
                lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   404
            int x, y, w;
5297
e1e2793072ad 32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   405
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   406
            w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   407
            if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   408
                if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   409
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   410
                        for (x=w; x > 0; x--) {                        
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   411
# ifdef __MSBFIRST
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   412
                            dstPtr[0] = srcPtr[_redOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   413
                            dstPtr[1] = srcPtr[_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   414
                            dstPtr[2] = srcPtr[_blueOffs];
5297
e1e2793072ad 32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   415
# else /* not MSB */
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   416
                            dstPtr[0] = srcPtr[_blueOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   417
                            dstPtr[1] = srcPtr[_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   418
                            dstPtr[2] = srcPtr[_redOffs];
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   419
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   420
                            dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   421
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   422
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   423
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   424
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   425
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   426
                        for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   427
                            unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   428
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   429
                            v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   430
                            v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   431
                            v |= (srcPtr[_blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   432
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   433
                            dstPtr[0] = (v) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   434
                            dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   435
                            dstPtr[2] = (v>>16) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   436
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   437
                            dstPtr[0] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   438
                            dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   439
                            dstPtr[2] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   440
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   441
                            dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   442
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   443
                        }
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
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   447
                for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   448
                    for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   449
                        unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   450
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   451
                        r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   452
                        g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   453
                        b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   454
                        v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   455
                        v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   456
                        v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   457
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   458
                        dstPtr[0] = (v) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   459
                        dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   460
                        dstPtr[2] = (v>>16) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   461
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   462
                        dstPtr[0] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   463
                        dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   464
                        dstPtr[2] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   465
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   466
                        dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   467
                        srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   468
                    }
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
        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   472
%}.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   473
    ] ifFalse:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   474
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   475
        "/ 8, 16 or 32 bit/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   476
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   477
        (usedDeviceBitsPerPixel == 16) ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   478
            padd := width \\ (usedDevicePadding // 16).
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   479
            imageBits := ByteArray uninitializedNew:((width + padd) * height * 2).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   480
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   481
            "/ 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
   482
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   483
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   484
            unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   485
            unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   486
            int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   487
            int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   488
            int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   489
            // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   490
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   491
            if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   492
                srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   493
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   494
                if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   495
                    srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   496
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   497
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   498
            if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   499
                dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   500
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   501
                if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   502
                    dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   503
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   504
            }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   505
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   506
            if (__bothSmallInteger(__INST(height),__INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   507
             && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   508
             && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   509
             && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   510
             && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   511
             && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   512
                int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   513
                    rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   514
                    rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   515
                    lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   516
                    lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   517
                    lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   518
                int x, y, w;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   519
                int p;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   520
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   521
                w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   522
                p = __intVal(padd) * 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   523
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   524
                if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   525
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   526
                        for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   527
                            unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   528
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   529
                            v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   530
                            v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   531
                            v |= (srcPtr[_blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   532
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   533
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   534
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   535
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   536
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   537
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   538
                            dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   539
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   540
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   541
                        dstPtr += p;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   542
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   543
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   544
                    if (p == 0) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   545
                        int n = __intVal(__INST(height)) * w;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   546
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   547
                        while (n >= 2) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   548
                            unsigned w, r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   549
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   550
                            n -= 2;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   551
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   552
                            r = srcPtr[_redOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   553
                            g = srcPtr[_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   554
                            b = srcPtr[_blueOffs];
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   555
                            v = (r >> rShRed) << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   556
                            v |= ((g >> rShGreen) << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   557
                            v |= ((b >> rShBlue) << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   558
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   559
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   560
# else
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   561
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   562
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   563
# endif /* not MSB */
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   564
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   565
                            r = srcPtr[3+_redOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   566
                            g = srcPtr[3+_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   567
                            b = srcPtr[3+_blueOffs];
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   568
                            v = (r >> rShRed) << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   569
                            v |= ((g >> rShGreen) << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   570
                            v |= ((b >> rShBlue) << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   571
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   572
                            ((short *)dstPtr)[1] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   573
# else
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   574
                            dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   575
                            dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   576
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   577
                            dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   578
                            srcPtr += 8;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   579
                        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   580
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   581
                        while (n--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   582
                            unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   583
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   584
                            r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   585
                            g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   586
                            b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   587
                            v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   588
                            v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   589
                            v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   590
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   591
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   592
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   593
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   594
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   595
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   596
                            dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   597
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   598
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   599
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   600
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   601
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   602
                                unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   603
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   604
                                r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   605
                                g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   606
                                b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   607
                                v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   608
                                v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   609
                                v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   610
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   611
                                ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   612
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   613
                                dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   614
                                dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   615
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   616
                                dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   617
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   618
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   619
                            dstPtr += p;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   620
                        }
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
            }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   624
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   625
        ] ifFalse:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   626
            "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   627
            "/ 32 or 8 bits/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   628
            "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   629
            (usedDeviceBitsPerPixel == 32) ifTrue:[
8000
62ea15884e2b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7922
diff changeset
   630
                "/ usedDevicePadding := 8.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   631
                imageBits := ByteArray uninitializedNew:(width * height * 4).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   632
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   633
                "/ 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
   634
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   635
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   636
                unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   637
                unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   638
                int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   639
                int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   640
                int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   641
                // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   642
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   643
                if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   644
                    srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   645
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   646
                    if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   647
                        srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   648
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   649
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   650
                if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   651
                    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   652
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   653
                    if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   654
                        dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   655
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   656
                }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   657
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   658
                if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   659
                 && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   660
                 && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   661
                 && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   662
                 && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   663
                 && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   664
                    int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   665
                        rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   666
                        rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   667
                        lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   668
                        lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   669
                        lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   670
                    int x, y, w;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   671
                    
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   672
                    w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   673
                    if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   674
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   675
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   676
                                unsigned v;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   677
                                
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   678
                                v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   679
                                v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   680
                                v |= (srcPtr[_blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   681
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   682
                                ((int *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   683
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   684
                                dstPtr[0] = (v>>24) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   685
                                dstPtr[1] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   686
                                dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   687
                                dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   688
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   689
                                dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   690
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   691
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   692
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   693
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   694
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   695
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   696
                                unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   697
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   698
                                r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   699
                                g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   700
                                b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   701
                                v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   702
                                v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   703
                                v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   704
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   705
                                ((int *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   706
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   707
                                dstPtr[0] = (v>>24) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   708
                                dstPtr[1] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   709
                                dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   710
                                dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   711
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   712
                                dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   713
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   714
                            }
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
                }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   718
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   719
            ] ifFalse:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   720
                "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   721
                "/ 8 bits/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   722
                "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   723
                (usedDeviceBitsPerPixel == 8) ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   724
                    usedDevicePadding := 8.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   725
                    imageBits := ByteArray uninitializedNew:(width * height).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   726
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   727
                    "/ 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
   728
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   729
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   730
                    unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   731
                    unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   732
                    int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   733
                    int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   734
                    int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   735
                    // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   736
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   737
                    if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   738
                        srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   739
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   740
                        if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   741
                            srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   742
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   743
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   744
                    if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   745
                        dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   746
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   747
                        if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   748
                            dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   749
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   750
                    }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   751
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   752
                    if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   753
                     && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   754
                     && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   755
                     && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   756
                     && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   757
                     && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   758
                        int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   759
                            rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   760
                            rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   761
                            lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   762
                            lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   763
                            lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   764
                        int x, y, w;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   765
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   766
                        w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   767
                        if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   768
                            for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   769
                                for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   770
                                    unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   771
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   772
                                    v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   773
                                    v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   774
                                    v |= (srcPtr[_blueOffs] << lShBlue);
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   775
                                    dstPtr[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   776
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   777
                                    dstPtr += 1;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   778
                                    srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   779
                                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   780
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   781
                        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   782
                            for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   783
                                for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   784
                                    unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   785
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   786
                                    r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   787
                                    g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   788
                                    b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   789
                                    v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   790
                                    v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   791
                                    v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   792
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   793
                                    dstPtr[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   794
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   795
                                    dstPtr += 1;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   796
                                    srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   797
                                }
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
                    }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   801
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   802
                ]
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   803
            ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   804
        ]
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   805
    ].
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
    imageBits isNil ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   808
        'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   809
        usedDeviceBitsPerPixel errorPrintCR.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   810
        ^ self asMonochromeFormOn:aDevice
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   811
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   812
7497
62a3648614ff #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7492
diff changeset
   813
    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
   814
    form isNil ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   815
        'Depth32Image [warning]: display bitmap creation failed' errorPrintCR.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   816
        ^ nil
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   817
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   818
    form initGC.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   819
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   820
    form
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   821
        copyBitsFrom:imageBits
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   822
        bitsPerPixel:usedDeviceBitsPerPixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   823
        depth:usedDeviceDepth
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   824
        padding:usedDevicePadding
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   825
        width:width height:height
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   826
        x:0 y:0 toX:0 y:0.
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   827
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   828
    ^ form
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   829
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   830
    "Created: / 27-05-2007 / 16:54:19 / cg"
8114
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   831
    "Modified: / 27-08-2017 / 21:06:49 / cg"
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   832
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   833
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   834
!Depth32Image methodsFor:'image manipulations'!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   835
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   836
negative
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   837
    |bytes 
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   838
     index "{ Class: SmallInteger }"
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   839
     newImage newBytes nBytes r g b a|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   840
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   841
    photometric ~~ #rgb ifTrue:[
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   842
        ^ super negative.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   843
    ].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   844
    bytes := self bits.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   845
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   846
    newImage := self copy.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   847
    nBytes := bytes size.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   848
    newImage bits:(newBytes := ByteArray new:nBytes).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   849
    index := 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   850
    [index < nBytes] whileTrue:[
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   851
        r := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   852
        newBytes at:index put:(255-r).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   853
        index := index + 1.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   854
        
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   855
        g := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   856
        newBytes at:index put:(255-g).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   857
        index := index + 1.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   858
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   859
        b := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   860
        newBytes at:index put:(255-b).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   861
        index := index + 1.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   862
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   863
        a := bytes at:index.
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   864
        newBytes at:index put:a.
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   865
        index := index + 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   866
    ].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   867
    ^ newImage
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   868
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   869
    "Modified (format): / 22-08-2017 / 17:13:38 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   870
! !
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   871
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   872
!Depth32Image methodsFor:'initialization'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   873
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   874
initialize
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   875
    super initialize.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   876
    samplesPerPixel := 4.
7819
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
   877
    bitsPerSample := #[8 8 8 8].
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   878
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   879
    "Created: / 27-05-2007 / 14:09:16 / cg"
7819
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
   880
    "Modified: / 30-01-2017 / 19:32:13 / stefan"
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   881
! !
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
!Depth32Image methodsFor:'magnification'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   884
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   885
magnifyRowFrom:srcBytes offset:srcStart
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   886
	  into:dstBytes offset:dstStart factor:mX
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   887
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   888
    "magnify a single pixel row - can only magnify by integer factors"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   889
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   890
%{
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   891
    unsigned char *srcP, *dstP;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   892
    int _mag;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   893
    REGISTER int i;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   894
    REGISTER unsigned char byte1, byte2, byte3, byte4;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   895
    int _pixels;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   896
    OBJ w = __INST(width);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   897
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   898
    if (__bothSmallInteger(srcStart, dstStart)
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   899
     && __bothSmallInteger(w, mX)
5474
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
   900
     && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   901
	_mag = __intVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   902
	srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   903
	dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   904
	_pixels = __intVal(w);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   905
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   906
	while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   907
	    byte1 = *srcP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   908
	    byte2 = *(srcP+1);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   909
	    byte3 = *(srcP+2);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   910
	    byte4 = *(srcP+3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   911
	    srcP += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   912
	    for (i=_mag; i>0; i--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   913
		*dstP = byte1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   914
		*(dstP+1) = byte2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   915
		*(dstP+2) = byte3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   916
		*(dstP+3) = byte4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   917
		dstP += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   918
	    }
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
	RETURN (self);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   921
    }
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
    super
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   924
	magnifyRowFrom:srcBytes offset:srcStart
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
   925
	into:dstBytes offset:dstStart factor:mX
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   926
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   927
    "Created: / 28-05-2007 / 15:20:52 / cg"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   928
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   929
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   930
!Depth32Image methodsFor:'queries'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   931
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   932
alphaBitsOf:pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   933
    "given a pixel-value, return the alpha component as byteValue (0..255)"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   934
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   935
    photometric == #argb ifTrue:[
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   936
        "a,r,g,b; MSB"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   937
        ^ (pixel bitShift:-24) bitAnd:16rFF.
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   938
    ].
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   939
    photometric == #rgba ifTrue:[
8002
d9f38365af4d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8000
diff changeset
   940
        "r,g,b,a; MSB"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   941
        ^ pixel bitAnd:16rFF.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   942
    ].
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   943
    "r,g,b,0; MSB"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   944
    ^ 0
8002
d9f38365af4d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8000
diff changeset
   945
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   946
    "Modified: / 22-08-2017 / 17:18:44 / cg"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   947
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   948
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   949
alphaComponentOf:pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   950
    "given a pixel-value, return the alpha component in percent (0..100)"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   951
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   952
    ^ (self alphaBitsOf:pixel) * (100.0 / 255.0)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   953
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   954
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   955
alphaMaskForPixelValue
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   956
    "return the mask used with translation from pixelValues to alphaBits.
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   957
     Determines the number of bits of alpha"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   958
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   959
    ^ 16rFF
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   960
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   961
    "Modified (comment): / 21-02-2017 / 16:37:31 / cg"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   962
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   963
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   964
alphaShiftForPixelValue
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   965
    "return the shift amount used with translation from pixelValues to alphaBits.
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   966
     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
   967
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   968
    photometric == #argb ifTrue:[
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   969
        "/ a,r,g,b - alpha in high byte
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   970
        ^ 24.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   971
    ].
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   972
    "/ r,g,b,a - alpha in low byte 
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   973
    "/ or r,g,b,0 - no alpha
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   974
    ^ 0
7896
1d6d23765472 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7819
diff changeset
   975
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   976
    "Modified: / 22-08-2017 / 17:19:36 / cg"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   977
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   978
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
bitsPerPixel
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   980
    "return the number of bits per pixel"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
    ^ 32
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   985
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   986
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   987
bitsPerRow
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   988
    "return the number of bits in one scanline of the image"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
   990
    ^ width * 32
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   992
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   994
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   995
bitsPerSample
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   996
    "return the number of bits per sample.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   997
     The return value is an array of bits-per-plane."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   998
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   999
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
7819
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1000
    ^ #[8 8 8 8]
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1001
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1002
    "Modified: / 30-01-2017 / 19:23:31 / stefan"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1003
!
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
blueBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1006
    "given a pixel-value, return the blue component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1007
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1008
    photometric == #rgba ifTrue:[
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1009
        ^ (pixel bitShift:-8) bitAnd:16rFF.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1010
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1011
    "r,g,b,a or ignored,r,g,b"
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1012
    ^ pixel bitAnd:16rFF.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1013
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1014
    "Modified: / 22-08-2017 / 18:23:41 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1015
!
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
blueComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1018
    "given a pixel-value, return the blue component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1019
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1020
    ^ (self blueBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1021
!
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
blueMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1024
    "return the mask used with translation from pixelValues to blueBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1025
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1026
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1027
!
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
blueShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1030
    "return the shift amount used with translation from pixelValues to blueBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1031
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1032
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1033
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1034
        ^ 0.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1035
    ].
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1036
    "r,g,b,a or r,g,b,0"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1037
    ^ -8
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1038
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1039
    "Modified: / 22-08-2017 / 17:19:55 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1040
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1041
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
bytesPerRow
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
    "return the number of bytes in one scanline of the image"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
    ^ width * 4.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1046
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1047
    "Created: 24.4.1997 / 19:00:28 / cg"
5327
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1048
!
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1049
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1050
greenBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1051
    "given a pixel-value, return the green component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1052
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1053
    photometric == #rgba ifTrue:[
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1054
        ^ (pixel bitShift:-16) bitAnd:16rFF.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1055
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1056
    ^ (pixel bitShift:-8) bitAnd:16rFF.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1057
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1058
    "Modified: / 22-08-2017 / 18:25:26 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1059
!
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
greenComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1062
    "given a pixel-value, return the green component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1063
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1064
    ^ (self greenBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1065
!
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
greenMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1068
    "return the mask used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1069
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1070
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1071
!
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
greenShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1074
    "return the shift amount used with translation from pixelValues to greenBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1075
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1076
    photometric == #argb ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1077
        "a,r,g,b"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1078
        ^ -8.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1079
    ].
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1080
    "r,g,b,a or r,g,b,0"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1081
    ^ -16
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1082
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1083
    "Modified: / 22-08-2017 / 17:20:14 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1084
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1085
5327
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1086
hasAlphaChannel
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1087
    "could be #rgb in 32 bits..."
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1088
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1089
    ^ (photometric == #argb) or:[photometric == #rgba]
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1090
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1091
    "Modified: / 21-02-2017 / 15:00:17 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1092
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1093
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1094
numAlphaBits
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1095
    photometric == #argb ifTrue:[
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1096
        ^ 8.
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1097
    ].
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1098
    photometric == #rgba ifTrue:[
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1099
        ^ 8.
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1100
    ].
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1101
    ^ 0
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1102
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1103
    "Created: / 22-08-2017 / 17:38:59 / cg"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1104
!
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
numBlueBits
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1107
    ^ 8
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1108
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1109
    "Created: / 22-08-2017 / 17:38:31 / cg"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1110
!
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
numGreenBits
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1113
    ^ 8
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1114
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1115
    "Created: / 22-08-2017 / 17:38:28 / cg"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1116
!
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
numRedBits
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1119
    ^ 8
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1120
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1121
    "Created: / 22-08-2017 / 17:38:25 / cg"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1122
!
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1123
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1124
redBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1125
    "given a pixel-value, return the red component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1126
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1127
    photometric == #rgba ifTrue:[
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1128
        ^ (pixel bitShift:-24) bitAnd:16rFF.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1129
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1130
    ^ (pixel bitShift:-16) bitAnd:16rFF.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1131
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1132
    "Modified: / 22-08-2017 / 18:25:52 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1133
!
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
redComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1136
    "given a pixel-value, return the red component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1137
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1138
    ^ (self redBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1139
!
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
redMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1142
    "return the mask used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1143
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1144
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1145
!
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
redShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1148
    "return the shift amount used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1149
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1150
    photometric == #rgba ifTrue:[
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1151
        ^ -24.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1152
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1153
    ^ -16
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1154
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1155
    "Modified: / 22-08-2017 / 18:27:02 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1156
!
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
rgbFromValue:pixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1159
    "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
  1160
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1161
    (photometric == #rgba) ifTrue:[
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1162
        ^ pixelValue rightShift:8     "lsb is alpha channel"
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1163
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1164
    ((photometric == #rgb) or:[photometric == #argb]) ifTrue:[
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1165
        ^ pixelValue bitAnd:16rFFFFFF     "msb is alpha channel"
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1166
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1167
    ^ super rgbFromValue:pixelValue.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1168
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1169
    "Modified: / 22-08-2017 / 18:32:22 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1170
!
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
samplesPerPixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1173
    "return the number of samples per pixel in the image."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1174
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1175
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1176
    ^ 4
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1177
!
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
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1180
    (photometric == #rgba) ifTrue:[
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1181
        "/ alpha in low byte
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1182
        ^ (((((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
  1183
    ].
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1184
    (photometric == #argb) ifTrue:[
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1185
        "/ alpha in high byte
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1186
        ^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits)) bitOr:16rFF000000
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1187
    ].
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1188
    (photometric == #rgb) ifTrue:[
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1189
        "/ no alpha
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1190
        ^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1191
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1192
    ^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1193
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1194
    "Modified: / 22-08-2017 / 18:34:30 / cg"
8166
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1195
!
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
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits alphaBits:alphaBits
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1198
    (photometric == #rgba) ifTrue:[
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1199
        "/ alpha in low byte
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1200
        ^ (((((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
  1201
    ].
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1202
    (photometric == #argb) ifTrue:[
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1203
        "/ alpha in high byte
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1204
        ^ (((((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
  1205
    ].
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1206
    (photometric == #rgb) ifTrue:[
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1207
        "/ no alpha
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1208
        ^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1209
    ].
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1210
    ^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits.
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1211
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1212
    "Created: / 05-09-2017 / 14:31:38 / cg"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1213
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1214
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1215
!Depth32Image class methodsFor:'documentation'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1216
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1217
version
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1218
    ^ '$Header$'
5474
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1219
!
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
version_CVS
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1222
    ^ '$Header$'
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1223
! !
6302
d393dae43c28 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
  1224