Depth32Image.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Apr 2020 15:28:14 +0200
changeset 9038 dd177fea6408
parent 8747 e84ae8a44b8d
permissions -rw-r--r--
#REFACTORING by stefan class: Font changed: #setFamily:face:style:size:sizeUnit:encoding:device:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8339
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
     1
"{ Encoding: utf8 }"
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
     2
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1995 by Claus Gittinger
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
     5
	      All Rights Reserved
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
    14
"{ Package: 'stx:libview' }"
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
    15
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
    16
"{ NameSpace: Smalltalk }"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
    17
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Image subclass:#Depth32Image
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Graphics-Images'
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!Depth32Image class methodsFor:'documentation'!
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
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 1995 by Claus Gittinger
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
    30
	      All Rights Reserved
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
    43
    this class represents 32 bit (eg. rgb+alpha) images.
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
    44
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    Only the minimum protocol is implemented here; much more is
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    needed for higher performance operations on depth32 images.
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
    47
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    48
    with #rgb, #rgba, #rgbx, photometrics 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    49
    pixels are internally stored byte-wise in rgba order.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    50
    (i.e. r at low-address byte, a at high-address byte). 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    51
    For rgb, a zero is always retrieved as alpha; 255 for rgbx.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    52
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    53
    When reading pixel values, photometric argb is returned as aarrggbb,
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    54
    photometric rgb is returned as 00rrggbb,
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    55
    photometric rgba is returned as rrggbb00,
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    56
    both on LSB and on MSB machines.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    57
    (i.e. blue in lower bits of the returned 32bit integer, alpha in the high bits for argb,
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    58
     and in the low bits for rgba)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    59
    Thus, pixelValues and rgbValues are identical, simulating MSB on all
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    60
    architectures.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    61
    (this should be transparent, if you use the rgbValueAt
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    62
     accessors; however, some old code uses pixelValueAt:, assuming that the
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    63
    returned pixel value is rrggbb - which it would not be without this hack).
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    64
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    65
    This also makes depth24Image's rgbValues compatible with depth32Image's rgbValues.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    66
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    67
    For argb and xrgb formats, alpha (or dummy alpha) is in the first byte 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    68
    (which are the high bits, as we present pixel values always MSB).
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
    69
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    [author:]
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
    71
        Claus Gittinger
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    [see also:]
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
    74
        Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
    75
        ImageReader
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
!Depth32Image class methodsFor:'queries'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    81
defaultPhotometric
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    82
    "return the default photometric pixel interpretation"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    83
7903
8dd4063b92fb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7902
diff changeset
    84
    "/ here we return #rgb - thus ignoring any alpha channel.
8dd4063b92fb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7902
diff changeset
    85
    "/ the reason is that many displays and graphics formats do use
8dd4063b92fb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7902
diff changeset
    86
    "/ 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
    87
    "/ Thus returning rgba here would make many images invisible (totally transparent)
8dd4063b92fb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7902
diff changeset
    88
    
5324
63a97775c5fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5297
diff changeset
    89
    ^ #rgb
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    90
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    91
    "Created: / 27-05-2007 / 14:03:59 / cg"
7903
8dd4063b92fb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7902
diff changeset
    92
    "Modified: / 16-02-2017 / 17:41:09 / cg"
8dd4063b92fb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7902
diff changeset
    93
    "Modified (comment): / 16-02-2017 / 19:00:25 / cg"
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    94
!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
    95
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
imageDepth
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    "return the depth of images represented by instances of
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
     this class - here we return 32"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    ^ 32
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    "Modified: 20.4.1996 / 23:40:01 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   106
!Depth32Image methodsFor:'accessing-pixels'!
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   108
colorAtX:x y:y
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   109
    "retrieve a pixel at x/y; return a color.
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   110
     Pixels start at x=0 , y=0 for upper left pixel, 
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   111
     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
   112
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   113
    |index "{ Class: SmallInteger }"
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   114
     rVal gVal bVal aVal|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   115
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   116
    index := 1 + (((width * y) + x) * 4).
8728
289cdc983b33 #BUGFIX by Stefan Reise
sr
parents: 8339
diff changeset
   117
    ((photometric == #rgb) or:[photometric == #rgbx]) ifTrue:[
289cdc983b33 #BUGFIX by Stefan Reise
sr
parents: 8339
diff changeset
   118
        "/ byteorder is: r,g,b,<ignoredAlpha>
289cdc983b33 #BUGFIX by Stefan Reise
sr
parents: 8339
diff changeset
   119
        rVal := bytes at:index.
289cdc983b33 #BUGFIX by Stefan Reise
sr
parents: 8339
diff changeset
   120
        gVal := bytes at:(index + 1).
289cdc983b33 #BUGFIX by Stefan Reise
sr
parents: 8339
diff changeset
   121
        bVal := bytes at:(index + 2).
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   122
        ^ Color redByte:rVal greenByte:gVal blueByte:bVal
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   123
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   124
    (photometric == #rgba) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   125
        "/ byteorder is: r,g,b,<ignoredAlpha>
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   126
        rVal := bytes at:(index).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   127
        gVal := bytes at:(index + 1).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   128
        bVal := bytes at:(index + 2).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   129
        aVal := bytes at:(index + 3).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   130
        ^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   131
    ].
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   132
    photometric == #argb ifTrue:[
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   133
        "/ byteorder is: a,r,g,b
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   134
        aVal := bytes at:(index).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   135
        rVal := bytes at:(index + 1).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   136
        gVal := bytes at:(index + 2).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   137
        bVal := bytes at:(index + 3).
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   138
        ^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   139
    ].
8339
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
   140
    photometric == #xrgb ifTrue:[
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
   141
        "/ byteorder is: ignored-alpha,r,g,b
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
   142
        rVal := bytes at:(index + 1).
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
   143
        gVal := bytes at:(index + 2).
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
   144
        bVal := bytes at:(index + 3).
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
   145
        ^ Color redByte:rVal greenByte:gVal blueByte:bVal
b2b10047577b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8327
diff changeset
   146
    ].
7124
51bbda668ab4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
   147
    "/ the inherited method should handle all cases.
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   148
    ^ super colorAtX:x y:y.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   149
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   150
    "Modified: / 22-08-2017 / 18:17:38 / cg"
8728
289cdc983b33 #BUGFIX by Stefan Reise
sr
parents: 8339
diff changeset
   151
    "Modified: / 12-07-2019 / 14:39:41 / Stefan Reise"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   152
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   153
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   154
colorAtX:x y:y put:aColor
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   155
    "set the pixel at x/y to aColor.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   156
     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
   157
     x = width-1, y=height-1 for lower right pixel."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   158
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   159
    |index "{ Class: SmallInteger }"
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   160
     r g b|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   161
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   162
    index := 1 + (((width * y) + x) * 4).
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   163
    r := aColor redByte.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   164
    g := aColor greenByte.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   165
    b := aColor blueByte.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   166
    
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   167
    ((photometric == #rgb) or:[photometric == #rgbx]) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   168
        "/ byteorder is: r,g,b,ignored-alpha
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   169
        bytes at:(index) put:r.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   170
        bytes at:(index + 1) put:g.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   171
        bytes at:(index + 2) put:b.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   172
        ^ self
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   173
    ].
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   174
    (photometric == #rgba) ifTrue:[
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   175
        "/ byteorder is: r,g,b,a
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   176
        bytes at:(index + 0) put:r.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   177
        bytes at:(index + 1) put:g.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   178
        bytes at:(index + 2) put:b.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   179
        bytes at:(index + 3) put:(aColor alphaByte). "alpha channel in last byte"
7167
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   180
        ^ self
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   181
    ].
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   182
    (photometric == #argb) ifTrue:[
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   183
        "/ byteorder is: a,r,g,b
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   184
        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
   185
        bytes at:(index + 1) put:r.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   186
        bytes at:(index + 2) put:g.
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   187
        bytes at:(index + 3) put:b.             
7167
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   188
        ^ self
12b5d9ffc66c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7124
diff changeset
   189
    ].
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   190
    (photometric == #xrgb) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   191
        "/ byteorder is: ignored-alpha,r,g,b
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   192
        bytes at:(index + 1) put:r.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   193
        bytes at:(index + 2) put:g.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   194
        bytes at:(index + 3) put:b.
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   195
        ^ self
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   196
    ].
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   197
7917
fb1dcd2edc4e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7903
diff changeset
   198
    super colorAtX:x y:y put:aColor.
fb1dcd2edc4e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7903
diff changeset
   199
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   200
    "Modified: / 22-08-2017 / 18:17:14 / cg"
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   201
    "Modified: / 22-07-2019 / 13:07:48 / Claus Gittinger"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   202
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   203
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
pixelAtX:x y:y
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    "retrieve a pixel at x/y; return a pixelValue.
7514
cdfa1afc6956 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7497
diff changeset
   206
     The interpretation of the returned value depends on the photometric
cdfa1afc6956 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7497
diff changeset
   207
     and the colormap. See also Image>>atX:y:)
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
     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
   209
     x = width-1, y=height-1 for lower right pixel.
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   210
     With rgba photometric, the pixel value contains r/g/b/a in lsb order 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   211
     (i.e. r at low, a at high bits);
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   212
     with argb, alpha is in the low byte"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
1669
d156d2623f41 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1663
diff changeset
   214
    |pixelIndex "{ Class: SmallInteger }"|
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
7274
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   216
%{  /* NOCONTEXT */
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   217
    OBJ b = __INST(bytes);
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   218
    OBJ w = __INST(width);
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   219
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   220
    if (__isByteArrayLike(b)
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   221
     && __bothSmallInteger(x, y)
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   222
     && __isSmallInteger(w)
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   223
     && (__INST(pixelFunction)==nil) ) {
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   224
        int _idx;
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   225
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   226
        _idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4;
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   227
        if (((unsigned)(_idx+3)) < __byteArraySize(b)) {
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   228
            unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]);
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   229
            unsigned int _pix;
7917
fb1dcd2edc4e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7903
diff changeset
   230
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   231
#ifdef __MSBFIRST__
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   232
            _pix = ((int *)pPix)[0];
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   233
#else
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   234
            _pix = pPix[0] << 24;
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   235
            _pix |= pPix[1] << 16;
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   236
            _pix |= pPix[2] << 8;
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   237
            _pix |= pPix[3];
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   238
#endif
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   239
7274
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   240
#if __POINTER_SIZE__ == 8
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   241
            RETURN( __MKSMALLINT(_pix) );
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   242
#else
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   243
            RETURN( __MKUINT(_pix) );
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   244
#endif
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   245
        }
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   246
    }
32011db2fd2c #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7225
diff changeset
   247
%}.
6302
d393dae43c28 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   248
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
d393dae43c28 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   249
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   250
    pixelIndex := 1 + (((width * y) + x) * 4).
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   251
    ^ bytes unsignedInt32At:pixelIndex MSB:true.
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
7917
fb1dcd2edc4e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7903
diff changeset
   253
    "Created: / 24-04-1997 / 19:00:28 / cg"
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   254
    "Modified: / 21-02-2017 / 17:21:44 / cg"
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   255
    "Modified (comment): / 22-08-2017 / 18:24:22 / cg"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
pixelAtX:x y:y put:aPixelValue
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    "set the pixel at x/y to aPixelValue.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   260
     The interpretation of the pixelValue depends on the photometric.
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
     Pixels start at x=0 , y=0 for upper left pixel, end at
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   262
     x = width-1, y=height-1 for lower right pixel.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   263
     With rgba photometric, the pixel value contains r/g/b/a in lsb order 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   264
     (i.e. r at low, a at high bits);
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   265
     with argb, alpha is in the low byte"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
1669
d156d2623f41 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1663
diff changeset
   267
    |pixelIndex "{ Class: SmallInteger }"|
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   269
%{  /* NOCONTEXT */
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   270
    OBJ b = __INST(bytes);
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   271
    OBJ w = __INST(width);
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   272
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   273
    if ((b != nil)
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   274
     && __isByteArrayLike(b)
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   275
     && __bothSmallInteger(x, y)
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   276
     && __isSmallInteger(aPixelValue)
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   277
     && (__INST(pixelFunction)==nil) ) {
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   278
        int _idx;
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   279
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   280
        _idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4;
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   281
        if (((unsigned)(_idx+3)) < __byteArraySize(b)) {
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   282
            unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]);
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   283
            unsigned int _pix = __intVal(aPixelValue);
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   284
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   285
#ifdef __MSBFIRST__
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   286
            ((int *)pPix)[0] = _pix;
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   287
#else
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   288
            pPix[0] = (_pix >> 24) & 0xFF;
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   289
            pPix[1] = (_pix >> 16) & 0xFF;
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   290
            pPix[2] = (_pix >> 8) & 0xFF;
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   291
            pPix[3] = _pix & 0xFF;
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   292
#endif
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   293
            RETURN(self);
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   294
        }
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   295
    }
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   296
%}.
8201
d8a475e6e994 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8166
diff changeset
   297
    bytes isNil ifTrue:[ self createPixelStore ].
d8a475e6e994 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8166
diff changeset
   298
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   299
    pixelIndex := 1 + (((width * y) + x) * 4).
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   300
    bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true.
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
4790
652fca7eac26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   302
    "Created: / 24-04-1997 / 19:00:28 / cg"
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
   303
    "Modified: / 22-08-2017 / 18:21:47 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   304
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   305
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   306
rowAt:y putAll:pixelArray startingAt:startIndex
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   307
    "store a single rows bits from bits in the pixelArray argument;
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   308
     The interpretation of the pixel values depends on the photometric.
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   309
     Notice: row coordinate starts at 0."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   310
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   311
    |bytes pixel
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   312
     dstIdx "{ Class: SmallInteger }" 
6846
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   313
     w "{ Class: SmallInteger }"|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   314
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   315
    bytes := self bits.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   316
    dstIdx := (y * self bytesPerRow) + 1.
6846
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   317
    w := width - 1.
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   318
6c9367f0ecb8 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6841
diff changeset
   319
    0 to:w do:[:col |
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   320
        pixel := pixelArray at:(startIndex + col).
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   321
        "/ msbFirst
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   322
        bytes unsignedInt32At:dstIdx put:pixel MSB:true.
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   323
        dstIdx := dstIdx + 4.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   324
    ].
7917
fb1dcd2edc4e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7903
diff changeset
   325
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   326
    "Modified (comment): / 21-02-2017 / 15:03:24 / cg"
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   327
!
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   328
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   329
valueFromColor:aColor
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   330
    "get a color's pixel value."
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   331
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   332
    |r g b a|
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   333
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   334
    r := aColor redByte.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   335
    g := aColor greenByte.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   336
    b := aColor blueByte.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   337
    
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   338
    ((photometric == #rgb) or:[photometric == #rgbx]) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   339
        "/ byteorder is: r,g,b,ignored-alpha
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   340
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
8747
e84ae8a44b8d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8746
diff changeset
   341
        ^ ((((r bitShift:8) bitOr:g) bitShift:8) bitOr:b) bitShift:8.
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   342
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   343
    a := aColor alphaByte.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   344
    (photometric == #rgba) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   345
        "/ byteorder is: r,g,b,a
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   346
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   347
        ^ (((((r bitShift:8) bitOr:g) bitShift:8) bitOr:b) bitShift:8) bitOr:a.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   348
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   349
    (photometric == #argb) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   350
        "/ byteorder is: a,r,g,b
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   351
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   352
        ^ (((((a bitShift:8) bitOr:r) bitShift:8) bitOr:g) bitShift:8) bitOr:b.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   353
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   354
    (photometric == #xrgb) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   355
        "/ byteorder is: ignored-alpha,r,g,b
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   356
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   357
        ^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   358
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   359
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   360
    ^ super valueFromColor:aColor.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   361
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   362
    "Created: / 22-07-2019 / 13:43:20 / Claus Gittinger"
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   363
!
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   364
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   365
valueFromRGB:anRGBValue
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   366
    "get the pixel value corresponding to an RGB value."
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   367
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   368
    |"r g b" a|
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   369
    
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   370
    "/
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   371
    "/ r := (anRGBValue bitShift:-16) bitAnd:16rFF.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   372
    "/ g := (anRGBValue bitShift:-8) bitAnd:16rFF.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   373
    "/ b := anRGBValue bitAnd:16rFF.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   374
    a := 255.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   375
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   376
    ((photometric == #rgb) or:[photometric == #rgbx]) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   377
        "/ byteorder is: r,g,b,ignored-alpha
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   378
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
8746
0338514ca23d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8744
diff changeset
   379
        ^ anRGBValue.
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   380
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   381
    (photometric == #rgba) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   382
        "/ byteorder is: r,g,b,a
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   383
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   384
        ^ (anRGBValue bitShift:8) bitOr:a.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   385
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   386
    (photometric == #argb) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   387
        "/ byteorder is: a,r,g,b
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   388
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   389
        ^ anRGBValue bitOr:(a bitShift:24).
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   390
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   391
    (photometric == #xrgb) ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   392
        "/ byteorder is: ignored-alpha,r,g,b
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   393
        "/ but the pixelvalue is assumed to be MSB (i.e. red at high byte)
8746
0338514ca23d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8744
diff changeset
   394
        ^ anRGBValue bitShift:8.
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   395
    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   396
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   397
    ^ super valueFromRGB:anRGBValue.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   398
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
   399
    "Created: / 22-07-2019 / 13:47:11 / Claus Gittinger"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   402
!Depth32Image methodsFor:'converting rgb images'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   403
7492
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   404
computeAlphaValuesFromMask:aMaskImage
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   405
    "convert a mask into alpha values;
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   406
     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
   407
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   408
    |alphaMask|
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   409
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   410
    alphaMask := (self alphaMaskForPixelValue bitShift:self alphaShiftForPixelValue).
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   411
    self 
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   412
        valuesFromX:0 y:0 toX:(width-1) y:(height-1)
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   413
        do:[:x :y :pixelValue |
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   414
            (aMaskImage pixelAtX:x y:y) ~~ 0 ifTrue:[
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   415
                self pixelAtX:x y:y put:(pixelValue bitOr:alphaMask).
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   416
            ] ifFalse:[
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   417
                self pixelAtX:x y:y put:(pixelValue bitClear:alphaMask).
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   418
            ].
7492
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   419
        ].
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   420
    photometric := #rgba
7902
865d2b3679cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7896
diff changeset
   421
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   422
    "Modified: / 21-02-2017 / 16:41:02 / cg"
7492
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   423
!
34cfdad00603 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7279
diff changeset
   424
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   425
rgbImageAsTrueColorFormOn:aDevice
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   426
    "return a truecolor form from the rgba or argb-picture."
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   427
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   428
    |bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   429
     myDepth form imageBits padd
8000
62ea15884e2b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7922
diff changeset
   430
     rightShiftR rightShiftG rightShiftB
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   431
     shiftRed shiftGreen shiftBlue
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   432
     redOffs greenOffs blueOffs alphaOffs|
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   433
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   434
    bytes := self bits.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   435
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   436
    bestFormat := self bestSupportedImageFormatFor:aDevice.
4763
69afd837e817 leftover halt:
Claus Gittinger <cg@exept.de>
parents: 4761
diff changeset
   437
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   438
    usedDeviceDepth := bestFormat at:#depth.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   439
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   440
    usedDevicePadding := bestFormat at:#padding.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   441
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   442
    rightShiftR := (8 - aDevice bitsRed).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   443
    rightShiftG := (8 - aDevice bitsGreen).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   444
    rightShiftB := (8 - aDevice bitsBlue).
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   445
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   446
    shiftRed := aDevice shiftRed.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   447
    shiftGreen := aDevice shiftGreen.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   448
    shiftBlue := aDevice shiftBlue.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   449
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   450
    redOffs := 0.
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   451
    greenOffs := 1.  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   452
    blueOffs := 2.
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   453
    alphaOffs := 3.
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   454
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   455
    ((photometric == #argb) or:[ photometric == #rgb ]) ifTrue:[
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   456
        redOffs := 1. greenOffs := 2. blueOffs := 3. alphaOffs := 0.
8114
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   457
    ] ifFalse:[
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   458
        (photometric == #rgba) ifFalse:[
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   459
            ^ self anyImageAsTrueColorFormOn:aDevice
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   460
        ].    
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   461
    ].    
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   462
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   463
    "/
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   464
    "/ for now, only a few formats are supported
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   465
    "/
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   466
    myDepth := self bitsPerPixel.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   467
    usedDeviceBitsPerPixel == 24 ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   468
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   469
        "/ 24 bit/pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   470
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   471
        imageBits := ByteArray uninitializedNew:(width * height * 3).
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   472
        usedDevicePadding := 8.
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   473
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   474
        "/ 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
   475
%{
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   476
        unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   477
        unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   478
        int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   479
        int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   480
        int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   481
        // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   482
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   483
        if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   484
            srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   485
        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   486
            if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   487
                srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   488
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   489
        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   490
        if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   491
            dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   492
        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   493
            if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   494
                dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   495
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   496
        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   497
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   498
        if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   499
         && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   500
         && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   501
         && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   502
         && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   503
         && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   504
            int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   505
                rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   506
                rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   507
                lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   508
                lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   509
                lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   510
            int x, y, w;
5297
e1e2793072ad 32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   511
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   512
            w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   513
            if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   514
                if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   515
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   516
                        for (x=w; x > 0; x--) {                        
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   517
# ifdef __MSBFIRST
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   518
                            dstPtr[0] = srcPtr[_redOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   519
                            dstPtr[1] = srcPtr[_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   520
                            dstPtr[2] = srcPtr[_blueOffs];
5297
e1e2793072ad 32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   521
# else /* not MSB */
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   522
                            dstPtr[0] = srcPtr[_blueOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   523
                            dstPtr[1] = srcPtr[_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   524
                            dstPtr[2] = srcPtr[_redOffs];
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   525
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   526
                            dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   527
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   528
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   529
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   530
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   531
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   532
                        for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   533
                            unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   534
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   535
                            v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   536
                            v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   537
                            v |= (srcPtr[_blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   538
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   539
                            dstPtr[0] = (v) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   540
                            dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   541
                            dstPtr[2] = (v>>16) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   542
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   543
                            dstPtr[0] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   544
                            dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   545
                            dstPtr[2] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   546
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   547
                            dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   548
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   549
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   550
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   551
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   552
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   553
                for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   554
                    for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   555
                        unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   556
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   557
                        r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   558
                        g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   559
                        b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   560
                        v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   561
                        v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   562
                        v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   563
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   564
                        dstPtr[0] = (v) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   565
                        dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   566
                        dstPtr[2] = (v>>16) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   567
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   568
                        dstPtr[0] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   569
                        dstPtr[1] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   570
                        dstPtr[2] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   571
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   572
                        dstPtr += 3;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   573
                        srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   574
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   575
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   576
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   577
        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   578
%}.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   579
    ] ifFalse:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   580
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   581
        "/ 8, 16 or 32 bit/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   582
        "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   583
        (usedDeviceBitsPerPixel == 16) ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   584
            padd := width \\ (usedDevicePadding // 16).
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   585
            imageBits := ByteArray uninitializedNew:((width + padd) * height * 2).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   586
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   587
            "/ 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
   588
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   589
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   590
            unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   591
            unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   592
            int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   593
            int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   594
            int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   595
            // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   596
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   597
            if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   598
                srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
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
                if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   601
                    srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   602
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   603
            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   604
            if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   605
                dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   606
            } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   607
                if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   608
                    dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   609
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   610
            }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   611
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   612
            if (__bothSmallInteger(__INST(height),__INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   613
             && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   614
             && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   615
             && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   616
             && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   617
             && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   618
                int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   619
                    rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   620
                    rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   621
                    lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   622
                    lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   623
                    lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   624
                int x, y, w;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   625
                int p;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   626
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   627
                w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   628
                p = __intVal(padd) * 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   629
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   630
                if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   631
                    for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   632
                        for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   633
                            unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   634
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   635
                            v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   636
                            v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   637
                            v |= (srcPtr[_blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   638
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   639
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   640
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   641
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   642
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   643
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   644
                            dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   645
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   646
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   647
                        dstPtr += p;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   648
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   649
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   650
                    if (p == 0) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   651
                        int n = __intVal(__INST(height)) * w;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   652
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   653
                        while (n >= 2) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   654
                            unsigned w, r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   655
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   656
                            n -= 2;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   657
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   658
                            r = srcPtr[_redOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   659
                            g = srcPtr[_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   660
                            b = srcPtr[_blueOffs];
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   661
                            v = (r >> rShRed) << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   662
                            v |= ((g >> rShGreen) << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   663
                            v |= ((b >> rShBlue) << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   664
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   665
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   666
# else
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   667
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   668
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   669
# endif /* not MSB */
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   670
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   671
                            r = srcPtr[3+_redOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   672
                            g = srcPtr[3+_greenOffs];
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   673
                            b = srcPtr[3+_blueOffs];
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   674
                            v = (r >> rShRed) << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   675
                            v |= ((g >> rShGreen) << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   676
                            v |= ((b >> rShBlue) << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   677
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   678
                            ((short *)dstPtr)[1] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   679
# else
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   680
                            dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   681
                            dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   682
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   683
                            dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   684
                            srcPtr += 8;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   685
                        }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   686
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   687
                        while (n--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   688
                            unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   689
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   690
                            r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   691
                            g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   692
                            b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   693
                            v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   694
                            v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   695
                            v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   696
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   697
                            ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   698
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   699
                            dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   700
                            dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   701
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   702
                            dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   703
                            srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   704
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   705
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   706
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   707
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   708
                                unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   709
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   710
                                r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   711
                                g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   712
                                b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   713
                                v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   714
                                v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   715
                                v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   716
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   717
                                ((short *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   718
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   719
                                dstPtr[0] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   720
                                dstPtr[1] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   721
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   722
                                dstPtr += 2;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   723
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   724
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   725
                            dstPtr += p;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   726
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   727
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   728
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   729
            }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   730
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   731
        ] ifFalse:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   732
            "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   733
            "/ 32 or 8 bits/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   734
            "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   735
            (usedDeviceBitsPerPixel == 32) ifTrue:[
8000
62ea15884e2b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7922
diff changeset
   736
                "/ usedDevicePadding := 8.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   737
                imageBits := ByteArray uninitializedNew:(width * height * 4).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   738
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   739
                "/ 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
   740
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   741
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   742
                unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   743
                unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   744
                int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   745
                int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   746
                int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   747
                // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   748
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   749
                if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   750
                    srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   751
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   752
                    if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   753
                        srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   754
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   755
                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   756
                if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   757
                    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   758
                } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   759
                    if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   760
                        dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   761
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   762
                }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   763
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   764
                if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   765
                 && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   766
                 && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   767
                 && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   768
                 && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   769
                 && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   770
                    int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   771
                        rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   772
                        rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   773
                        lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   774
                        lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   775
                        lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   776
                    int x, y, w;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   777
                    
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   778
                    w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   779
                    if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   780
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   781
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   782
                                unsigned v;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   783
                                
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   784
                                v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   785
                                v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   786
                                v |= (srcPtr[_blueOffs] << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   787
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   788
                                ((int *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   789
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   790
                                dstPtr[0] = (v>>24) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   791
                                dstPtr[1] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   792
                                dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   793
                                dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   794
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   795
                                dstPtr += 4;
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
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   800
                        for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   801
                            for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   802
                                unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   803
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   804
                                r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   805
                                g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   806
                                b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   807
                                v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   808
                                v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   809
                                v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   810
# ifdef __MSBFIRST
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   811
                                ((int *)dstPtr)[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   812
# else /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   813
                                dstPtr[0] = (v>>24) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   814
                                dstPtr[1] = (v>>16) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   815
                                dstPtr[2] = (v>>8) & 0xFF;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   816
                                dstPtr[3] = (v) & 0xFF;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   817
# endif /* not MSB */
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   818
                                dstPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   819
                                srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   820
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   821
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   822
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   823
                }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   824
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   825
            ] ifFalse:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   826
                "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   827
                "/ 8 bits/pixel ...
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   828
                "/
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   829
                (usedDeviceBitsPerPixel == 8) ifTrue:[
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   830
                    usedDevicePadding := 8.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   831
                    imageBits := ByteArray uninitializedNew:(width * height).
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   832
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   833
                    "/ 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
   834
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   835
%{
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   836
                    unsigned char *srcPtr = 0;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   837
                    unsigned char *dstPtr = 0;
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   838
                    int _redOffs = __intVal(redOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   839
                    int _greenOffs = __intVal(greenOffs);  
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   840
                    int _blueOffs = __intVal(blueOffs);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   841
                    // int _alphaOffs = __intVal(alphaOffs);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   842
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   843
                    if (__isByteArrayLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   844
                        srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   845
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   846
                        if (__isExternalBytesLike(bytes)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   847
                            srcPtr = __externalBytesAddress(bytes);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   848
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   849
                    }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   850
                    if (__isByteArray(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   851
                        dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   852
                    } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   853
                        if (__isExternalBytesLike(imageBits)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   854
                            dstPtr = __externalBytesAddress(imageBits);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   855
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   856
                    }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   857
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   858
                    if (__bothSmallInteger(__INST(height), __INST(width))
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   859
                     && __bothSmallInteger(rightShiftR, shiftRed)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   860
                     && __bothSmallInteger(rightShiftG, shiftGreen)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   861
                     && __bothSmallInteger(rightShiftB, shiftBlue)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   862
                     && srcPtr
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   863
                     && dstPtr) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   864
                        int rShRed = __intVal(rightShiftR),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   865
                            rShGreen = __intVal(rightShiftG),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   866
                            rShBlue = __intVal(rightShiftB),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   867
                            lShRed = __intVal(shiftRed),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   868
                            lShGreen = __intVal(shiftGreen),
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   869
                            lShBlue = __intVal(shiftBlue);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   870
                        int x, y, w;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   871
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   872
                        w = __intVal(__INST(width));
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   873
                        if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   874
                            for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   875
                                for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   876
                                    unsigned v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   877
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   878
                                    v = srcPtr[_redOffs] << lShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   879
                                    v |= (srcPtr[_greenOffs] << lShGreen);
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   880
                                    v |= (srcPtr[_blueOffs] << lShBlue);
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   881
                                    dstPtr[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   882
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   883
                                    dstPtr += 1;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   884
                                    srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   885
                                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   886
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   887
                        } else {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   888
                            for (y=__intVal(__INST(height)); y > 0; y--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   889
                                for (x=w; x > 0; x--) {
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   890
                                    unsigned r, g, b, v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   891
8094
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   892
                                    r = srcPtr[_redOffs] >> rShRed;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   893
                                    g = srcPtr[_greenOffs] >> rShGreen;
72be8139d8e8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8089
diff changeset
   894
                                    b = srcPtr[_blueOffs] >> rShBlue;
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   895
                                    v = r << lShRed;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   896
                                    v |= (g << lShGreen);
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   897
                                    v |= (b << lShBlue);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   898
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   899
                                    dstPtr[0] = v;
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   900
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   901
                                    dstPtr += 1;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   902
                                    srcPtr += 4;
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   903
                                }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   904
                            }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   905
                        }
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   906
                    }
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   907
%}.
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   908
                ]
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   909
            ].
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   910
        ]
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   911
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   912
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   913
    imageBits isNil ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   914
        'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   915
        usedDeviceBitsPerPixel errorPrintCR.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   916
        ^ self asMonochromeFormOn:aDevice
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   917
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   918
7497
62a3648614ff #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7492
diff changeset
   919
    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
   920
    form isNil ifTrue:[
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   921
        'Depth32Image [warning]: display bitmap creation failed' errorPrintCR.
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   922
        ^ nil
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   923
    ].
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   924
    form initGC.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   925
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   926
    form
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   927
        copyBitsFrom:imageBits
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   928
        bitsPerPixel:usedDeviceBitsPerPixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   929
        depth:usedDeviceDepth
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   930
        padding:usedDevicePadding
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   931
        width:width height:height
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
   932
        x:0 y:0 toX:0 y:0.
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   933
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   934
    ^ form
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   935
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   936
    "Created: / 27-05-2007 / 16:54:19 / cg"
8114
4b012d4736b0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
   937
    "Modified: / 27-08-2017 / 21:06:49 / cg"
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   938
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   939
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   940
!Depth32Image methodsFor:'image manipulations'!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   941
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   942
negative
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   943
    |bytes 
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   944
     index "{ Class: SmallInteger }"
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   945
     newImage newBytes nBytes r g b a
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   946
     alphaFirst|
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   947
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   948
    ((photometric ~~ #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   949
    and:[(photometric ~~ #rgba)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   950
    and:[(photometric ~~ #xrgb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   951
    and:[(photometric ~~ #rgbx)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   952
    and:[(photometric ~~ #rgb0)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   953
    and:[(photometric ~~ #'0rgb')]]]]]) ifTrue:[
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   954
        ^ super negative.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   955
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   956
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   957
    alphaFirst := (photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   958
                  or:[ (photometric == #xrgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   959
                  or:[ (photometric == #'0rgb') ]].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   960
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   961
    bytes := self bits.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   962
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   963
    newImage := self copy.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   964
    nBytes := bytes size.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   965
    newImage bits:(newBytes := ByteArray new:nBytes).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   966
    index := 1.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   967
    [index < nBytes] whileTrue:[
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   968
        alphaFirst ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   969
            a := bytes at:index.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   970
            newBytes at:index put:a.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   971
            index := index + 1.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   972
        ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   973
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   974
        r := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   975
        newBytes at:index put:(255-r).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   976
        index := index + 1.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   977
        
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   978
        g := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   979
        newBytes at:index put:(255-g).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   980
        index := index + 1.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   981
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   982
        b := bytes at:index.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   983
        newBytes at:index put:(255-b).
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   984
        index := index + 1.
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   985
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   986
        alphaFirst ifFalse:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   987
            a := bytes at:index.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   988
            newBytes at:index put:a.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   989
            index := index + 1.
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
   990
        ]
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   991
    ].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   992
    ^ newImage
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
   993
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
   994
    "Modified (format): / 22-08-2017 / 17:13:38 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   995
! !
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
   996
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   997
!Depth32Image methodsFor:'initialization'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   998
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   999
initialize
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1000
    super initialize.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1001
    samplesPerPixel := 4.
7819
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1002
    bitsPerSample := #[8 8 8 8].
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1003
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1004
    "Created: / 27-05-2007 / 14:09:16 / cg"
7819
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1005
    "Modified: / 30-01-2017 / 19:32:13 / stefan"
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1006
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1007
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1008
!Depth32Image methodsFor:'magnification'!
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1009
8262
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1010
hardAntiAliasedMagnifiedBy:scaleArg
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1011
    "return a new image magnified by scalePoint, aPoint.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1012
     This interpolates pixels and is therefore much slower,
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1013
     but generates nicer looking magnifications."
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1014
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1015
    |scalePoint mX
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1016
     mY
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1017
     newWidth  "{ Class: SmallInteger }"
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1018
     newHeight "{ Class: SmallInteger }"
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1019
     w         "{ Class: SmallInteger }"
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1020
     h         "{ Class: SmallInteger }"
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1021
     newImage newBits bitsPerPixel newBytesPerRow newMask
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1022
     value
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1023
     srcRow pixelArray|
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1024
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1025
    scalePoint := scaleArg asPoint. 
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1026
    mX := scalePoint x.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1027
    mY := scalePoint y.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1028
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1029
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1030
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1031
    newWidth := (width * mX) truncated.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1032
    newHeight := (height * mY) truncated.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1033
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1034
    bitsPerPixel := self depth.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1035
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1036
    newBits := ByteArray new: "uninitializedNew:" (newBytesPerRow * newHeight).
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1037
    newBits isNil ifTrue:[
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1038
        'Depth32Image [warning]: failed to allocate byteArray for image bits' errorPrintCR.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1039
        ^ nil
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1040
    ].
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1041
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1042
    mask notNil ifTrue:[
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1043
        newMask := (mask magnifiedBy:scalePoint)
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1044
    ].
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1045
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1046
    newImage := self species new.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1047
    newImage
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1048
        width:newWidth
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1049
        height:newHeight
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1050
        photometric:photometric
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1051
        samplesPerPixel:samplesPerPixel
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1052
        bitsPerSample:bitsPerSample
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1053
        colorMap:nil
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1054
        bits:newBits
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1055
        mask:newMask.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1056
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1057
    mY := mY asFloat.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1058
    mX := mX asFloat.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1059
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1060
%{
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1061
    REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBits)->ba_element;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1062
    unsigned char *_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1063
    unsigned char *_srcRowP, *sP;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1064
    int _width4 = __intVal(__INST(width)) * 4;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1065
    int _oldW = __intVal(__INST(width)) - 1;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1066
    int _oldH = __intVal(__INST(height)) - 1;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1067
    int _w = __intVal(newWidth) - 1;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1068
    int _h = __intVal(newHeight) - 1;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1069
    int _row, _col;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1070
    double _mX = __floatVal(mX);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1071
    double _mY = __floatVal(mY);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1072
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1073
    for (_row = 0; _row <= _h; _row++) {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1074
        double _srcY;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1075
        double _dY;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1076
        int _sR;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1077
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1078
        _srcY = ((double)_row / _mY);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1079
        _sR = (int)_srcY;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1080
        _dY = _srcY - ((double)_sR);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1081
        _srcRowP = _srcP + (_width4 * _sR);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1082
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1083
        for (_col = 0; _col <= _w; _col++) {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1084
            unsigned int rHere, gHere, bHere, aHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1085
            unsigned int rRight, gRight, bRight, aRight;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1086
            unsigned int rRightBelow, gRightBelow, bRightBelow, aRightBelow;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1087
            unsigned int rBelow, gBelow, bBelow, aBelow;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1088
            unsigned int _r, _g, _b, _a;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1089
            double wHere, wRight, wRightBelow, wBelow, sumW;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1090
            double _srcX;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1091
            double _dX;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1092
            int _sC;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1093
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1094
            _srcX = ((double)_col / _mX);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1095
            _sC = (int)_srcX;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1096
            _dX = _srcX - ((double)_sC);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1097
            sP = _srcRowP + (_sC * 4);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1098
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1099
            rHere = sP[0];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1100
            gHere = sP[1];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1101
            bHere = sP[2];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1102
            aHere = sP[3];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1103
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1104
            if (_sC < _oldW) {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1105
                rRight = sP[0+4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1106
                gRight = sP[0+5];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1107
                bRight = sP[0+6];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1108
                aRight = sP[0+7];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1109
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1110
                if (_sR < _oldH) {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1111
                    rBelow = sP[0+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1112
                    gBelow = sP[1+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1113
                    bBelow = sP[2+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1114
                    aBelow = sP[3+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1115
                    rRightBelow = sP[4+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1116
                    gRightBelow = sP[5+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1117
                    bRightBelow = sP[6+_width4];
8264
a37a81b3942b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8262
diff changeset
  1118
                    aRightBelow = sP[7+_width4];
8262
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1119
                } else {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1120
                    rRightBelow = rHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1121
                    gRightBelow = gHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1122
                    bRightBelow = bHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1123
                    aRightBelow = aHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1124
                    rBelow = rHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1125
                    gBelow = gHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1126
                    bBelow = bHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1127
                    aBelow = aHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1128
                }
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1129
            } else {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1130
                rRight = rRightBelow = rHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1131
                gRight = gRightBelow = gHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1132
                bRight = bRightBelow = bHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1133
                aRight = aRightBelow = aHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1134
                if (_sR < _oldH) {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1135
                    rBelow = sP[0+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1136
                    gBelow = sP[1+_width4];
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1137
                    bBelow = sP[2+_width4];
8264
a37a81b3942b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8262
diff changeset
  1138
                    aBelow = sP[3+_width4];
8262
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1139
                } else {
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1140
                    rBelow = rHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1141
                    gBelow = gHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1142
                    bBelow = bHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1143
                    aBelow = aHere;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1144
                }
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1145
            }
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1146
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1147
            wHere = (1.0 - _dX) * (1.0 - _dY);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1148
            wRight = _dX * (1.0 - _dY);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1149
            wBelow = _dY * (1.0 - _dX);
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1150
            wRightBelow = _dX * _dY;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1151
            sumW = wHere + wRight + wBelow + wRightBelow;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1152
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1153
            _r = ((rHere * wHere) + (rRight * wRight) + (rBelow * wBelow) + (rRightBelow * wRightBelow)) / sumW;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1154
            _g = ((gHere * wHere) + (gRight * wRight) + (gBelow * wBelow) + (gRightBelow * wRightBelow)) / sumW;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1155
            _b = ((bHere * wHere) + (bRight * wRight) + (bBelow * wBelow) + (bRightBelow * wRightBelow)) / sumW;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1156
            _a = ((aHere * wHere) + (aRight * wRight) + (aBelow * wBelow) + (aRightBelow * wRightBelow)) / sumW;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1157
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1158
            _dstP[0] = _r;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1159
            _dstP[1] = _g;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1160
            _dstP[2] = _b;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1161
            _dstP[3] = _a;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1162
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1163
            _dstP += 4;
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1164
        }
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1165
    }
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1166
%}.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1167
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1168
    ^ newImage
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1169
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1170
    "
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1171
     |i|
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1172
     i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1173
     i := Depth32Image fromImage:i.
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1174
     i hardAntiAliasedMagnifiedBy:2@2
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1175
    "
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1176
    "
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1177
     |i|
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1178
     i := Depth32Image width:3 height:3 fromArray:#[ 0 0 0 127   0 0 0 127  0 0 0 127
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1179
                                                     0 0 0 127  255 255 255 127  0 0 0 127
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1180
                                                     0 0 0 127   0 0 0 127  0 0 0 127].
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1181
     i hardAntiAliasedMagnifiedBy:8@8
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1182
    "
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1183
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1184
    "Created: / 02-06-1997 / 13:18:53 / cg"
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1185
    "Modified: / 30-08-2017 / 13:35:20 / cg"
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1186
!
a9845a7cad69 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8201
diff changeset
  1187
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1188
magnifyRowFrom:srcBytes offset:srcStart
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1189
	  into:dstBytes offset:dstStart factor:mX
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1190
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1191
    "magnify a single pixel row - can only magnify by integer factors"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1192
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1193
%{
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1194
    unsigned char *srcP, *dstP;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1195
    int _mag;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1196
    REGISTER int i;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1197
    REGISTER unsigned char byte1, byte2, byte3, byte4;
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1198
    int _pixels;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1199
    OBJ w = __INST(width);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1200
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1201
    if (__bothSmallInteger(srcStart, dstStart)
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1202
     && __bothSmallInteger(w, mX)
5474
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1203
     && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1204
	_mag = __intVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1205
	srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1206
	dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1207
	_pixels = __intVal(w);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1208
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1209
	while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1210
	    byte1 = *srcP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1211
	    byte2 = *(srcP+1);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1212
	    byte3 = *(srcP+2);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1213
	    byte4 = *(srcP+3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1214
	    srcP += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1215
	    for (i=_mag; i>0; i--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1216
		*dstP = byte1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1217
		*(dstP+1) = byte2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1218
		*(dstP+2) = byte3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1219
		*(dstP+3) = byte4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1220
		dstP += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1221
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1222
	}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1223
	RETURN (self);
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1224
    }
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1225
%}.
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1226
    super
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1227
	magnifyRowFrom:srcBytes offset:srcStart
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5474
diff changeset
  1228
	into:dstBytes offset:dstStart factor:mX
4761
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1229
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1230
    "Created: / 28-05-2007 / 15:20:52 / cg"
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1231
! !
9672fbf6ad20 defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  1232
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1233
!Depth32Image methodsFor:'queries'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1235
alphaBitsOf:pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1236
    "given a pixel-value, return the alpha component as byteValue (0..255)"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1237
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1238
    photometric == #argb ifTrue:[
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1239
        "/ value is: aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1240
        ^ (pixel bitShift:-24) bitAnd:16rFF.   
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1241
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1242
    (photometric == #rgb) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1243
        "/ value is: 00rrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1244
        ^ 0
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1245
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1246
    (photometric == #xrgb) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1247
        "/ value is: FFrrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1248
        ^ 255       
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1249
    ].
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1250
    photometric == #rgba ifTrue:[
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1251
        "/ value is: rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1252
        ^ pixel bitAnd:16rFF           
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1253
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1254
    photometric == #rgb0 ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1255
        "/ value is: rrggbb00
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1256
        ^ 0           
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1257
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1258
    photometric == #rgbx ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1259
        "/ value is: rrggbbFF
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1260
        ^ 255           
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1261
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1262
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1263
    ^ super alphaBitsOf:pixel.
8002
d9f38365af4d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8000
diff changeset
  1264
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1265
    "Modified: / 22-08-2017 / 17:18:44 / cg"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1266
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1267
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1268
alphaComponentOf:pixel
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1269
    "given a pixel-value, return the alpha component in percent (0..100)"
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1270
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1271
    ^ (self alphaBitsOf:pixel) * (100.0 / 255.0)
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1272
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1273
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1274
alphaMaskForPixelValue
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1275
    "return the mask used with translation from pixelValues to alphaBits.
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1276
     Determines the number of bits of alpha"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1277
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1278
    ^ 16rFF
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1279
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1280
    "Modified (comment): / 21-02-2017 / 16:37:31 / cg"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1281
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1282
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1283
alphaShiftForPixelValue
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1284
    "return the shift amount used with translation from pixelValues to alphaBits.
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1285
     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
  1286
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1287
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1288
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1289
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1290
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1291
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1292
        ^ -24.    
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1293
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1294
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1295
    or:[ (photometric == #rgbx) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1296
    or:[ (photometric == #rgb0)]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1297
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1298
        ^ 0.    
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1299
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1300
    ^ super alphaShiftForPixelValue.
7896
1d6d23765472 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7819
diff changeset
  1301
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1302
    "Modified: / 22-08-2017 / 17:19:36 / cg"
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1303
!
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1304
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1305
bitsPerPixel
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1306
    "return the number of bits per pixel"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1307
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1308
    ^ 32
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1309
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1310
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1311
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1312
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1313
bitsPerRow
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
    "return the number of bits in one scanline of the image"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1315
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1316
    ^ width * 32
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1317
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1318
    "Created: 24.4.1997 / 19:00:28 / cg"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1319
!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1320
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1321
bitsPerSample
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1322
    "return the number of bits per sample.
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1323
     The return value is an array of bits-per-plane."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1324
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1325
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
7819
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1326
    ^ #[8 8 8 8]
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1327
1dd77ab4b48f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7514
diff changeset
  1328
    "Modified: / 30-01-2017 / 19:23:31 / stefan"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1329
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1330
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1331
blueBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1332
    "given a pixel-value, return the blue component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1333
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1334
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1335
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1336
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1337
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1338
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1339
        ^ pixel bitAnd:16rFF.    
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1340
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1341
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1342
    or:[ (photometric == #rgbx) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1343
    or:[ (photometric == #rgb0)]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1344
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1345
        ^ (pixel bitShift:-8) bitAnd:16rFF.    
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1346
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1347
    ^ super blueBitsOf:pixel.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1348
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1349
    "Modified: / 22-08-2017 / 18:23:41 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1350
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1351
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1352
blueComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1353
    "given a pixel-value, return the blue component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1354
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1355
    ^ (self blueBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1356
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1357
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1358
blueMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1359
    "return the mask used with translation from pixelValues to blueBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1360
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1361
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1362
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1363
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1364
blueShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1365
    "return the shift amount used with translation from pixelValues to blueBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1366
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1367
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1368
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1369
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1370
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1371
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1372
        ^ 0.    
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1373
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1374
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1375
    or:[ (photometric == #rgbx) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1376
    or:[ (photometric == #rgb0)]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1377
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1378
        ^ -8
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1379
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1380
    ^ super blueShiftForPixelValue
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1381
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1382
    "Modified: / 22-08-2017 / 17:19:55 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1383
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1384
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1385
bytesPerRow
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1386
    "return the number of bytes in one scanline of the image"
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1387
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1388
    ^ width * 4.
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1389
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1390
    "Created: 24.4.1997 / 19:00:28 / cg"
5327
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1391
!
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1392
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1393
greenBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1394
    "given a pixel-value, return the green component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1395
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1396
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1397
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1398
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1399
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1400
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1401
        ^ (pixel bitShift:-8) bitAnd:16rFF.    
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1402
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1403
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1404
    or:[ (photometric == #rgbx) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1405
    or:[ (photometric == #rgb0)]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1406
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1407
        ^ (pixel bitShift:-16) bitAnd:16rFF.    
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1408
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1409
    ^ super greenBitsOf:pixel.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1410
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1411
    "Modified: / 22-08-2017 / 18:23:41 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1412
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1413
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1414
greenComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1415
    "given a pixel-value, return the green component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1416
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1417
    ^ (self greenBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1418
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1419
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1420
greenMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1421
    "return the mask used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1422
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1423
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1424
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1425
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1426
greenShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1427
    "return the shift amount used with translation from pixelValues to greenBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1428
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1429
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1430
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1431
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1432
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1433
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1434
        ^ -8    
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1435
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1436
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1437
    or:[ (photometric == #rgbx) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1438
    or:[ (photometric == #rgb0)]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1439
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1440
        ^ -16.    
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1441
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1442
    ^ super greenShiftForPixelValue.
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1443
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1444
5327
cc9e8a99b6d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  1445
hasAlphaChannel
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1446
    "could be #rgb in 32 bits..."
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1447
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1448
    ^ (photometric == #argb) or:[photometric == #rgba]
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1449
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1450
    "Modified: / 21-02-2017 / 15:00:17 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1451
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1452
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1453
numAlphaBits
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1454
    ^ 8 "/ always 8 - even if ignored
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1455
"/    photometric == #argb ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1456
"/        ^ 8.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1457
"/    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1458
"/    photometric == #rgba ifTrue:[
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1459
"/        ^ 8.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1460
"/    ].
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1461
"/    ^ 0
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1462
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1463
    "Created: / 22-08-2017 / 17:38:59 / cg"
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1464
    "Modified: / 22-07-2019 / 13:36:02 / Claus Gittinger"
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1465
!
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1466
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1467
numBlueBits
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1468
    ^ 8
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1469
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1470
    "Created: / 22-08-2017 / 17:38:31 / cg"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1471
!
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1472
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1473
numGreenBits
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1474
    ^ 8
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1475
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1476
    "Created: / 22-08-2017 / 17:38:28 / cg"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1477
!
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1478
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1479
numRedBits
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1480
    ^ 8
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1481
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1482
    "Created: / 22-08-2017 / 17:38:25 / cg"
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1483
!
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1484
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1485
redBitsOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1486
    "given a pixel-value, return the red component as byteValue (0..255)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1487
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1488
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1489
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1490
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1491
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1492
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1493
        ^ (pixel bitShift:-16) bitAnd:16rFF.    
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1494
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1495
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1496
    or:[ (photometric == #rgbx) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1497
    or:[ (photometric == #rgb0)]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1498
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1499
        ^ (pixel bitShift:-24) bitAnd:16rFF.    
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1500
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1501
    ^ super redBitsOf:pixel.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1502
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1503
    "Modified: / 22-08-2017 / 18:23:41 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1504
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1505
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1506
redComponentOf:pixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1507
    "given a pixel-value, return the red component in percent (0..100)"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1508
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1509
    ^ (self redBitsOf:pixel) * (100.0 / 255.0)
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1510
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1511
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1512
redMaskForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1513
    "return the mask used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1514
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1515
    ^ 16rFF
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1516
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1517
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1518
redShiftForPixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1519
    "return the shift amount used with translation from pixelValues to redBits"
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1520
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1521
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1522
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1523
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1524
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1525
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1526
        ^ -16    
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1527
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1528
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1529
    or:[ (photometric == #rgbx) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1530
    or:[ (photometric == #rgb0)]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1531
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1532
        ^ -24.    
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1533
    ].
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1534
    ^ super redShiftForPixelValue.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1535
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1536
    "Modified: / 22-08-2017 / 18:23:41 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1537
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1538
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1539
rgbFromValue:pixelValue
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1540
    "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
  1541
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1542
    ((photometric == #argb)
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1543
    or:[ (photometric == #rgb) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1544
    or:[ (photometric == #xrgb) ]])
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1545
     ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1546
        "/ aarrggbb
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1547
        ^ pixelValue bitAnd:16rFFFFFF   
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1548
    ].
8327
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1549
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1550
    ((photometric == #rgba) 
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1551
    or:[ photometric == #rgbx
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1552
    or:[ photometric == #rgb0]]) ifTrue:[
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1553
        "/ rrggbbaa
98509411b62e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8264
diff changeset
  1554
        ^ (pixelValue rightShift:8) bitAnd:16rFFFFFF       
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1555
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1556
    ^ super rgbFromValue:pixelValue.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1557
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1558
    "Modified: / 22-08-2017 / 18:32:22 / cg"
6841
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1559
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1560
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1561
samplesPerPixel
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1562
    "return the number of samples per pixel in the image."
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1563
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1564
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1565
    ^ 4
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1566
!
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1567
3f4935787091 class: Depth32Image
Stefan Vogel <sv@exept.de>
parents: 6302
diff changeset
  1568
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1569
    "given the rgb bits, each in 0..maxXXXValue (i.e. according to
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1570
     r/g/b channels number of bits, return the corresponding pixel value.
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1571
     For now, only useful with RGB images"
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1572
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1573
     (photometric == #rgba) ifTrue:[
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1574
        "/ alpha in low byte
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1575
        ^ (((((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
  1576
    ].
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1577
    (photometric == #argb) ifTrue:[
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1578
        "/ alpha in high byte
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1579
        ^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits)) bitOr:16rFF000000
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1580
    ].
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1581
    (photometric == #rgb) ifTrue:[
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1582
        "/ no alpha
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1583
        ^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits
8085
ba867f680fde #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8002
diff changeset
  1584
    ].
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1585
    ^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits.
7922
800a52cd955b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7917
diff changeset
  1586
8089
9a9ae8e56007 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8085
diff changeset
  1587
    "Modified: / 22-08-2017 / 18:34:30 / cg"
8744
d9c17cf6f9dd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8728
diff changeset
  1588
    "Modified (comment): / 22-07-2019 / 13:51:14 / Claus Gittinger"
8166
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1589
!
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1590
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1591
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits alphaBits:alphaBits
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1592
    (photometric == #rgba) ifTrue:[
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1593
        "/ alpha in low byte
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1594
        ^ (((((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
  1595
    ].
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1596
    (photometric == #argb) ifTrue:[
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1597
        "/ alpha in high byte
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1598
        ^ (((((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
  1599
    ].
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1600
    (photometric == #rgb) ifTrue:[
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1601
        "/ no alpha
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1602
        ^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1603
    ].
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1604
    ^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits.
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1605
71ddc0db4c31 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8114
diff changeset
  1606
    "Created: / 05-09-2017 / 14:31:38 / cg"
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1607
! !
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1608
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1609
!Depth32Image class methodsFor:'documentation'!
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1610
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1611
version
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1612
    ^ '$Header$'
5474
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1613
!
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1614
037b18c68ac9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5327
diff changeset
  1615
version_CVS
7122
100dd2139178 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6846
diff changeset
  1616
    ^ '$Header$'
1663
a2be19b14666 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1617
! !
6302
d393dae43c28 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
  1618