ImageReader.st
author matilk
Wed, 13 Sep 2017 09:40:34 +0200
changeset 8174 2704c965b97b
parent 8146 97a4ee050bd6
child 8246 7fbe2b212aee
permissions -rw-r--r--
#BUGFIX by Maren class: DeviceGraphicsContext changed: #displayDeviceOpaqueForm:x:y: nil check
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     1
"
6
7ee0cfde237d *** empty log message ***
claus
parents: 5
diff changeset
     2
 COPYRIGHT (c) 1991 by Claus Gittinger
77
da4678fae5c8 *** empty log message ***
claus
parents: 72
diff changeset
     3
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     4
48194c26a46c Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
"
3260
e4e8e2b99900 use Image>>newForDepth:
Claus Gittinger <cg@exept.de>
parents: 3243
diff changeset
    12
"{ Package: 'stx:libview' }"
e4e8e2b99900 use Image>>newForDepth:
Claus Gittinger <cg@exept.de>
parents: 3243
diff changeset
    13
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
    14
"{ NameSpace: Smalltalk }"
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
    15
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    16
Object subclass:#ImageReader
8145
83f792c6d9b1 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8129
diff changeset
    17
	instanceVariableNames:'width height data byteOrder inStream outStream photometric depth
1648
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
    18
		samplesPerPixel bitsPerSample colorMap mask maskPixel
7375
9675ac6ee423 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7184
diff changeset
    19
		dimensionCallBack dimensionHolder progressHolder imageSequence
9675ac6ee423 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7184
diff changeset
    20
		metaData'
8129
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
    21
	classVariableNames:'BlackCountTable BlackShiftTable LeftBits ReverseBits
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
    22
		WhiteCountTable WhiteShiftTable'
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    23
	poolDictionaries:''
3843
57d7f752c63b code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 3839
diff changeset
    24
	category:'Graphics-Images-Readers'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    25
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    26
189
claus
parents: 153
diff changeset
    27
!ImageReader primitiveDefinitions!
claus
parents: 153
diff changeset
    28
%{
1891
0dc56210cbfb VMS stuff
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    29
6062
dc9d34b204a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6061
diff changeset
    30
# define STDC_HEADERS
189
claus
parents: 153
diff changeset
    31
#ifndef _STDIO_H_INCLUDED_
claus
parents: 153
diff changeset
    32
# include <stdio.h>
claus
parents: 153
diff changeset
    33
# define _STDIO_H_INCLUDED_
claus
parents: 153
diff changeset
    34
#endif
5973
028f7d7e7e73 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5927
diff changeset
    35
6061
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    36
#if defined(__osx__)
6062
dc9d34b204a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6061
diff changeset
    37
# include <stdlib.h>
6061
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    38
# define _MALLOC_H_INCLUDED_
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    39
#endif
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    40
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
    41
#ifndef _MALLOC_H_INCLUDED_
5973
028f7d7e7e73 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5927
diff changeset
    42
# if !defined(FREEBSD)
6061
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    43
#  include <malloc.h>
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    44
#  define _MALLOC_H_INCLUDED_
5527
216f389ffe42 freebsd changes
Michael Beyl <mb@exept.de>
parents: 5481
diff changeset
    45
# endif
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
    46
#endif
2423
416882dbf8cf changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents: 2261
diff changeset
    47
416882dbf8cf changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents: 2261
diff changeset
    48
189
claus
parents: 153
diff changeset
    49
%}
claus
parents: 153
diff changeset
    50
! !
claus
parents: 153
diff changeset
    51
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    52
!ImageReader primitiveFunctions!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    53
%{
48194c26a46c Initial revision
claus
parents:
diff changeset
    54
48194c26a46c Initial revision
claus
parents:
diff changeset
    55
/*
48194c26a46c Initial revision
claus
parents:
diff changeset
    56
 * ccitt decompression
48194c26a46c Initial revision
claus
parents:
diff changeset
    57
 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    58
static short *whiteCountTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    59
static char  *whiteShiftTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    60
static short *blackCountTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    61
static char  *blackShiftTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    62
48194c26a46c Initial revision
claus
parents:
diff changeset
    63
struct ccitt_def {
48194c26a46c Initial revision
claus
parents:
diff changeset
    64
    unsigned short bits;
48194c26a46c Initial revision
claus
parents:
diff changeset
    65
    short nBits;
48194c26a46c Initial revision
claus
parents:
diff changeset
    66
};
48194c26a46c Initial revision
claus
parents:
diff changeset
    67
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    68
static struct ccitt_def
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    69
whiteDef[] = {
48194c26a46c Initial revision
claus
parents:
diff changeset
    70
    { 0x3500, 8 }, /* 0 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    71
    { 0x1c00, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    72
    { 0x7000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    73
    { 0x8000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    74
    { 0xb000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    75
    { 0xc000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    76
    { 0xe000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    77
    { 0xf000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    78
    { 0x9800, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    79
    { 0xA000, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    80
    { 0x3800, 5 }, /* 10 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    81
    { 0x4000, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    82
    { 0x2000, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    83
    { 0x0c00, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    84
    { 0xd000, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    85
    { 0xd400, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    86
    { 0xa800, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    87
    { 0xac00, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    88
    { 0x4e00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    89
    { 0x1800, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    90
    { 0x1000, 7 }, /* 20 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    91
    { 0x2e00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    92
    { 0x0600, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    93
    { 0x0800, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    94
    { 0x5000, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    95
    { 0x5600, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    96
    { 0x2600, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    97
    { 0x4800, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    98
    { 0x3000, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    99
    { 0x0200, 8 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   100
    { 0x0300, 8 }, /* 30 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   101
    { 0x1a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   102
    { 0x1b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   103
    { 0x1200, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   104
    { 0x1300, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   105
    { 0x1400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   106
    { 0x1500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   107
    { 0x1600, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   108
    { 0x1700, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   109
    { 0x2800, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   110
    { 0x2900, 8 }, /* 40 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   111
    { 0x2a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   112
    { 0x2b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   113
    { 0x2c00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   114
    { 0x2d00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   115
    { 0x0400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   116
    { 0x0500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   117
    { 0x0a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   118
    { 0x0b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   119
    { 0x5200, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   120
    { 0x5300, 8 }, /* 50 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   121
    { 0x5400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   122
    { 0x5500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   123
    { 0x2400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   124
    { 0x2500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   125
    { 0x5800, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   126
    { 0x5900, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   127
    { 0x5a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   128
    { 0x5b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   129
    { 0x4a00, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   130
    { 0x4b00, 8 }, /* 60 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   131
    { 0x3200, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   132
    { 0x3300, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   133
    { 0x3400, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   134
/* ---------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   135
    { 0xd800, 5 }, /* 64 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   136
    { 0x9000, 5 }, /* 128 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   137
    { 0x5c00, 6 }, /* 192 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   138
    { 0x6e00, 7 }, /* 256 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   139
    { 0x3600, 8 }, /* 320 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   140
    { 0x3700, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   141
    { 0x6400, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   142
    { 0x6500, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   143
    { 0x6800, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   144
    { 0x6700, 8 }, /* 640 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   145
    { 0x6600, 9 }, /* 704 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   146
    { 0x6680, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   147
    { 0x6900, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   148
    { 0x6980, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   149
    { 0x6a00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   150
    { 0x6a80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   151
    { 0x6b00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   152
    { 0x6b80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   153
    { 0x6c00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   154
    { 0x6c80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   155
    { 0x6d00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   156
    { 0x6d80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   157
    { 0x4c00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   158
    { 0x4c80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   159
    { 0x4d00, 9 }, /* 1600 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   160
    { 0x6000, 6 }, /* 1664 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   161
    { 0x4d80, 9 }, /* 1728 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   162
/* -------------------------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   163
    { 0x0100, 11 }, /* 1792 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   164
    { 0x0180, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   165
    { 0x01a0, 11 }, /* 1920 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   166
    { 0x0120, 12 }, /* 1984 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   167
    { 0x0130, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   168
    { 0x0140, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   169
    { 0x0150, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   170
    { 0x0160, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   171
    { 0x0170, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   172
    { 0x01c0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   173
    { 0x01d0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   174
    { 0x01e0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   175
    { 0x01f0, 12 }, /* 2560 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   176
/* -------------------------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   177
    { 0x0010, 12 }, /* EOL */
48194c26a46c Initial revision
claus
parents:
diff changeset
   178
};
48194c26a46c Initial revision
claus
parents:
diff changeset
   179
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   180
static struct ccitt_def
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   181
blackDef[] = {
48194c26a46c Initial revision
claus
parents:
diff changeset
   182
    { 0x0dc0, 10 }, /* 0 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   183
    { 0x4000, 3 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   184
    { 0xc000, 2 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   185
    { 0x8000, 2 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   186
    { 0x6000, 3 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   187
    { 0x3000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   188
    { 0x2000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   189
    { 0x1800, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   190
    { 0x1400, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   191
    { 0x1000, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   192
    { 0x0800, 7 }, /* 10 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   193
    { 0x0a00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   194
    { 0x0e00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   195
    { 0x0400, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   196
    { 0x0700, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   197
    { 0x0c00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   198
    { 0x05c0, 10 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   199
    { 0x0600, 10 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   200
    { 0x0200, 10 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   201
    { 0x0ce0, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   202
    { 0x0d00, 11 }, /* 20 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   203
    { 0x0d80, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   204
    { 0x06e0, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   205
    { 0x0500, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   206
    { 0x02e0, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   207
    { 0x0300, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   208
    { 0x0ca0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   209
    { 0x0cb0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   210
    { 0x0cc0, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   211
    { 0x0cd0, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   212
    { 0x0680, 12 }, /* 30 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   213
    { 0x0690, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   214
    { 0x06a0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   215
    { 0x06b0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   216
    { 0x0d20, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   217
    { 0x0d30, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   218
    { 0x0d40, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   219
    { 0x0d50, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   220
    { 0x0d60, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   221
    { 0x0d70, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   222
    { 0x06c0, 12 }, /* 40 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   223
    { 0x06d0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   224
    { 0x0da0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   225
    { 0x0db0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   226
    { 0x0540, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   227
    { 0x0550, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   228
    { 0x0560, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   229
    { 0x0570, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   230
    { 0x0640, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   231
    { 0x0650, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   232
    { 0x0520, 12 }, /* 50 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   233
    { 0x0530, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   234
    { 0x0240, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   235
    { 0x0370, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   236
    { 0x0380, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   237
    { 0x0270, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   238
    { 0x0280, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   239
    { 0x0580, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   240
    { 0x0590, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   241
    { 0x02b0, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   242
    { 0x02c0, 12 }, /* 60 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   243
    { 0x05a0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   244
    { 0x0660, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   245
    { 0x0670, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   246
/* ---------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   247
    { 0x03c0, 10 }, /* 64 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   248
    { 0x0c80, 12 }, /* 128 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   249
    { 0x0c90, 12 }, /* 192 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   250
    { 0x05b0, 12 }, /* 256 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   251
    { 0x0330, 12 }, /* 320 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   252
    { 0x0340, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   253
    { 0x0350, 12 }, /* 448 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   254
    { 0x0360, 13 }, /* 512 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   255
    { 0x0368, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   256
    { 0x0250, 13 }, /* 640 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   257
    { 0x0258, 13 }, /* 704 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   258
    { 0x0260, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   259
    { 0x0268, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   260
    { 0x0390, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   261
    { 0x0398, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   262
    { 0x03a0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   263
    { 0x03a8, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   264
    { 0x03b0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   265
    { 0x03b8, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   266
    { 0x0290, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   267
    { 0x0298, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   268
    { 0x02a0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   269
    { 0x02a8, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   270
    { 0x02d0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   271
    { 0x02d8, 13 }, /* 1600 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   272
    { 0x0320, 13 }, /* 1664 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   273
    { 0x0328, 13 }, /* 1728 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   274
/* -------------------------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   275
};
48194c26a46c Initial revision
claus
parents:
diff changeset
   276
6761
7307a75477f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6618
diff changeset
   277
static void
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   278
initCCITTTables() {
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   279
    register int cnt, bits, value;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   280
    int nBits, index;
48194c26a46c Initial revision
claus
parents:
diff changeset
   281
48194c26a46c Initial revision
claus
parents:
diff changeset
   282
    if (whiteCountTable != (short *)0) return;
48194c26a46c Initial revision
claus
parents:
diff changeset
   283
48194c26a46c Initial revision
claus
parents:
diff changeset
   284
    whiteCountTable = (short *) malloc(sizeof(short) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   285
    if (! whiteCountTable) return;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   286
    whiteShiftTable = (char *) malloc(sizeof(char) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   287
    if (! whiteShiftTable) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   288
	goto fail1;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   289
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   290
    blackCountTable = (short *) malloc(sizeof(short) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   291
    if (! blackCountTable) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   292
	goto fail2;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   293
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   294
    blackShiftTable = (char *) malloc(sizeof(char) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   295
    if (! blackShiftTable) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   296
	free(blackCountTable); blackCountTable = (short *)0;
95
47ac85948d38 asText eliminated
claus
parents: 89
diff changeset
   297
fail2:
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   298
	free(whiteShiftTable); whiteShiftTable = (char *)0;
95
47ac85948d38 asText eliminated
claus
parents: 89
diff changeset
   299
fail1:
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   300
	free(whiteCountTable); whiteCountTable = (short *)0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   301
	return;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   302
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   303
48194c26a46c Initial revision
claus
parents:
diff changeset
   304
    for (index = 0; index < 8192; index++) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   305
	whiteCountTable[index] = -1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   306
	blackCountTable[index] = -1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   307
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   308
48194c26a46c Initial revision
claus
parents:
diff changeset
   309
    for (value = 0; value <= 63; value++) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   310
	nBits = whiteDef[value].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   311
	bits = whiteDef[value].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   312
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   313
	    whiteCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   314
	    whiteShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   315
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   316
	nBits = blackDef[value].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   317
	bits = blackDef[value].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   318
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   319
	    blackCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   320
	    blackShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   321
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   322
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   323
    index = value;
48194c26a46c Initial revision
claus
parents:
diff changeset
   324
48194c26a46c Initial revision
claus
parents:
diff changeset
   325
    for (; value <= 1728; value += 64) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   326
	nBits = whiteDef[index].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   327
	bits = whiteDef[index].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   328
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   329
	    whiteCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   330
	    whiteShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   331
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   332
	nBits = blackDef[index].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   333
	bits = blackDef[index].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   334
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   335
	    blackCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   336
	    blackShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   337
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   338
	index++;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   339
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   340
48194c26a46c Initial revision
claus
parents:
diff changeset
   341
    for (; value <= 2560; value += 64) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   342
	nBits = whiteDef[index].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   343
	bits = whiteDef[index].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   344
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   345
	    whiteCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   346
	    whiteShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   347
	    blackCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   348
	    blackShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   349
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   350
	index++;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   351
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   352
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   353
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   354
static short
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   355
leftBits[] = {
48194c26a46c Initial revision
claus
parents:
diff changeset
   356
     0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF
48194c26a46c Initial revision
claus
parents:
diff changeset
   357
};
48194c26a46c Initial revision
claus
parents:
diff changeset
   358
189
claus
parents: 153
diff changeset
   359
static int
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   360
__decodeCCITTgroup3__(unsigned char *from, unsigned char *to, int len)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   361
{
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   362
    register int cnt;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   363
    register short *countPtr;
48194c26a46c Initial revision
claus
parents:
diff changeset
   364
    register char *shiftPtr;
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   365
    unsigned int bits, bits13;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   366
    int shift, outCount, nBitsLess13;
48194c26a46c Initial revision
claus
parents:
diff changeset
   367
    int outBitOffset;
48194c26a46c Initial revision
claus
parents:
diff changeset
   368
    int nLeft, t;
48194c26a46c Initial revision
claus
parents:
diff changeset
   369
8107
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   370
    if (! whiteCountTable) {
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   371
	initCCITTTables();
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   372
	if (! whiteCountTable) return 0; /* malloc failed */
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   373
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   374
48194c26a46c Initial revision
claus
parents:
diff changeset
   375
    countPtr = whiteCountTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
   376
    shiftPtr = whiteShiftTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
   377
    outCount = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   378
    outBitOffset = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   379
    bits = *from++;
48194c26a46c Initial revision
claus
parents:
diff changeset
   380
    bits = (bits << 8) | *from++;
48194c26a46c Initial revision
claus
parents:
diff changeset
   381
    nBitsLess13 = 3;
8107
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   382
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   383
    for (;;) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   384
	bits13 = (bits >> nBitsLess13) & 0x1FFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   385
	cnt = countPtr[bits13];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   386
	if (cnt < 0) return 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   387
	shift = shiftPtr[bits13];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   388
	outCount += cnt;
8107
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   389
	if (outCount > len) {
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   390
	    fprintf(stderr, "CCITT buffer overrun\n");
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   391
	    return 0;
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
   392
	}
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   393
	if (countPtr == blackCountTable) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   394
	    /* toggle if it was a terminating code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   395
	    if (cnt < 64) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   396
		countPtr = whiteCountTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   397
		shiftPtr = whiteShiftTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   398
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   399
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   400
	    /* draw cnt black bits */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   401
	    if (cnt) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   402
		if (outBitOffset) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   403
		    nLeft = 8 - outBitOffset;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   404
		    if (cnt < nLeft) nLeft = cnt;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   405
		    t = leftBits[nLeft] >> outBitOffset;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   406
		    *to |= t;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   407
		    cnt -= nLeft;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   408
		    outBitOffset += nLeft;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   409
		    if (outBitOffset >= 8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   410
			to++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   411
			outBitOffset -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   412
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   413
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   414
		if (cnt > 256) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   415
		    while ((INT)to & 3) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   416
			*to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   417
			cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   418
		    }
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
   419
#if __POINTER_SIZE__ == 8
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   420
		    while ((INT)to & 7) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   421
			*to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   422
			cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   423
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   424
		    while (cnt >= 64) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   425
			(*(INT *)to) = 0xFFFFFFFFFFFFFFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   426
			to += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   427
			cnt -= 64;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   428
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   429
		    if (cnt >= 32) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   430
			(*(long *)to) = 0xFFFFFFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   431
			to += 4;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   432
			cnt -= 32;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   433
		    }
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
   434
#else
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   435
		    while ((INT)to & 3) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   436
			*to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   437
			cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   438
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   439
		    while (cnt >= 32) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   440
			(*(long *)to) = 0xFFFFFFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   441
			to += 4;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   442
			cnt -= 32;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   443
		    }
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
   444
#endif
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   445
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   446
		while (cnt >= 8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   447
		    *to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   448
		    cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   449
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   450
		*to |= leftBits[cnt];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   451
		outBitOffset += cnt;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   452
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   453
	} else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   454
	    /* toggle if it was a terminating code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   455
	    if (cnt < 64) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   456
		countPtr = blackCountTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   457
		shiftPtr = blackShiftTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   458
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   459
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   460
	    /* skip cnt bits */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   461
	    to += cnt >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   462
	    outBitOffset += cnt & 7;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   463
	    if (outBitOffset >= 8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   464
		to++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   465
		outBitOffset -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   466
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   467
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   468
	if (outCount >= len) return 1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   469
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   470
	nBitsLess13 -= shift;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   471
	while (nBitsLess13 < 0) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   472
	    bits = (bits << 8) | *from++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   473
	    nBitsLess13 += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   474
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   475
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   476
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   477
48194c26a46c Initial revision
claus
parents:
diff changeset
   478
/*
48194c26a46c Initial revision
claus
parents:
diff changeset
   479
 * LZW decompression
48194c26a46c Initial revision
claus
parents:
diff changeset
   480
 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   481
struct buffer {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   482
	struct buffer *prev;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   483
	unsigned char chars[8192 - 4];
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   484
};
189
claus
parents: 153
diff changeset
   485
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   486
static int
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   487
__decodeLZW__(unsigned char *from, unsigned char *to, int inCount, int fromSize, int toSize)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   488
{
48194c26a46c Initial revision
claus
parents:
diff changeset
   489
    register unsigned code;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   490
    unsigned char **strings;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   491
    short *stringLen;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   492
    struct buffer *scratchBuffer;
48194c26a46c Initial revision
claus
parents:
diff changeset
   493
    struct buffer *newBuffer;
48194c26a46c Initial revision
claus
parents:
diff changeset
   494
    unsigned char *scratchPtr;
48194c26a46c Initial revision
claus
parents:
diff changeset
   495
    int nScratch;
1262
61bbba463582 lzw_decode caused a SIGSEGV.
Stefan Vogel <sv@exept.de>
parents: 1175
diff changeset
   496
    unsigned nextCode;
61bbba463582 lzw_decode caused a SIGSEGV.
Stefan Vogel <sv@exept.de>
parents: 1175
diff changeset
   497
    int oldCode = -1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   498
    register unsigned bits;
48194c26a46c Initial revision
claus
parents:
diff changeset
   499
    int nBits, mask, shift;
48194c26a46c Initial revision
claus
parents:
diff changeset
   500
    int i;
48194c26a46c Initial revision
claus
parents:
diff changeset
   501
    int len;
48194c26a46c Initial revision
claus
parents:
diff changeset
   502
    int codeLen = 9;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   503
    unsigned char *fromEnd, *toEnd;
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
   504
    int ret = 1;        /* return success */
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   505
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   506
    fromEnd = from + fromSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   507
    toEnd = to + toSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   508
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   509
    scratchBuffer = (struct buffer *)malloc(sizeof(struct buffer));
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   510
    if (! scratchBuffer) return 0;
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   511
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   512
    strings = (unsigned char **)malloc(sizeof(unsigned char *) * 4096);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   513
    if (! strings) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   514
	free(scratchBuffer);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   515
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   516
    }
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   517
    stringLen = (short *)malloc(sizeof(short) * 4096);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   518
    if (! stringLen) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   519
	free(strings);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   520
	free(scratchBuffer);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   521
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   522
    }
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   523
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   524
    scratchBuffer->prev = (struct buffer *)0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   525
    scratchPtr = scratchBuffer->chars;
48194c26a46c Initial revision
claus
parents:
diff changeset
   526
    nScratch = sizeof(scratchBuffer->chars);
48194c26a46c Initial revision
claus
parents:
diff changeset
   527
48194c26a46c Initial revision
claus
parents:
diff changeset
   528
    for (i = 0; i < 256; i++) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   529
	*scratchPtr = i;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   530
	strings[i] = scratchPtr++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   531
	stringLen[i] = 1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   532
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   533
48194c26a46c Initial revision
claus
parents:
diff changeset
   534
    nextCode = 258;
48194c26a46c Initial revision
claus
parents:
diff changeset
   535
    nScratch -= 256;
48194c26a46c Initial revision
claus
parents:
diff changeset
   536
    mask = 0x1FF;
48194c26a46c Initial revision
claus
parents:
diff changeset
   537
    nBits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   538
    bits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   539
    while (inCount) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   540
	/* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   541
	while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   542
	    bits = (bits<<8) | *from++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   543
	    inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   544
	    nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   545
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   546
	shift = nBits - codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   547
	code = (bits >> shift) & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   548
	bits &= ~(mask << shift);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   549
	nBits -= codeLen;
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   550
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   551
	if (code == 257) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   552
	if (code == 256) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   553
	    if (! inCount)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   554
		break;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   555
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   556
	    /* free stuff */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   557
	    while (scratchBuffer->prev) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   558
		newBuffer = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   559
		scratchBuffer = scratchBuffer->prev;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   560
		free(newBuffer);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   561
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   562
	    /* reset everything */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   563
	    scratchPtr = scratchBuffer->chars + 256;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   564
	    nScratch = sizeof(scratchBuffer->chars) - 256;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   565
	    codeLen = 9;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   566
	    nextCode = 258;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   567
	    mask = 0x1FF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   568
	    /* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   569
	    while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   570
		bits = (bits<<8) | *from++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   571
		inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   572
		nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   573
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   574
	    shift = nBits - codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   575
	    code = (bits >> shift) & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   576
	    bits &= ~(mask << shift);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   577
	    nBits -= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   578
	    if (code == 257) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   579
	    /* add to output */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   580
	    if (to >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   581
		if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   582
		    console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   583
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   584
		ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   585
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   586
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   587
	    *to++ = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   588
	    oldCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   589
	} else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   590
	    if (code < nextCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   591
		/* writeString(string[code]) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   592
		len = stringLen[code];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   593
		bcopy(strings[code], to, len);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   594
		to += len;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   595
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   596
		if (oldCode != -1) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   597
		    /* add( string[oldcode] + first(string[code]) ) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   598
		    len = stringLen[oldCode] + 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   599
		    if (nScratch < len) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   600
			newBuffer = (struct buffer *)malloc(sizeof(struct buffer));
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   601
			if (! newBuffer) goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   602
			newBuffer->prev = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   603
			scratchBuffer = newBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   604
			scratchPtr = scratchBuffer->chars;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   605
			nScratch = sizeof(scratchBuffer->chars);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   606
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   607
		    stringLen[nextCode] = len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   608
		    strings[nextCode] = scratchPtr;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   609
		    bcopy(strings[oldCode], scratchPtr, len-1);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   610
		    scratchPtr += len-1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   611
		    *scratchPtr++ = strings[code][0];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   612
		    nScratch -= len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   613
		    nextCode++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   614
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   615
	    } else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   616
		if (oldCode == -1) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   617
		    /* bad input */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   618
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   619
		    goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   620
		}
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   621
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   622
		/* writeString(string[oldCode] + first(string[oldCode]) ) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   623
		len = stringLen[oldCode];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   624
		if ((to+len) >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   625
		    if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   626
			console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   627
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   628
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   629
		    goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   630
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   631
		bcopy(strings[oldCode], to, len);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   632
		to += len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   633
		*to++ = strings[oldCode][0];
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   634
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   635
		/* add( string[oldcode] + first(string[oldCode]) ) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   636
		len++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   637
		if (nScratch < len) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   638
		    newBuffer = (struct buffer *)malloc(sizeof(struct buffer));
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   639
		    if (! newBuffer) goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   640
		    newBuffer->prev = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   641
		    scratchBuffer = newBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   642
		    scratchPtr = scratchBuffer->chars;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   643
		    nScratch = sizeof(scratchBuffer->chars);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   644
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   645
		stringLen[nextCode] = len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   646
		strings[nextCode] = scratchPtr;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   647
		bcopy(strings[oldCode], scratchPtr, len-1);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   648
		scratchPtr += len-1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   649
		*scratchPtr++ = strings[oldCode][0];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   650
		nScratch -= len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   651
		nextCode++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   652
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   653
	    oldCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   654
	    if (nextCode >= 511) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   655
		if (nextCode == 511) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   656
		    codeLen = 10;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   657
		    mask = 0x3FF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   658
		} else if (nextCode >= 1023) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   659
		    if (nextCode == 1023) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   660
			codeLen = 11;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   661
			mask = 0x7FF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   662
		    } else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   663
			if (nextCode == 2047) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   664
			    codeLen = 12;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   665
			    mask = 0xFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   666
			}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   667
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   668
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   669
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   670
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   671
    }
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   672
out: ;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   673
    /* free stuff */
48194c26a46c Initial revision
claus
parents:
diff changeset
   674
    while (scratchBuffer) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   675
	newBuffer = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   676
	scratchBuffer = scratchBuffer->prev;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   677
	free(newBuffer);
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   678
    }
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   679
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   680
    free(strings);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   681
    free(stringLen);
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   682
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   683
    if (from > fromEnd) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   684
	if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   685
	    console_fprintf(stderr, "ImageReader [warning]: LZW inBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   686
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   687
	ret = 0;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   688
    }
1262
61bbba463582 lzw_decode caused a SIGSEGV.
Stefan Vogel <sv@exept.de>
parents: 1175
diff changeset
   689
    return ret;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   690
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   691
48194c26a46c Initial revision
claus
parents:
diff changeset
   692
/*
48194c26a46c Initial revision
claus
parents:
diff changeset
   693
 * delta decoding (TIFF predictor = 2)
48194c26a46c Initial revision
claus
parents:
diff changeset
   694
 */
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   695
static void
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   696
__decodeDelta3__(register unsigned char *bytes, int width, int height)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   697
{
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   698
	register int w;
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   699
	unsigned char r, g, b;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   700
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   701
	while (height--) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   702
	    r = g = b = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   703
	    for (w = width; w; w--) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   704
		r += *bytes;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   705
		*bytes++ = r;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   706
		g += *bytes;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   707
		*bytes++ = g;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   708
		b += *bytes;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   709
		*bytes++ = b;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   710
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   711
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   712
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   713
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   714
/*
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   715
 * delta decoding (TIFF predictor = 2)
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   716
 */
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   717
static void
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   718
__decodeDelta4__(register unsigned char *bytes, int width, int height)
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   719
{
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   720
	register int w;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   721
	unsigned char r, g, b, a;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   722
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   723
	while (height--) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   724
	    r = g = b = a = 0;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   725
	    for (w = width; w; w--) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   726
		r += *bytes;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   727
		*bytes++ = r;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   728
		g += *bytes;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   729
		*bytes++ = g;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   730
		b += *bytes;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   731
		*bytes++ = b;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   732
		a += *bytes;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   733
		*bytes++ = a;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   734
	    }
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   735
	}
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   736
}
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   737
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
   738
/*
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   739
 * GIF decompression
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   740
 */
189
claus
parents: 153
diff changeset
   741
static int
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   742
__decodeGIF__(unsigned char *from, unsigned char *to, int inCount, int initialCodeLen, int fromSize, int toSize)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   743
{
48194c26a46c Initial revision
claus
parents:
diff changeset
   744
    register unsigned code;
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   745
    // #define GIF_PREFIX_SUFFIX_SIZE 4096
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   746
    #define GIF_PREFIX_SUFFIX_SIZE (4096*2)
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   747
    unsigned short *prefix;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   748
    unsigned short *suffix;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   749
    unsigned short *outCode;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   750
    int outCount;
48194c26a46c Initial revision
claus
parents:
diff changeset
   751
    unsigned maxCode, oldCode, fin, inCode, curCode;
48194c26a46c Initial revision
claus
parents:
diff changeset
   752
    register unsigned bits;
48194c26a46c Initial revision
claus
parents:
diff changeset
   753
    register int nBits, mask, shift;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   754
    int ret = 1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   755
    int i;
48194c26a46c Initial revision
claus
parents:
diff changeset
   756
    int len;
48194c26a46c Initial revision
claus
parents:
diff changeset
   757
    int endCode, clearCode, freeCode;
48194c26a46c Initial revision
claus
parents:
diff changeset
   758
    int codeLen = initialCodeLen;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   759
    unsigned char *fromEnd, *toEnd;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   760
    static int ranges[] = {0, 1, 2, 4, 8, 16, 32, 64,
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   761
			   128, 256, 512, 1024, 2048 };
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   762
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   763
    fromEnd = from + fromSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   764
    toEnd = to + toSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   765
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
   766
    if ((unsigned)codeLen > 12) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   767
	if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   768
	    console_fprintf(stderr, "ImageReader [warning]: GIF bad codelen (>12)\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   769
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   770
	return 0;
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
   771
    }
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   772
    prefix = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   773
    if (! prefix) return 0;
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   774
    suffix  = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   775
    if (! suffix) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   776
	free(prefix);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   777
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   778
    }
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   779
    outCode = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   780
    if (! outCode) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   781
	free(prefix);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   782
	free(suffix);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   783
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   784
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   785
    clearCode = ranges[codeLen]; /* 256 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   786
    endCode = clearCode + 1;     /* 257 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   787
    freeCode = clearCode + 2;    /* 258 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   788
    maxCode = clearCode << 1;    /* 512 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   789
    outCount = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   790
48194c26a46c Initial revision
claus
parents:
diff changeset
   791
    mask = maxCode - 1;          /* 1FF */
48194c26a46c Initial revision
claus
parents:
diff changeset
   792
    nBits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   793
    bits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   794
    while (inCount) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   795
	/* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   796
	while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   797
	    bits = bits | (*from++ << nBits);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   798
	    inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   799
	    nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   800
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   801
	if (inCount <= 0)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   802
	    break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   803
	code = bits & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   804
	bits >>= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   805
	nBits -= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   806
	if (code == endCode) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   807
	if (code == clearCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   808
	    if (inCount <= 0)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   809
		break;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   810
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   811
	    codeLen = initialCodeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   812
	    maxCode = clearCode<<1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   813
	    mask = maxCode - 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   814
	    freeCode = clearCode + 2;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   815
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   816
	    /* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   817
	    while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   818
		bits = bits | (*from++ << nBits);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   819
		inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   820
		nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   821
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   822
	    if (inCount <= 0)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   823
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   824
	    code = bits & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   825
	    bits >>= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   826
	    nBits -= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   827
	    if (code == endCode) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   828
	    /* add to output */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   829
	    if (to >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   830
		if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   831
		    console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   832
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   833
		ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   834
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   835
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   836
	    *to++ = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   837
	    oldCode = fin = curCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   838
	} else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   839
	    curCode = inCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   840
	    if (curCode >= freeCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   841
		curCode = oldCode;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   842
		outCode[outCount++] = fin;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   843
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   844
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   845
	    while (curCode >= clearCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   846
		if (outCount > 1024) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   847
		    goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   848
		}
2261
740be162343e check to avoid overwriting
Claus Gittinger <cg@exept.de>
parents: 2152
diff changeset
   849
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   850
		/* debugging and protecting myself from overwrites */
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   851
		if (curCode > (GIF_PREFIX_SUFFIX_SIZE-1)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   852
		    if (@global(InfoPrinting) == true) {
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   853
			console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (code > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1));
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   854
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   855
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   856
		    break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   857
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   858
		outCode[outCount++] = suffix[curCode];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   859
		curCode = prefix[curCode];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   860
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   861
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   862
	    fin = curCode;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   863
	    outCode[outCount++] = fin;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   864
2014
bcae1c2c32e4 fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents: 1988
diff changeset
   865
#if 0
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   866
	    if ((to+outCount) >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   867
		if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   868
		    console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   869
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   870
		ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   871
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   872
	    }
2014
bcae1c2c32e4 fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents: 1988
diff changeset
   873
#endif
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   874
	    for (i = outCount - 1; i >= 0; i--) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   875
		if (to >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   876
		    if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   877
			console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   878
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   879
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   880
		    break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   881
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   882
		*to++ = outCode[i];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   883
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   884
	    outCount = 0;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   885
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   886
	    /* debugging and protecting myself from overwrites */
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   887
	    if (freeCode > (GIF_PREFIX_SUFFIX_SIZE-1)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   888
		if (@global(InfoPrinting) == true) {
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   889
		    console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (freeCode > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1));
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   890
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   891
		ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   892
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   893
	    }
2261
740be162343e check to avoid overwriting
Claus Gittinger <cg@exept.de>
parents: 2152
diff changeset
   894
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   895
	    prefix[freeCode] = oldCode;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   896
	    suffix[freeCode] = fin;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   897
	    oldCode = inCode;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   898
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   899
	    freeCode++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   900
	    if (freeCode >= maxCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   901
		if (codeLen < 12) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   902
		    codeLen++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   903
		    maxCode *= 2;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   904
		    mask = (1 << codeLen) - 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   905
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   906
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   907
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   908
    }
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   909
out: ;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   910
    free(prefix);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   911
    free(suffix);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   912
    free(outCode);
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   913
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   914
    if (from > fromEnd) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   915
	if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   916
	    console_fprintf(stderr, "ImageReader [warning]: GIF inBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   917
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   918
	ret = 0;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   919
    }
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   920
    return ret;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   921
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   922
48194c26a46c Initial revision
claus
parents:
diff changeset
   923
%}
77
da4678fae5c8 *** empty log message ***
claus
parents: 72
diff changeset
   924
! !
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   925
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   926
!ImageReader class methodsFor:'documentation'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   927
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   928
copyright
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   929
"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   930
 COPYRIGHT (c) 1991 by Claus Gittinger
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   931
	      All Rights Reserved
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   932
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   933
 This software is furnished under a license and may be used
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   934
 only in accordance with the terms of that license and with the
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   935
 inclusion of the above copyright notice.   This software may not
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   936
 be provided or otherwise made available to, or used by, any
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   937
 other person.  No title to or ownership of the software is
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   938
 hereby transferred.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   939
"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   940
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   941
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   942
documentation
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   943
"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   944
    Abstract class to provide common functions for image-readers/writers.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   945
    (i.e. TIFFReader, GIFReader etc.).
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   946
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   947
    In contrast to what the name suggests, ImageReaders are supposed to support
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   948
    both reading and writing of images
6058
7c5c40861f50 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6057
diff changeset
   949
    (i.e. the name is somewhat outdated, but kept for historic and backward
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   950
    compatibility reasons).
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   951
    They provide functionality similar to Squeak's ImageReaderWriter classes.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   952
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   953
    ImageReaders are created temporary to read an image from a stream.
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   954
    Normally, they are not directly used - instead, the image class is
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   955
    asked to read some file, and return an instance for it:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   956
	Image fromFile:<someFileName>
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   957
    The Image class will guess the image's format and forward the task to
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   958
    some concrete ImageReaderClass.
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   959
    If that class thinks, that the file's format is incorrect,
6508
589f02f1a068 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6377
diff changeset
   960
    other readers are tried until some reader class finds the file's format acceptable.
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   961
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   962
    Image readers read the stream and collect all relevant information internally.
118
25e775072a89 *** empty log message ***
claus
parents: 105
diff changeset
   963
    Once done with reading, the actual image object is created and
25e775072a89 *** empty log message ***
claus
parents: 105
diff changeset
   964
    data filled in from the imageReaders collected info.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   965
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   966
    See the implementation of #fromStream: in concrete subclasses.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   967
    The public interfaces are:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   968
	 <ConcreteReaderClass> fromFile:aFilename
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   969
    or:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   970
	 <ConcreteReaderClass> fromStream:aStream
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   971
6058
7c5c40861f50 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6057
diff changeset
   972
    If you add a new reader, don't forget to add the method #isValidImageFile:
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   973
    which should return true, if this reader supports reading a given file.
6058
7c5c40861f50 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6057
diff changeset
   974
7c5c40861f50 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6057
diff changeset
   975
    If your new reader class supports writing files, don't forget to add
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   976
    #canRepresent:anImage and return true from this method.
593
a3264954cf83 commentary
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   977
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   978
    writing:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   979
	tell the image, to save itself, via <image> saveOn:fileName
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   980
	or <image> saveOn:fileName using:<readerClass>
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   981
593
a3264954cf83 commentary
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   982
    [See also:]
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   983
	Image Icon Form
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   984
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   985
    [author:]
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   986
	Claus Gittinger
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   987
"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   988
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   989
1358
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   990
!ImageReader class methodsFor:'instance creation'!
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   991
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   992
new
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   993
    ^ self basicNew initialize
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   994
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   995
    "Created: 18.2.1997 / 17:08:45 / cg"
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   996
! !
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   997
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   998
!ImageReader class methodsFor:'cleanup'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   999
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1000
lowSpaceCleanup
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1001
    "cleanup things we do not need"
118
25e775072a89 *** empty log message ***
claus
parents: 105
diff changeset
  1002
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1003
    ReverseBits := nil
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1004
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1005
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1006
!ImageReader class methodsFor:'constants'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1007
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1008
reverseBits
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1009
    "return a table filled with bit reverse information.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1010
     To convert from msbit-first to lsbit-first bytes, use
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1011
     the value as index into the table, retrieving the reverse
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1012
     value. Since indexing must start at 1, use (value + 1) as
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1013
     index."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1014
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1015
    |val "{ Class: SmallInteger }" |
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1016
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1017
    ReverseBits isNil ifTrue:[
153
claus
parents: 134
diff changeset
  1018
	ReverseBits := ByteArray uninitializedNew:256.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1019
	0 to:255 do:[:i |
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1020
	    val := 0.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1021
	    (i bitTest:16r01) ifTrue:[val := val bitOr:16r80].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1022
	    (i bitTest:16r02) ifTrue:[val := val bitOr:16r40].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1023
	    (i bitTest:16r04) ifTrue:[val := val bitOr:16r20].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1024
	    (i bitTest:16r08) ifTrue:[val := val bitOr:16r10].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1025
	    (i bitTest:16r10) ifTrue:[val := val bitOr:16r08].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1026
	    (i bitTest:16r20) ifTrue:[val := val bitOr:16r04].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1027
	    (i bitTest:16r40) ifTrue:[val := val bitOr:16r02].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1028
	    (i bitTest:16r80) ifTrue:[val := val bitOr:16r01].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1029
	    ReverseBits at:(i + 1) put:val
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1030
	]
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1031
    ].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1032
    ^ ReverseBits
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1033
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1034
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1035
!ImageReader class methodsFor:'decompression support'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1036
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1037
_decompressCCITT3From:src count:inCount into:dst startingAt:dstIndexIn 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1038
    |srcIndex dstIndex countTable shiftTable 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1039
     outCount outBitOffset bits nBitsLess13 bits13 cnt shift
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1040
     nLeft t leftBits|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1041
    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1042
    WhiteCountTable isNil ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1043
        self initCCITTTables.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1044
    ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1045
    countTable := WhiteCountTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1046
    shiftTable := WhiteShiftTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1047
    leftBits := #[ 0 16r80 16rC0 16rE0 16rF0 16rF8 16rFC 16rFE 16rFF ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1048
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1049
    srcIndex := 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1050
    dstIndex := dstIndexIn.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1051
    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1052
    outCount := 0.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1053
    outBitOffset := 0.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1054
    bits := ((src at:srcIndex) bitShift:8) bitOr:(src at:srcIndex+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1055
    srcIndex := srcIndex + 2.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1056
    nBitsLess13 := 3.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1057
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1058
    [
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1059
        bits13 := (bits rightShift: nBitsLess13) bitAnd: 16r1FFF.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1060
        cnt := countTable at:(bits13+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1061
        cnt < 0 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1062
            ^ dstIndex
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1063
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1064
        shift := shiftTable at:(bits13+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1065
        outCount := outCount + cnt.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1066
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1067
        countTable == BlackCountTable ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1068
            "/ toggle if it was a terminating code
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1069
            cnt < 64 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1070
                countTable := WhiteCountTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1071
                shiftTable := WhiteShiftTable
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1072
            ].    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1073
            "/ draw cnt black bits 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1074
            cnt ~~ 0 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1075
                outBitOffset > 0 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1076
                    nLeft := 8 - outBitOffset.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1077
                    (cnt < nLeft) ifTrue:[ nLeft := cnt ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1078
                    t := (leftBits at:(nLeft+1)) rightShift: outBitOffset.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1079
                    dst at:dstIndex put: ((dst at:dstIndex) bitOr:(t bitAnd:16rFF)).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1080
                    cnt := cnt - nLeft.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1081
                    outBitOffset := outBitOffset + nLeft.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1082
                    (outBitOffset >= 8) ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1083
                        dstIndex := dstIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1084
                        outBitOffset := outBitOffset - 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1085
                    ]
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1086
                ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1087
                [ cnt >= 8 ] whileTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1088
                    dst at:dstIndex put:16rFF.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1089
                    dstIndex := dstIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1090
                    cnt := cnt - 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1091
                ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1092
                dst at:dstIndex put:((dst at:dstIndex) bitOr:(leftBits at:(cnt+1))).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1093
                outBitOffset := outBitOffset + cnt.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1094
            ]
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1095
        ] ifFalse:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1096
            "/ toggle if it was a terminating code
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1097
            cnt < 64 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1098
                countTable := BlackCountTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1099
                shiftTable := BlackShiftTable
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1100
            ].    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1101
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1102
            "/ skip cnt bits
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1103
            dstIndex := dstIndex + (cnt rightShift: 3).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1104
            outBitOffset := outBitOffset + (cnt bitAnd: 7).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1105
            (outBitOffset >= 8)  ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1106
                dstIndex := dstIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1107
                outBitOffset := outBitOffset - 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1108
            ]
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1109
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1110
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1111
        nBitsLess13 := nBitsLess13 - shift.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1112
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1113
        "/ fill bits from the input
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1114
        [ nBitsLess13 < 0 ] whileTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1115
            srcIndex > inCount ifTrue:[^ 1].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1116
            
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1117
            bits := (bits bitShift:8) bitOr:( src at:srcIndex ).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1118
            srcIndex := srcIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1119
            nBitsLess13 := nBitsLess13 + 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1120
        ].        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1121
    ] loop.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1122
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1123
    "Created: / 25-08-2017 / 13:34:29 / cg"
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1124
    "Modified: / 26-08-2017 / 18:12:15 / cg"
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1125
!
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1126
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1127
_decompressCCITT3From:src count:inCount into:dst startingAt:dstIndexIn count:len
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1128
    |srcIndex dstIndex countTable shiftTable 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1129
     outCount outBitOffset bits nBitsLess13 bits13 cnt shift
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1130
     nLeft t leftBits|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1131
    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1132
    WhiteCountTable isNil ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1133
        self initCCITTTables.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1134
    ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1135
    countTable := WhiteCountTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1136
    shiftTable := WhiteShiftTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1137
    leftBits := #[ 0 16r80 16rC0 16rE0 16rF0 16rF8 16rFC 16rFE 16rFF ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1138
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1139
    srcIndex := 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1140
    dstIndex := dstIndexIn.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1141
    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1142
    outCount := 0.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1143
    outBitOffset := 0.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1144
    bits := ((src at:srcIndex) bitShift:8) bitOr:(src at:srcIndex+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1145
    srcIndex := srcIndex + 2.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1146
    nBitsLess13 := 3.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1147
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1148
    [
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1149
        bits13 := (bits rightShift: nBitsLess13) bitAnd: 16r1FFF.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1150
        cnt := countTable at:(bits13+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1151
        cnt < 0 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1152
            ^ 1
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1153
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1154
        shift := shiftTable at:(bits13+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1155
        outCount := outCount + cnt.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1156
        outCount > len ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1157
            self error:'out buffer overflow'.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1158
            ^ 0
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1159
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1160
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1161
        countTable == BlackCountTable ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1162
            "/ toggle if it was a terminating code
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1163
            cnt < 64 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1164
                countTable := WhiteCountTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1165
                shiftTable := WhiteShiftTable
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1166
            ].    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1167
            "/ draw cnt black bits 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1168
            cnt > 0 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1169
                outBitOffset > 0 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1170
                    nLeft := 8 - outBitOffset.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1171
                    (cnt < nLeft) ifTrue:[ nLeft := cnt ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1172
                    t := (leftBits at:(nLeft+1)) rightShift: outBitOffset.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1173
                    dst at:dstIndex put: ((dst at:dstIndex) bitOr:(t bitAnd:16rFF)).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1174
                    cnt := cnt - nLeft.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1175
                    outBitOffset := outBitOffset + nLeft.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1176
                    (outBitOffset >= 8) ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1177
                        dstIndex := dstIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1178
                        outBitOffset := outBitOffset - 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1179
                    ]
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1180
                ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1181
                [ cnt >= 8 ] whileTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1182
                    dst at:dstIndex put:16rFF.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1183
                    dstIndex := dstIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1184
                    cnt := cnt - 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1185
                ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1186
                dst at:dstIndex put:((dst at:dstIndex) bitOr:(leftBits at:(cnt+1))).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1187
                outBitOffset := outBitOffset + cnt.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1188
            ]
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1189
        ] ifFalse:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1190
            "/ toggle if it was a terminating code
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1191
            cnt < 64 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1192
                countTable := BlackCountTable.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1193
                shiftTable := BlackShiftTable
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1194
            ].    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1195
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1196
            "/ skip cnt bits
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1197
            dstIndex := dstIndex + (cnt rightShift: 3).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1198
            outBitOffset := outBitOffset + (cnt bitAnd: 7).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1199
            (outBitOffset >= 8)  ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1200
                dstIndex := dstIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1201
                outBitOffset := outBitOffset - 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1202
            ]
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1203
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1204
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1205
        outCount >= len ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1206
            ^ 1
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1207
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1208
        nBitsLess13 := nBitsLess13 - shift.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1209
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1210
        "/ fill bits from the input
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1211
        [ nBitsLess13 < 0 ] whileTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1212
            bits := (bits bitShift:8) bitOr:( src at:srcIndex ).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1213
            srcIndex := srcIndex + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1214
            nBitsLess13 := nBitsLess13 + 8.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1215
        ].        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1216
    ] loop.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1217
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1218
    "
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1219
     |bytes outBytes|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1220
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1221
     bytes := '/Users/cg/DownloadsUnsaved/images/software/libtiffpic/g3test.g3'
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1222
                asFilename binaryContentsOfEntireFile.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1223
     outBytes := ByteArray new:100000.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1224
     ImageReader 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1225
        _decompressCCITT3From:bytes
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1226
        count:bytes size    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1227
        into:outBytes
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1228
        startingAt:1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1229
    "
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1230
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1231
    "Created: / 26-08-2017 / 14:16:54 / cg"
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1232
!
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1233
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1234
decodeDelta:step in:data width:width height:height
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1235
    "perform TIFF predictor = 2 delta decoding inplace on data.
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1236
     Calls primitive c function for speed"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1237
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1238
    |idx values ov nv|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1239
    
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1240
    (step == 3) ifTrue:[
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1241
%{
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1242
        if (__isByteArray(data)
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1243
         && __bothSmallInteger(width, height)) {
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1244
            __decodeDelta3__(__ByteArrayInstPtr(data)->ba_element,
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1245
                             __intVal(width), __intVal(height));
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1246
            RETURN ( self );
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1247
        }
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1248
%}.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1249
    ].
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1250
    (step == 4) ifTrue:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1251
%{
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1252
        if (__isByteArray(data)
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1253
         && __bothSmallInteger(width, height)) {
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1254
            __decodeDelta4__(__ByteArrayInstPtr(data)->ba_element,
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1255
                             __intVal(width), __intVal(height));
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1256
            RETURN ( self );
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1257
        }
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1258
%}.
8102
e60aac8eccb9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8101
diff changeset
  1259
    ].
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1260
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1261
    "/ slow fallback
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1262
    idx := 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1263
    1 to:height do:[:y |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1264
        values := Array new:step withAll:0.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1265
        1 to:width do:[:x |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1266
            1 to:step do:[:chNr |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1267
                ov := (values at:chNr).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1268
                nv := (ov + (data at:idx)) bitAnd:16rFF.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1269
                values at:chNr put:nv.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1270
                data at:idx put:nv.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1271
                idx := idx + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1272
            ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1273
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1274
    ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1275
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1276
    "Modified: / 27-08-2017 / 16:52:37 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1277
!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1278
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1279
decompressCCITT3From:srcBytes into:dstBytes startingAt:offset count:count
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1280
    "decompress CCITT Group 3 compressed image data.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1281
     count bytes from srcBytes are decompressed into dstBytes.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1282
     Calls primitive c function for speed"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1283
%{
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  1284
    if (__isByteArrayLike(srcBytes)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1285
     && __isByteArray(dstBytes)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1286
     && __bothSmallInteger(offset, count)) {
8107
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
  1287
	int _count = __intVal(count);
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
  1288
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
  1289
	if (_count > __byteArraySize(dstBytes)) {
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
  1290
	    _count = __byteArraySize(dstBytes);
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
  1291
	}
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1292
	if (__decodeCCITTgroup3__(__ByteArrayInstPtr(srcBytes)->ba_element,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1293
				  __ByteArrayInstPtr(dstBytes)->ba_element
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1294
				  + __intVal(offset) - 1,
8107
154acb64bf45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8102
diff changeset
  1295
				  _count)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1296
	    RETURN ( self );
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1297
	}
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1298
    }
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1299
%}
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1300
.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1301
    self primitiveFailed
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1302
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1303
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1304
decompressGIFFrom:srcBytes count:count into:dstBytes startingAt:offset codeLen:codeLen
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1305
    "decompress GIF compressed image data.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1306
     count bytes from srcBytes are decompressed into dstBytes.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1307
     Calls primitive c function for speed"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1308
%{
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  1309
    if (__isByteArrayLike(srcBytes)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1310
     && __isByteArray(dstBytes)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1311
     && __bothSmallInteger(codeLen, offset)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1312
     && __isSmallInteger(count)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1313
	if (__decodeGIF__(__ByteArrayInstPtr(srcBytes)->ba_element,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1314
			  __ByteArrayInstPtr(dstBytes)->ba_element
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1315
						+__intVal(offset) - 1,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1316
			  __intVal(count),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1317
			  __intVal(codeLen),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1318
			  __byteArraySize(srcBytes),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1319
			  __byteArraySize(dstBytes)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1320
			 )) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1321
	    RETURN ( self );
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1322
	}
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1323
    }
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1324
%}
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1325
.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1326
    self primitiveFailed
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1327
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1328
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1329
decompressLZWFrom:srcBytes count:count into:dstBytes startingAt:offset
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1330
    "decompress LZW (tiff) compressed image data.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1331
     count bytes from srcBytes are decompressed into dstBytes.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1332
     Calls primitive c function for speed"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1333
%{
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  1334
    if (__isByteArrayLike(srcBytes)
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1335
     && __isByteArray(dstBytes)
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1336
     && __bothSmallInteger(offset, count)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1337
	if (__decodeLZW__(__ByteArrayInstPtr(srcBytes)->ba_element,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1338
			  __ByteArrayInstPtr(dstBytes)->ba_element
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1339
					      + __intVal(offset) - 1,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1340
			  __intVal(count),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1341
			  __byteArraySize(srcBytes),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1342
			  __byteArraySize(dstBytes)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1343
			)) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1344
	    RETURN ( self );
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1345
	}
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1346
    }
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1347
%}
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1348
.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1349
    self primitiveFailed
189
claus
parents: 153
diff changeset
  1350
!
claus
parents: 153
diff changeset
  1351
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1352
decompressPackBits:nIn from:srcBytes to:dstBytes startingAt:dstOffset
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1353
    "decompress a number of input bytes.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1354
     Used by tiff and some mac image formats.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1355
     Return the number of decompressed output bytes."
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1356
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1357
    |i b n v dstOffs|
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1358
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1359
    dstOffs := dstOffset.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1360
    i := 1.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1361
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1362
    [i <= nIn] whileTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1363
	b := srcBytes at:i.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1364
	i := i + 1.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1365
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1366
	b ~~ 16rFF ifTrue:[   "/ not a NOP
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1367
	    b <= 127 ifTrue:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1368
		"/ 0..127 literal bytes
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1369
		n := b + 1.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1370
		dstBytes replaceFrom:dstOffs to:dstOffs+n-1 with:srcBytes startingAt:i.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1371
		i := i + n.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1372
	    ] ifFalse:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1373
		"/ 128..254 a run
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1374
		n := b - 125.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1375
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1376
		v := srcBytes at:i.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1377
		i := i + 1.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1378
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1379
		dstBytes from:dstOffs to:dstOffs+n put:v.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1380
	    ].
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1381
	    dstOffs := dstOffs + n.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1382
	]
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1383
    ].
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1384
    ^ dstOffs - dstOffset
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1385
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1386
    "Created: / 1.12.1997 / 18:39:23 / cg"
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1387
    "Modified: / 1.12.1997 / 18:49:58 / cg"
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1388
!
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1389
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1390
decompressPackBitsV2From:srcBytes at:srcStart to:dstBytes at:dstStart count:outCount
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1391
    "decompress until a number of output bytes has been decompressed.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1392
     Used by some mac image formats.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1393
     Return the number of processed input bytes.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1394
     This does NOT treat FF as a noop."
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1395
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1396
    |i b n v dstOffs nRemaining|
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1397
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1398
    dstOffs := dstStart.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1399
    i := srcStart.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1400
    nRemaining := outCount.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1401
    [nRemaining > 0] whileTrue:[
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1402
	b := srcBytes at:i.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1403
	i := i + 1.
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1404
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1405
	"/ mhmh - other packbits decoders seem to treat FF as a noop
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1406
	"/ here, we do not.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1407
	true "b ~~ 16rFF" ifTrue:[   "/ not a NOP
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1408
	    b <= 127 ifTrue:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1409
		"/ 0..127: 1..128 literal bytes
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1410
		n := b + 1.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1411
		dstBytes replaceFrom:dstOffs to:dstOffs+b with:srcBytes startingAt:i.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1412
		nRemaining := nRemaining - n.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1413
		i := i + n.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1414
	    ] ifFalse:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1415
		"/ 128..255 a run of length 3..130
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1416
		n := b - 125.
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1417
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1418
		v := srcBytes at:i.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1419
		i := i + 1.
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1420
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1421
		dstBytes from:dstOffs to:dstOffs+n-1 put:v.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1422
		nRemaining := nRemaining - n.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1423
	    ].
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1424
	    dstOffs := dstOffs + n.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1425
	] ifFalse:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1426
	    self halt
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  1427
	].
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1428
    ].
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1429
    ^ i-srcStart
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1430
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1431
    "Created: / 22-02-2017 / 12:05:26 / cg"
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1432
!
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1433
1648
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1434
decompressRLEFrom:srcBytes at:srcStartIndex into:dstBytes at:dstStartIndex increment:dstIncrement
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1435
    "common helper to expand RLE encoded data"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1436
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1437
    "/ the code below expands common RLE formats, where the high bit
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1438
    "/ controls how the count in the low 7 bits is to be interpreted:
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1439
    "/ 1 means: count verbatim bytes follow;
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1440
    "/ 0 means: repeat the next byte count times.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1441
    "/ Decoding stops when a 0-count is encountered.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1442
    "/ srcBytes and dstBytes should not overlap.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1443
    "/ dstIncrement controls the stepping in the destination (usually: 1)
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1444
    "/
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1445
    "/ this may be recoded in C in the future
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1446
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1447
    |srcIdx "{Class: SmallInteger }"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1448
     dstIdx "{Class: SmallInteger }"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1449
     pixel  "{Class: SmallInteger }"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1450
     count  "{Class: SmallInteger }"|
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1451
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1452
    srcIdx := srcStartIndex.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1453
    dstIdx := dstStartIndex.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1454
    [true] whileTrue:[
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1455
	pixel := srcBytes at:srcIdx.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1456
	count := pixel bitAnd:16r7F.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1457
	count == 0 ifTrue:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1458
	    ^ self
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1459
	].
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1460
	srcIdx := srcIdx + 1.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1461
	(pixel bitAnd:16r80) == 0 ifTrue:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1462
	    "/ run bytes
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1463
	    pixel := srcBytes at:srcIdx.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1464
	    srcIdx := srcIdx + 1.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1465
	    dstIncrement == 1 ifTrue:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1466
		dstBytes from:dstIdx to:(dstIdx+count-1) put:pixel.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1467
		dstIdx := dstIdx + count.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1468
	    ] ifFalse:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1469
		1 to:count do:[:c |
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1470
		    dstBytes at:dstIdx put:pixel.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1471
		    dstIdx := dstIdx + dstIncrement.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1472
		]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1473
	    ]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1474
	] ifFalse:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1475
	    "/ verbatim bytes
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1476
	    dstIncrement == 1 ifTrue:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1477
		dstBytes replaceFrom:dstIdx to:(dstIdx+count-1) with:srcBytes startingAt:srcIdx.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1478
		srcIdx := srcIdx + count.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1479
		dstIdx := dstIdx + count.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1480
	    ] ifFalse:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1481
		1 to:count do:[:c |
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1482
		    dstBytes at:dstIdx put:(srcBytes at:srcIdx).
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1483
		    srcIdx := srcIdx + 1.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1484
		    dstIdx := dstIdx + dstIncrement.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1485
		]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1486
	    ]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1487
	]
1648
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1488
    ].
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1489
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1490
    "Modified: 23.4.1997 / 18:54:05 / cg"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1491
!
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1492
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1493
decompressTiffPackBitsFrom:srcBytes to:dstBytes at:dstStart count:maxOutCount
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1494
    "decompress all of srcBytes to dstBytes starting at dstStart.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1495
     Used by TIFF image formats.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1496
     This DOES TREAT FF as a noop."
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1497
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1498
    |i b n v dstOffs dstLast end srcSize|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1499
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1500
    dstOffs := dstStart.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1501
    dstLast := (dstStart + maxOutCount - 1) min:(dstBytes size).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1502
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1503
    i := 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1504
    srcSize := srcBytes size.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1505
    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1506
    [i <= srcSize] whileTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1507
        b := srcBytes at:i.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1508
        i := i + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1509
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1510
        "/ treat FF as a noop
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1511
        b ~~ 128 ifTrue:[   "/ not a NOP
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1512
            b <= 127 ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1513
                "/ 0..127: 1..128 literal bytes
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1514
                n := b + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1515
                end := (dstOffs+n-1) min:dstLast.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1516
                dstBytes replaceFrom:dstOffs to:end with:srcBytes startingAt:i.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1517
                i := i + n.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1518
            ] ifFalse:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1519
                n := 1 - (b - 256).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1520
                v := srcBytes at:i.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1521
                i := i + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1522
                end := (dstOffs+n-1) min:dstLast.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1523
                dstBytes from:dstOffs to:end put:v.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1524
            ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1525
            dstOffs := dstOffs + n.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1526
            dstOffs > dstLast ifTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1527
                ^ dstLast-1-dstStart.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1528
            ].    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1529
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1530
    ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1531
    ^ dstOffs-dstStart
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1532
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1533
    "Created: / 26-08-2017 / 17:50:13 / cg"
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1534
    "Modified: / 27-08-2017 / 12:32:17 / cg"
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1535
!
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1536
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1537
initCCITTTables
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1538
    |whiteDef blackDef index value| 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1539
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1540
    whiteDef := #(
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1541
        ( 16r3500 8 ) "/ 0 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1542
        ( 16r1c00 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1543
        ( 16r7000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1544
        ( 16r8000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1545
        ( 16rb000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1546
        ( 16rc000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1547
        ( 16re000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1548
        ( 16rf000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1549
        ( 16r9800 5 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1550
        ( 16rA000 5 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1551
        ( 16r3800 5 ) "/ 10 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1552
        ( 16r4000 5 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1553
        ( 16r2000 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1554
        ( 16r0c00 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1555
        ( 16rd000 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1556
        ( 16rd400 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1557
        ( 16ra800 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1558
        ( 16rac00 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1559
        ( 16r4e00 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1560
        ( 16r1800 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1561
        ( 16r1000 7 ) "/ 20 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1562
        ( 16r2e00 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1563
        ( 16r0600 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1564
        ( 16r0800 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1565
        ( 16r5000 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1566
        ( 16r5600 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1567
        ( 16r2600 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1568
        ( 16r4800 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1569
        ( 16r3000 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1570
        ( 16r0200 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1571
        ( 16r0300 8 ) "/ 30 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1572
        ( 16r1a00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1573
        ( 16r1b00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1574
        ( 16r1200 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1575
        ( 16r1300 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1576
        ( 16r1400 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1577
        ( 16r1500 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1578
        ( 16r1600 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1579
        ( 16r1700 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1580
        ( 16r2800 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1581
        ( 16r2900 8 ) "/ 40 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1582
        ( 16r2a00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1583
        ( 16r2b00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1584
        ( 16r2c00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1585
        ( 16r2d00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1586
        ( 16r0400 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1587
        ( 16r0500 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1588
        ( 16r0a00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1589
        ( 16r0b00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1590
        ( 16r5200 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1591
        ( 16r5300 8 ) "/ 50 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1592
        ( 16r5400 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1593
        ( 16r5500 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1594
        ( 16r2400 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1595
        ( 16r2500 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1596
        ( 16r5800 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1597
        ( 16r5900 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1598
        ( 16r5a00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1599
        ( 16r5b00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1600
        ( 16r4a00 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1601
        ( 16r4b00 8 ) "/ 60 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1602
        ( 16r3200 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1603
        ( 16r3300 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1604
        ( 16r3400 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1605
        "/ ---------------- 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1606
        ( 16rd800 5 ) "/ 64 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1607
        ( 16r9000 5 ) "/ 128 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1608
        ( 16r5c00 6 ) "/ 192 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1609
        ( 16r6e00 7 ) "/ 256 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1610
        ( 16r3600 8 ) "/ 320 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1611
        ( 16r3700 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1612
        ( 16r6400 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1613
        ( 16r6500 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1614
        ( 16r6800 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1615
        ( 16r6700 8 ) "/ 640 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1616
        ( 16r6600 9 ) "/ 704 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1617
        ( 16r6680 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1618
        ( 16r6900 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1619
        ( 16r6980 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1620
        ( 16r6a00 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1621
        ( 16r6a80 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1622
        ( 16r6b00 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1623
        ( 16r6b80 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1624
        ( 16r6c00 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1625
        ( 16r6c80 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1626
        ( 16r6d00 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1627
        ( 16r6d80 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1628
        ( 16r4c00 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1629
        ( 16r4c80 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1630
        ( 16r4d00 9 ) "/ 1600 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1631
        ( 16r6000 6 ) "/ 1664 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1632
        ( 16r4d80 9 ) "/ 1728 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1633
        "/ -------------------------------- 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1634
        ( 16r0100 11 ) "/ 1792 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1635
        ( 16r0180 11 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1636
        ( 16r01a0 11 ) "/ 1920 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1637
        ( 16r0120 12 ) "/ 1984 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1638
        ( 16r0130 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1639
        ( 16r0140 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1640
        ( 16r0150 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1641
        ( 16r0160 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1642
        ( 16r0170 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1643
        ( 16r01c0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1644
        ( 16r01d0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1645
        ( 16r01e0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1646
        ( 16r01f0 12 ) "/ 2560 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1647
        "/ -------------------------------- 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1648
        ( 16r0010 12 ) "/ EOL 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1649
    ).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1650
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1651
    blackDef := #(
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1652
        ( 16r0dc0 10 ) "/ 0 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1653
        ( 16r4000 3 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1654
        ( 16rc000 2 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1655
        ( 16r8000 2 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1656
        ( 16r6000 3 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1657
        ( 16r3000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1658
        ( 16r2000 4 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1659
        ( 16r1800 5 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1660
        ( 16r1400 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1661
        ( 16r1000 6 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1662
        ( 16r0800 7 ) "/ 10 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1663
        ( 16r0a00 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1664
        ( 16r0e00 7 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1665
        ( 16r0400 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1666
        ( 16r0700 8 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1667
        ( 16r0c00 9 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1668
        ( 16r05c0 10 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1669
        ( 16r0600 10 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1670
        ( 16r0200 10 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1671
        ( 16r0ce0 11 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1672
        ( 16r0d00 11 ) "/ 20 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1673
        ( 16r0d80 11 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1674
        ( 16r06e0 11 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1675
        ( 16r0500 11 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1676
        ( 16r02e0 11 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1677
        ( 16r0300 11 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1678
        ( 16r0ca0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1679
        ( 16r0cb0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1680
        ( 16r0cc0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1681
        ( 16r0cd0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1682
        ( 16r0680 12 ) "/ 30 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1683
        ( 16r0690 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1684
        ( 16r06a0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1685
        ( 16r06b0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1686
        ( 16r0d20 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1687
        ( 16r0d30 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1688
        ( 16r0d40 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1689
        ( 16r0d50 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1690
        ( 16r0d60 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1691
        ( 16r0d70 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1692
        ( 16r06c0 12 ) "/ 40 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1693
        ( 16r06d0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1694
        ( 16r0da0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1695
        ( 16r0db0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1696
        ( 16r0540 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1697
        ( 16r0550 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1698
        ( 16r0560 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1699
        ( 16r0570 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1700
        ( 16r0640 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1701
        ( 16r0650 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1702
        ( 16r0520 12 ) "/ 50 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1703
        ( 16r0530 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1704
        ( 16r0240 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1705
        ( 16r0370 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1706
        ( 16r0380 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1707
        ( 16r0270 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1708
        ( 16r0280 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1709
        ( 16r0580 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1710
        ( 16r0590 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1711
        ( 16r02b0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1712
        ( 16r02c0 12 ) "/ 60 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1713
        ( 16r05a0 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1714
        ( 16r0660 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1715
        ( 16r0670 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1716
        "/ ---------------- 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1717
        ( 16r03c0 10 ) "/ 64 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1718
        ( 16r0c80 12 ) "/ 128 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1719
        ( 16r0c90 12 ) "/ 192 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1720
        ( 16r05b0 12 ) "/ 256 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1721
        ( 16r0330 12 ) "/ 320 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1722
        ( 16r0340 12 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1723
        ( 16r0350 12 ) "/ 448 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1724
        ( 16r0360 13 ) "/ 512 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1725
        ( 16r0368 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1726
        ( 16r0250 13 ) "/ 640 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1727
        ( 16r0258 13 ) "/ 704 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1728
        ( 16r0260 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1729
        ( 16r0268 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1730
        ( 16r0390 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1731
        ( 16r0398 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1732
        ( 16r03a0 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1733
        ( 16r03a8 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1734
        ( 16r03b0 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1735
        ( 16r03b8 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1736
        ( 16r0290 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1737
        ( 16r0298 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1738
        ( 16r02a0 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1739
        ( 16r02a8 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1740
        ( 16r02d0 13 )
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1741
        ( 16r02d8 13 ) "/ 1600 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1742
        ( 16r0320 13 ) "/ 1664 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1743
        ( 16r0328 13 ) "/ 1728 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1744
        "/ -------------------------------- 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1745
    ).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1746
    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1747
    WhiteCountTable := SignedWordArray new: 8192 withAll:-1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1748
    BlackCountTable := SignedWordArray new: 8192 withAll:-1.   
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1749
    WhiteShiftTable := SignedWordArray new: 8192.    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1750
    BlackShiftTable := SignedWordArray new: 8192. 
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1751
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1752
    0 to:63 do:[:value |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1753
        |def nBits bits|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1754
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1755
        def := whiteDef at:(value+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1756
        nBits := def second.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1757
        bits := def first >> 3.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1758
        (1 << (13 - nBits)) to:1 by:-1 do:[:cnt |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1759
            WhiteCountTable at:bits+1 put:value.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1760
            WhiteShiftTable at:bits+1 put:nBits.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1761
            bits := bits + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1762
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1763
        def := blackDef at:(value+1).
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1764
        nBits := def second.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1765
        bits := def first >> 3.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1766
        (1 << (13 - nBits)) to:1 by:-1 do:[:cnt |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1767
            BlackCountTable at:bits+1 put:value.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1768
            BlackShiftTable at:bits+1 put:nBits.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1769
            bits := bits + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1770
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1771
    ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1772
    
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1773
    index := value := 64.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1774
    [ value <= 1728 ] whileTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1775
        |nBits bits|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1776
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1777
        nBits := (whiteDef at:(index+1)) second.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1778
        bits := (whiteDef at:(index+1)) first >> 3.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1779
        
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1780
        (1 << (13 - nBits)) to:1 by:-1 do:[:cnt |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1781
            WhiteCountTable at:bits+1 put:value.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1782
            WhiteShiftTable at:bits+1 put:nBits.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1783
            bits := bits + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1784
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1785
        nBits := (blackDef at:(index+1)) second.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1786
        bits := (blackDef at:(index+1)) first >> 3.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1787
        (1 << (13 - nBits)) to:1 by:-1 do:[:cnt |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1788
            BlackCountTable at:bits+1 put:value.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1789
            BlackShiftTable at:bits+1 put:nBits.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1790
            bits := bits + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1791
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1792
        index := index + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1793
        value := value + 64.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1794
    ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1795
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1796
    [ value <= 2560 ] whileTrue:[
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1797
        |nBits bits|
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1798
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1799
        nBits := (whiteDef at:(index+1)) second.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1800
        bits := (whiteDef at:(index+1)) first >> 3.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1801
        (1 << (13 - nBits)) to:1 by:-1 do:[:cnt |
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1802
            WhiteCountTable at:bits+1 put:value.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1803
            WhiteShiftTable at:bits+1 put:nBits.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1804
            BlackCountTable at:bits+1 put:value.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1805
            BlackShiftTable at:bits+1 put:nBits.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1806
            bits := bits + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1807
        ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1808
        index := index + 1.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1809
        value := value + 64.
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1810
    ].
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1811
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1812
    "Created: / 25-08-2017 / 13:25:46 / cg"
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1813
!
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  1814
7501
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1815
swap:nBytes bytesFromRGBA_to_BGRA_in:data startingAt:startIndex
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1816
    "swap bytes from RGBA into BGRA order.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1817
     The argument is a pixel data buffer (byteArray)"
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1818
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1819
    self swap:(nBytes//4) pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:4
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1820
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1821
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1822
     |bytes|
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1823
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1824
     bytes := #[ 0 1 2 3 4 5 6 7 8 9 ].
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1825
     self swap:6 bytesFromRGB_to_BGR_in:bytes startingAt:1.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1826
     bytes.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1827
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1828
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1829
     |bytes|
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1830
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1831
     bytes := ByteArray new:1000000.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1832
     bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12].
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1833
     Time millisecondsToRun:[
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
  1834
	self swap:1000000 bytesFromRGB_to_BGR_in:bytes.
7501
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1835
     ].
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1836
     bytes copyTo:10.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1837
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1838
!
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1839
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1840
swap:nBytes bytesFromRGB_to_BGR_in:data
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1841
    "swap bytes from RGB into BGR order.
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1842
     The argument is a pixel data buffer (byteArray)"
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1843
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1844
    self swap:(nBytes//3) pixelsFromRGB_to_BGR_in:data startingAt:1 bytesPerPixel:3
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1845
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1846
    "
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1847
     |bytes|
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1848
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1849
     bytes := #[ 0 1 2 3 4 5 6 7 8 9 ].
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1850
     self swap:6 bytesFromRGB_to_BGR_in:bytes.
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1851
     bytes.
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1852
    "
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1853
    "
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1854
     |bytes|
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1855
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1856
     bytes := ByteArray new:1000000.
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1857
     bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12].
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1858
     Time millisecondsToRun:[
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
  1859
	self swap:1000000 bytesFromRGB_to_BGR_in:bytes.
5129
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1860
     ].
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1861
     bytes copyTo:10.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1862
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1863
!
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1864
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1865
swap:nBytes bytesFromRGB_to_BGR_in:data startingAt:startIndex
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1866
    "swap bytes from RGB into BGR order.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1867
     The argument is a pixel data buffer (byteArray)"
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1868
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1869
    self swap:(nBytes//3) pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:3
5129
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1870
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1871
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1872
     |bytes|
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1873
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1874
     bytes := #[ 0 1 2 3 4 5 6 7 8 9 ].
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1875
     self swap:6 bytesFromRGB_to_BGR_in:bytes startingAt:1.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1876
     bytes.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1877
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1878
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1879
     |bytes|
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1880
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1881
     bytes := ByteArray new:1000000.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1882
     bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12].
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1883
     Time millisecondsToRun:[
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
  1884
	self swap:1000000 bytesFromRGB_to_BGR_in:bytes.
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1885
     ].
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1886
     bytes copyTo:10.
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1887
    "
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1888
!
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1889
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1890
swap:count pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:bpp
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1891
    "swap bytes from RGB into BGR order.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1892
     The argument is a pixel data buffer (byteArray).
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1893
     Can be used for both 24bit rgb data (bpp=3) or rgba data (bpp=4)"
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1894
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1895
    |t idx|
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1896
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1897
%{  /* OPTIONAL */
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1898
    if (__isByteArray(data)
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1899
     && __isSmallInteger(count)
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1900
     && __isSmallInteger(startIndex)
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1901
     && __isSmallInteger(bpp)) {
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1902
	INT __count = __intVal(count);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1903
	INT __startOffset = __intVal(startIndex) - 1;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1904
	INT __dataSize = __byteArraySize(data);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1905
	int __bpp = __intVal(bpp);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1906
	INT __nBytes = __count * __bpp;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1907
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1908
	if ((__startOffset + __nBytes) <= __dataSize) {
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1909
	    unsigned char *__cp = __ByteArrayInstPtr(data)->ba_element + __startOffset;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1910
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1911
	    while (__count-- > 0) {
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1912
		unsigned char __t;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1913
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1914
		__t = __cp[0];
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1915
		__cp[0] = __cp[2];
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1916
		__cp[2] = __t;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1917
		__cp += __bpp;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1918
	    }
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1919
	    RETURN (true);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1920
	}
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1921
    }
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1922
%}.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1923
    idx := startIndex.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1924
    1 to:count do:[:i |
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1925
	t := data at:idx.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1926
	data at:idx put:(data at:idx+2).
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1927
	data at:idx+2 put:t.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1928
	idx := idx + bpp.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1929
    ].
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1930
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1931
    "
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1932
     |bytes|
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1933
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1934
     bytes := #[ 0 1 2  3 4 5  6 7 8  9 ].
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1935
     self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:3.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1936
     bytes.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1937
    "
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1938
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1939
    "
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1940
     |bytes|
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1941
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1942
     bytes := #[ 0 1 2 3  4 5 6 7  8 9 ].
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1943
     self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:4.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1944
     bytes.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1945
    "
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1946
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1947
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1948
!ImageReader class methodsFor:'i/o support'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1949
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1950
streamReadingFile:aFilename
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1951
    "return a stream to read aFilename.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1952
     If the filename ends with '.Z' or '.gz', return a stream
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1953
     to a pipe for the uncompressor. Otherwise, return a stream to read
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1954
     the file directly."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1955
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1956
    |inStream name fn|
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1957
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1958
    name := aFilename asString.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1959
    ((name endsWith:'.Z') or:[name endsWith:'.gz']) ifTrue:[
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1960
	fn := Smalltalk getSystemFileName:name.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1961
	inStream := PipeStream readingFrom:'gunzip < ' , fn.
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1962
    ] ifFalse:[
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1963
	inStream := Smalltalk systemFileStreamFor:aFilename.
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1964
	inStream isNil ifTrue:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1965
	    inStream := Smalltalk bitmapFileStreamFor:aFilename
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1966
	]
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1967
    ].
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1968
    inStream isNil ifTrue:[
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1969
	'ImageReader [warning]: open error on: ' infoPrint. aFilename infoPrintCR.
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1970
    ].
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1971
    ^ inStream
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
  1972
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1973
    "Modified: 31.1.1997 / 10:37:24 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1974
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1975
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1976
!ImageReader class methodsFor:'image reading'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1977
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1978
fromBytes:aByteArray
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1979
    "read an image (in my format) from aByteArray.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1980
     Return the image or nil (if unrecognized format or error)"
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1981
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1982
    |reader|
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1983
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1984
    reader := self readStream:aByteArray readStream.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1985
    ^ reader image
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1986
!
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1987
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1988
fromFile:aFileName
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1989
    "read an image (in my format) from aFileName.
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1990
     Return the image or nil on error."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1991
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1992
    |reader|
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1993
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1994
    reader := self readFile:aFileName.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1995
    reader notNil ifTrue:[
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1996
	^ reader image
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1997
    ].
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1998
    ^ nil
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1999
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2000
    "
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2001
     XBMReader fromFile:'bitmaps/SBrowser.xbm'
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2002
     XPMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2003
     XBMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
  2004
    "
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
  2005
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2006
    "Modified: 4.4.1997 / 22:09:49 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2007
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2008
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2009
fromStream:aStream
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2010
    "read an image (in my format) from aStream.
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2011
     Return the image or nil (if unrecognized format or error).
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2012
     The stream remains open."
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2013
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2014
    |reader|
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2015
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2016
    reader := self readStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2017
    ^ reader image
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2018
!
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2019
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2020
fromURL:url
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2021
    "read an image (in my format) from url.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2022
     Return the image or nil (if unrecognized format or error)"
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2023
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2024
    |readerClass response|
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2025
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2026
    self == ImageReader ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2027
	"select a reader supporting this file format"
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2028
	readerClass := self readerClassForFilename:url asURL path.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2029
	readerClass ~~ self ifTrue:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2030
	    ^ readerClass fromURL:url.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2031
	].
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2032
    ].
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2033
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2034
    response := HTTPInterface get:url.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2035
    response isErrorResponse ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2036
	self error:'failed to read url' mayProceed:true.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2037
	^ nil
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2038
    ].
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2039
    ^ self fromBytes:(response data).
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2040
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2041
    "
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2042
     self fromURL:'http://www.lutece.paris.fr/tech/images/helloworld.png'
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2043
    "
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2044
!
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2045
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2046
imagesFromFile:aFileName
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2047
    "read all images (in my format) from aFileName.
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2048
     Return a collection of images or nil on error.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2049
     Not all reader may support multiple images."
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2050
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2051
    |reader|
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2052
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2053
    reader := self readFile:aFileName.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2054
    reader notNil ifTrue:[
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2055
	^ reader images
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2056
    ].
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2057
    ^ nil
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2058
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2059
    "Modified: 4.4.1997 / 22:11:01 / cg"
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2060
!
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2061
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2062
imagesFromStream:aStream
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2063
    "read all images (in my format) from aStream.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2064
     Return a collection of images or nil (if unrecognized format or error).
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2065
     The stream remains open.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2066
     Not all reader may support multiple images."
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2067
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2068
    |reader|
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2069
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2070
    reader := self new.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2071
    reader inStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2072
    reader fromStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2073
    ^ reader images
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2074
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2075
    "Modified: 4.4.1997 / 22:11:40 / cg"
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2076
!
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2077
4912
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  2078
readFile:aFilename
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  2079
    "create a reader and let it read an image (in my format) from aFilename.
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2080
     Return the reader, NOT the image (however, the reader has already read the image,
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2081
     so it can be asked with 'reader image')."
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2082
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2083
    |readerClass reader inStream|
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2084
4912
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  2085
    self == ImageReader ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2086
	"select a reader supporting this file format"
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2087
	readerClass := self readerClassForFilename:aFilename.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2088
	readerClass ~~ self ifTrue:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2089
	    ^ readerClass readFile:aFilename.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2090
	].
4912
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  2091
    ].
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  2092
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  2093
    inStream := self streamReadingFile:aFilename.
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2094
    inStream isNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2095
	'ImageReader [warning]: file open error' errorPrintCR.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2096
	^ nil
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2097
    ].
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2098
    reader := self new.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2099
    reader inStream:inStream.
3489
60e6b6ded0b3 close inStream on unwind
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
  2100
    [
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2101
	reader fromStream:inStream.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3489
diff changeset
  2102
    ] ensure:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2103
	inStream close.
3489
60e6b6ded0b3 close inStream on unwind
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
  2104
    ].
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2105
    ^ reader
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2106
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2107
    "
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2108
     XPMReader readFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2109
     (XPMReader readFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm') image
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2110
    "
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2111
5737
f39cc6dc9848 raise different error in #readFile: for unsupported filetypes
Claus Gittinger <cg@exept.de>
parents: 5567
diff changeset
  2112
    "Modified: / 04-04-2011 / 14:16:56 / cg"
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2113
!
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2114
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2115
readStream:aStream
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2116
    "create a reader and let it read a stream (in my format).
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2117
     Return the reader, NOT the image (however, the reader has already read the image,
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2118
     so it can be asked with 'reader image').
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2119
     The stream remains open."
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2120
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2121
    |reader|
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2122
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2123
    reader := self new.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2124
    reader fromStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2125
    ^ reader
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2126
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2127
    "Created: 4.4.1997 / 22:08:13 / cg"
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2128
!
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2129
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2130
readerClassForFilename:aStringOrFilename
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2131
    "return a reader class, determined by the file's name"
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2132
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2133
    |mime reader|
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2134
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2135
    mime := aStringOrFilename asFilename mimeTypeFromName.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2136
    mime isNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2137
	mime := aStringOrFilename asFilename mimeTypeOfContents.
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2138
    ].
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2139
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2140
    mime notNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2141
	reader := MIMETypes imageReaderForType:mime.
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2142
    ].
6167
baa4c9ec056a class: ImageReader
Stefan Vogel <sv@exept.de>
parents: 6062
diff changeset
  2143
    reader isNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2144
	"answer the reader when proceeding form this error"
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2145
	reader := ConversionError raiseRequestErrorString:(' - unsupported image type: ''%1''' bindWith:(mime ? aStringOrFilename asFilename suffix)).
6167
baa4c9ec056a class: ImageReader
Stefan Vogel <sv@exept.de>
parents: 6062
diff changeset
  2146
    ].
baa4c9ec056a class: ImageReader
Stefan Vogel <sv@exept.de>
parents: 6062
diff changeset
  2147
    ^ reader
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2148
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2149
    "
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2150
     self readerClassForFilename:('http://www.foo.bar/helloworld.png' asURL path)
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2151
     self readerClassForFilename:('http://www.foo.bar/helloworld.gif' asURL path)
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  2152
    "
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2153
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2154
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2155
!ImageReader class methodsFor:'image support'!
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2156
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2157
buildMaskFromColor:maskPixelValue for:pixels depth:depth width:width height:height
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2158
    "helper for image formats, where an individual pixel value
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2159
     has been defined as a mask-pixel (i.e. GIF).
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2160
     Creates a maskImage, with zeros at positions where the image
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2161
     has the given pixelValue; all other mask pixels are set to 1."
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2162
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2163
    |maskArray bytesPerMaskRow mask ok|
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2164
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2165
    bytesPerMaskRow := (width+7) // 8.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2166
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2167
    maskArray := ByteArray uninitializedNew:bytesPerMaskRow * height.
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2168
    ok := false.
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2169
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2170
%{
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2171
    int __w = __intVal(width);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2172
    int __h = __intVal(height);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2173
    int __x, __y;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2174
    int __outBits, __nOut;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2175
    unsigned char *__inP, *__outP, *__nextOutRow;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2176
    int __bpr = __intVal(bytesPerMaskRow);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2177
    int __maskPixel = __intVal(maskPixelValue);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2178
#ifdef DEBUG
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2179
    unsigned char *outEnd;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2180
#endif
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2181
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  2182
    if (! __isByteArrayLike(pixels)) goto fail;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2183
    if (! __isByteArray(maskArray)) goto fail;
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2184
    if (__intVal(depth) != 8) goto fail;
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2185
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2186
    __inP = __ByteArrayInstPtr(pixels)->ba_element;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2187
    __outP = __ByteArrayInstPtr(maskArray)->ba_element;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2188
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2189
#ifdef DEBUG
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2190
    outEnd = __outP + (__byteArraySize(maskArray));
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2191
#endif
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2192
    //
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2193
    // printf("outP: %x outEnd: %x sz: %d\n", __outP, outEnd, __byteArraySize(maskArray));
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2194
    //
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2195
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2196
    for (__y=__h; __y>0; __y--) {
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2197
	__outBits = 0;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2198
	__nOut = 8;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2199
	__nextOutRow = __outP + __bpr;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2200
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2201
	for (__x=__w; __x>=8; __x-=8) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2202
	    if (__inP[0] != __maskPixel) { __outBits |= 0x80; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2203
	    if (__inP[1] != __maskPixel) { __outBits |= 0x40; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2204
	    if (__inP[2] != __maskPixel) { __outBits |= 0x20; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2205
	    if (__inP[3] != __maskPixel) { __outBits |= 0x10; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2206
	    if (__inP[4] != __maskPixel) { __outBits |= 0x08; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2207
	    if (__inP[5] != __maskPixel) { __outBits |= 0x04; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2208
	    if (__inP[6] != __maskPixel) { __outBits |= 0x02; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2209
	    if (__inP[7] != __maskPixel) { __outBits |= 0x01; };
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2210
	    __inP += 8;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2211
	    *__outP++ = __outBits;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2212
	    __outBits = 0;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2213
	}
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2214
	for (; __x>0; __x--) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2215
	    __outBits <<= 1;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2216
	    if (*__inP != __maskPixel) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2217
		__outBits |= 1;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2218
	    }
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2219
	    __inP++;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2220
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2221
	    //
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2222
	    // printf("x: %d  bits: %x\n", __x, __outBits);
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2223
	    //
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2224
	    if (--__nOut == 0) {
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2225
#ifdef DEBUG
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2226
		if (__outP >= outEnd) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2227
		    if (@global(InfoPrinting) == true) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2228
			console_fprintf(stderr, "oops %d\n", __LINE__);
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2229
		    }
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2230
		    goto fail;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2231
		}
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2232
#endif
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2233
		*__outP = __outBits;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2234
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2235
		__outP++;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2236
		__nOut = 8;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2237
		__outBits = 0;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2238
	    }
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2239
	}
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2240
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2241
	if (__nOut != 8) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2242
	    __outBits <<= __nOut;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2243
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2244
#ifdef DEBUG
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2245
	    if (__outP >= outEnd) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2246
		if (@global(InfoPrinting) == true) {
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2247
		    console_fprintf(stderr, "oops2 %d\n", __LINE__);
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2248
		}
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2249
		goto fail;
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2250
	    }
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2251
#endif
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2252
	    *__outP = __outBits;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2253
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2254
	}
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2255
	__outP = __nextOutRow;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2256
    }
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2257
    ok = true;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2258
fail: ;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2259
%}.
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2260
    ok ifFalse:[
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2261
	"/ slow fallback...
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2262
	self halt.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2263
    ].
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2264
    mask := ImageMask width:width height:height fromArray:maskArray.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2265
    ^ mask
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2266
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2267
    "Created: / 23-08-2017 / 17:10:03 / cg"
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2268
!
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2269
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2270
buildMaskFromColor:maskPixelValue for:pixels width:width height:height
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2271
    "helper for image formats, where an individual pixel value
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2272
     has been defined as a mask-pixel (i.e. GIF).
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2273
     Creates a maskImage, with zeros at positions where the image
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2274
     has the given pixelValue; all other mask pixels are set to 1."
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2275
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2276
    ^ self buildMaskFromColor:maskPixelValue for:pixels depth:8 width:width height:height
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2277
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2278
    "Created: / 21-06-1996 / 11:43:47 / cg"
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2279
    "Modified: / 23-08-2017 / 17:13:23 / cg"
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2280
! !
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2281
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  2282
!ImageReader class methodsFor:'image writing'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2283
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2284
save:anImage onFile:aFileName
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2285
    "save the image in my format on aFileName.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2286
     Returns the imageReader instance (bad name; is a writer).
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
  2287
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2288
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2289
     or it is not support"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2290
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2291
    ^ (self basicNew) save:anImage onFile:aFileName
1574
7c25ed84ad12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1551
diff changeset
  2292
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2293
    "Modified: / 10-04-1997 / 17:42:57 / cg"
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2294
    "Modified (comment): / 05-02-2017 / 16:58:30 / cg"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2295
!
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2296
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2297
save:anImage onFile:aFileName quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2298
    "save the image in my format on aFileName.
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2299
     The qualityPercent argument is ignored by all lossless formats.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2300
     (however, JPG does care for it.)
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2301
     Returns the imageReader instance (bad name; is a writer).
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
  2302
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2303
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2304
     or it is not support"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2305
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2306
    ^ (self basicNew) save:anImage onFile:aFileName quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2307
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2308
    "Modified: / 10-04-1997 / 17:42:57 / cg"
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2309
    "Modified (comment): / 05-02-2017 / 16:58:45 / cg"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2310
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2311
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2312
save:anImage onStream:aStream
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2313
    "save the image in my format on aStream.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2314
     Returns the imageReader instance (bad name; is a writer).
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
  2315
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2316
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2317
     or it is not support"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2318
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2319
    ^ (self basicNew) save:anImage onStream:aStream
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2320
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2321
    "Modified: / 10-04-1997 / 17:42:57 / cg"
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2322
    "Modified (comment): / 05-02-2017 / 16:58:18 / cg"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2323
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2324
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2325
save:anImage onStream:aStream quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2326
    "save the image in my format on a Stream.
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2327
     The qualityPercent argument is ignored by all lossless formats.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2328
     (however, JPG does care for it.)
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2329
     Returns the imageReader instance (bad name; is a writer).
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
  2330
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2331
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2332
     or it is not support"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2333
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2334
    ^ (self basicNew) save:anImage onStream:aStream quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2335
7174
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  2336
    "
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2337
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield.gif'
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2338
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield.jpg'
7174
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  2339
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield50.jpg' quality:50
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  2340
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield100.jpg' quality:100
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  2341
    "
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2342
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  2343
    "Modified (comment): / 05-02-2017 / 16:58:11 / cg"
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2344
!
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2345
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2346
saveAll:aCollectionOfImages onFile:aFilename
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2347
    "save an image collection in my format on a file.
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2348
     Not all file formats support multiple images,
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2349
     so be prepared for an exception to be raised."
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2350
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2351
    ^ (self basicNew) saveAll:aCollectionOfImages onFile:aFilename
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2352
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2353
    "Created: / 22-02-2017 / 01:01:17 / cg"
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2354
!
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2355
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2356
saveAll:aCollectionOfImages onStream:aStream
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2357
    "save an image collection in my format on a Stream.
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2358
     Not all file formats support multiple images,
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2359
     so be prepared for an exception to be raised."
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2360
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2361
    ^ (self basicNew) saveAll:aCollectionOfImages onStream:aStream
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2362
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2363
    "Created: / 22-02-2017 / 01:00:44 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2364
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2365
7859
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2366
!ImageReader class methodsFor:'queries'!
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2367
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2368
isAbstract
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2369
    "Return if this class is an abstract class.
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2370
     True is returned here for myself only; false for subclasses.
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2371
     Abstract subclasses must redefine this again."
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2372
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2373
    ^ self == ImageReader.
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2374
! !
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  2375
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  2376
!ImageReader class methodsFor:'testing'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2377
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2378
canRepresent:anImage
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2379
    "return true, if anImage can be represented in my file format.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2380
     must be redefined in concrete subclasses which support saving."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2381
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2382
    ^ false
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2383
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2384
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2385
isValidImageFile:aFileName
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2386
    "return true, if aFileName contains an image this
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2387
     reader understands - must be redefined in concrete subclasses
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2388
     which support reading."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2389
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2390
    ^ false
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2391
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2392
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2393
!ImageReader methodsFor:'accessing'!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2394
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2395
bitsPerPixel
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2396
    "return the number of bits per pixel"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2397
8146
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2398
    "/ if depth was given, that is what we use;
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2399
    "/ otherwise, compute from bitsPerSample.
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2400
    "/ notice, that depth is >= sum(bitsPerSample),
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2401
    "/ for example, in a 16bit image, we mght have
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2402
    "/ depth == 16 and bitsPerSample = 5+5+5,
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2403
    
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2404
    depth notNil ifTrue:[^ depth].
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2405
    
3386
b9294699dbcf care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  2406
    bitsPerSample isNil ifTrue:[^ nil].
5927
eebe3a485637 changed: #bitsPerPixel
Stefan Vogel <sv@exept.de>
parents: 5737
diff changeset
  2407
    ^ bitsPerSample sum
8146
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2408
97a4ee050bd6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 8145
diff changeset
  2409
    "Modified (format): / 31-08-2017 / 18:09:59 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2410
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2411
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2412
bitsPerRow
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2413
    "return the number of bits in one scanline of the image"
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2414
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3843
diff changeset
  2415
    ^ width * (self bitsPerPixel).
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2416
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2417
    "Created: 31.1.1997 / 10:38:42 / cg"
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2418
!
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2419
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2420
bitsPerSample
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2421
    "return the number of bits per sample"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2422
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2423
    ^ bitsPerSample
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2424
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2425
    "Modified: 22.4.1996 / 19:15:18 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2426
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2427
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2428
bytesPerRow
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2429
    "return the number of bytes in one scanline of the image"
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2430
7897
de53f0853c91 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7894
diff changeset
  2431
    ^ Image bytesPerRowForWidth:width bitsPerPixel:(self bitsPerPixel)
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2432
7897
de53f0853c91 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7894
diff changeset
  2433
    "Created: / 31-01-1997 / 10:39:06 / cg"
de53f0853c91 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7894
diff changeset
  2434
    "Modified: / 16-02-2017 / 16:18:13 / cg"
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2435
!
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  2436
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2437
colorMap
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2438
    "return the colormap"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2439
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2440
    ^ colorMap
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2441
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2442
    "Modified: 22.4.1996 / 19:15:24 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2443
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2444
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2445
compressQuality:qualityPercentIgnoredHere
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2446
    "/ intentionally ignored here (redefined in JPEGReader)
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2447
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2448
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2449
data
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2450
    "return the raw image data"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2451
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2452
    ^ data
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2453
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2454
    "Modified: 22.4.1996 / 19:15:31 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2455
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2456
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2457
hasMultipleImages
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2458
    ^ imageSequence size > 1
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2459
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2460
    "Created: 4.4.1997 / 21:37:06 / cg"
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2461
    "Modified: 24.6.1997 / 15:33:43 / cg"
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2462
!
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  2463
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2464
height
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2465
    "return the height of the image"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2466
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2467
    ^ height
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2468
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2469
    "Modified: 22.4.1996 / 19:15:39 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2470
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2471
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2472
image
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2473
    "return the image as represented by myself;
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2474
     If my file contained multiple images, return the first one."
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2475
7908
84a8ad360ada #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7897
diff changeset
  2476
    imageSequence notEmptyOrNil ifTrue:[
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2477
        ^ imageSequence first image
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2478
    ].
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2479
    ^ self makeImage.
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2480
7908
84a8ad360ada #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7897
diff changeset
  2481
    "Modified: / 15-01-1998 / 15:46:24 / stefan"
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2482
    "Modified: / 26-08-2017 / 14:38:18 / cg"
2082
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2483
!
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2484
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2485
imageFrames
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2486
    "return a collection of all imageFrames as represented by myself.
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2487
     ImageFrames are wrappers for individual images, which hold
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2488
     additional information (such as image delay time).
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2489
     Nil is return for single image formats/files."
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2490
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2491
    ^ imageSequence
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2492
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2493
    "Created: / 1.4.1998 / 14:37:42 / cg"
893
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2494
!
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2495
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2496
images
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2497
    "return a collection of all images as represented by myself.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2498
     For compatibility with single-image formats, return a collection
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2499
     containing my single image here if the file format does not support
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2500
     multiple images.
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2501
     Readers for formats with multiple images should leave the images
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2502
     in the imageSequence instVar as a side effect of reading."
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2503
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2504
    |img|
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2505
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2506
    imageSequence notNil ifTrue:[
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2507
        ^ (imageSequence collect:[:aFrame | aFrame image])
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2508
    ].
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2509
2082
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2510
    img := self makeImage.
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2511
    img isNil ifTrue:[
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2512
        ^ img
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2513
    ].
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2514
    ^ Array with:img
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2515
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2516
    "Modified: / 01-04-1998 / 14:36:23 / cg"
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2517
    "Modified (comment): / 26-08-2017 / 14:38:48 / cg"
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2518
!
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  2519
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2520
makeImage
2082
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2521
    "return the image as represented by the values found in my
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2522
     instvars; these have been typically set as a side effect of
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  2523
     the fromStream:-method, which reads images."
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2524
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2525
    |image depth|
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2526
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2527
    depth := self bitsPerPixel.
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2528
    (depth notNil and:[data notNil]) ifTrue:[
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2529
	image := Image newForDepth:depth.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2530
	image depth:depth.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2531
	inStream isFileStream ifTrue:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2532
	    image fileName:inStream pathName.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2533
	].
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2534
	image
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2535
	    width:width
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2536
	    height:height
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2537
	    photometric:photometric
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2538
	    samplesPerPixel:samplesPerPixel
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2539
	    bitsPerSample:bitsPerSample
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2540
	    colorMap:colorMap
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2541
	    bits:data
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2542
	    mask:mask.
3386
b9294699dbcf care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  2543
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2544
	imageSequence notNil ifTrue:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2545
	    image imageSequence:imageSequence.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2546
	].
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2547
	metaData notEmptyOrNil ifTrue:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2548
	    image metaData:metaData
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2549
	].
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2550
    ].
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2551
    ^ image
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2552
8026
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  2553
    "Modified: / 15-01-1998 / 15:46:24 / stefan"
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  2554
    "Created: / 01-04-1998 / 14:09:45 / cg"
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  2555
    "Modified: / 17-05-2017 / 14:37:16 / mawalch"
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2556
!
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2557
893
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2558
mask
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2559
    "return the image mask (or nil)"
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2560
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2561
    ^ mask
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2562
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2563
    "Modified: 22.4.1996 / 19:15:31 / cg"
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2564
    "Created: 20.6.1996 / 17:08:29 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2565
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2566
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2567
numberOfImages
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2568
    "return the number of images as read.
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2569
     By default (here), I hold a single image;
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2570
     however, some fileFormats allow for multiple images"
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2571
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2572
    |n|
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2573
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2574
    (n := imageSequence size) > 0 ifTrue:[
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2575
	^ n
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2576
    ].
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2577
    ^ 1
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2578
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2579
    "Created: 21.6.1997 / 18:33:45 / cg"
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2580
    "Modified: 24.6.1997 / 15:33:26 / cg"
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2581
!
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2582
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2583
photometric
6309
d12f01f0e52e class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6167
diff changeset
  2584
    "return the photometric interpretation of the image data.
d12f01f0e52e class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6167
diff changeset
  2585
     This may be a somewhat old leftover from times, when tiff was the first image file type to be read.
d12f01f0e52e class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6167
diff changeset
  2586
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2587
     However, in the meantime, many other classes depend on that, so that it should be kept as an API
6309
d12f01f0e52e class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6167
diff changeset
  2588
     - even when the internal representation will be replaced by something better in the future."
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2589
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2590
    ^ photometric
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2591
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2592
    "Modified: 22.4.1996 / 19:15:57 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2593
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2594
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2595
samplesPerPixel
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2596
    "return the number of samples per pixel"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2597
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2598
    ^ samplesPerPixel
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2599
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2600
    "Modified: 22.4.1996 / 19:16:03 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2601
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2602
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2603
width
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2604
    "return the width of the image"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2605
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2606
    ^ width
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2607
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2608
    "Modified: 22.4.1996 / 19:16:10 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2609
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2610
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3260
diff changeset
  2611
!ImageReader methodsFor:'accessing-private'!
1355
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2612
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2613
byteOrder:aSymbol
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2614
    "set the byte order - either #lsb or #msb"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2615
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2616
    byteOrder := aSymbol
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2617
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2618
    "Created: 15.2.1997 / 13:58:50 / cg"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2619
!
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2620
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2621
inStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2622
    ^ inStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2623
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2624
    "Created: 15.2.1997 / 13:57:40 / cg"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2625
!
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2626
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2627
inStream:aStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2628
    inStream := aStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2629
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2630
    "Created: 15.2.1997 / 13:57:35 / cg"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2631
! !
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2632
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2633
!ImageReader methodsFor:'error reporting'!
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2634
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2635
fileFormatError:aMessage
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  2636
    "report a format error - no image could be read.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  2637
     The error may be proceeded, then a nil is returned (useful for image sequences as in ICNS)"
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2638
8129
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2639
    ^ self fileFormatError:aMessage with:nil
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2640
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2641
    "Created: / 03-02-1998 / 17:50:06 / cg"
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2642
    "Modified: / 29-08-2017 / 23:00:51 / cg"
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2643
!
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2644
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2645
fileFormatError:aMessage with:argument
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2646
    "report a format error - no image could be read.
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2647
     The error may be proceeded, then a nil is returned (useful for image sequences as in ICNS)"
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2648
4055
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2649
    |errorString|
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2650
8129
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2651
    errorString := self class name , ' [error]: ' , (aMessage bindWith:argument).
4055
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2652
    inStream isFileStream ifTrue:[
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2653
        errorString := errorString , Character cr, '[in "' , inStream pathName , '"]'
4055
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2654
    ].
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2655
6618
9d377a77a1a1 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6585
diff changeset
  2656
    Image badImageFormatQuerySignal raiseRequestErrorString:errorString.
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2657
    ^ nil
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2658
8129
a84ca4eab4ae #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8110
diff changeset
  2659
    "Created: / 29-08-2017 / 23:00:37 / cg"
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2660
! !
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2661
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2662
!ImageReader methodsFor:'i/o support'!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2663
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2664
readLong
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2665
    "return the next 4-byte long, honoring the byte-order"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2666
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2667
    ^ inStream nextInt32MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2668
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2669
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2670
readShort
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2671
    "return the next 2-byte short, honoring the byte-order"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2672
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2673
    ^ inStream nextUnsignedInt16MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2674
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2675
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2676
readShortLong
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2677
    "return the next 2-byte short, honoring the byte-order.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2678
     There are actually 4 bytes read, but only 2 looked at."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2679
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2680
    |bytes val|
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2681
153
claus
parents: 134
diff changeset
  2682
    bytes := ByteArray uninitializedNew:4.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2683
    inStream nextBytes:4 into:bytes.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2684
    (byteOrder == #lsb) ifTrue:[
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2685
	val := bytes at:2.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2686
	val := val * 256 + (bytes at:1)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2687
    ] ifFalse:[
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2688
	val := bytes at:3.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2689
	val := val * 256 + (bytes at:4)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2690
    ].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2691
    ^ val
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2692
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2693
5318
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2694
readUnsignedLong
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2695
    "return the next 4-byte long, honoring the byte-order"
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2696
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2697
    ^ inStream nextUnsignedInt32MSB:(byteOrder ~~ #lsb)
5318
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2698
!
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2699
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2700
writeLong:anInteger
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2701
    "write a 4-byte long, honoring the byte-order."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2702
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2703
    outStream nextPutInt32:anInteger MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2704
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2705
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2706
writeShort:anInteger
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2707
    "write a 2-byte short, honoring the byte-order."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2708
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2709
    outStream nextPutInt16:anInteger MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2710
! !
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2711
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2712
!ImageReader methodsFor:'image reading'!
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2713
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2714
fromStream:aStream
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2715
    "read an image in my format from aStream.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2716
     Leave image description in instance variables."
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2717
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2718
    self inStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2719
    self readImage.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2720
!
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2721
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2722
readImage
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2723
    "read an image in my format from my inStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2724
     Leave image description in instance variables."
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2725
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2726
    self subclassResponsibility.
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2727
! !
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2728
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2729
!ImageReader methodsFor:'image reading support'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2730
929
f792d9689def Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents: 893
diff changeset
  2731
buildMaskFromColor:maskPixelValue
1631
fc944d181796 use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2732
    "helper for image formats, where an individual pixel value
fc944d181796 use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2733
     has been defined as a mask-pixel (i.e. GIF).
fc944d181796 use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2734
     Creates a maskImage, with zeros at positions where the image
fc944d181796 use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2735
     has the given pixelValue; all other mask pixels are set to 1."
fc944d181796 use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2736
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2737
    mask := self class
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2738
		buildMaskFromColor:maskPixelValue
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2739
		for:data depth:(self bitsPerPixel)
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2740
		width:width height:height
929
f792d9689def Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents: 893
diff changeset
  2741
8095
7d4b25655182 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8060
diff changeset
  2742
    "Modified: / 23-08-2017 / 17:11:51 / cg"
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2743
! !
929
f792d9689def Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents: 893
diff changeset
  2744
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2745
!ImageReader methodsFor:'image writing'!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2746
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2747
save:image onFile:aFileName
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2748
    "save image in my format on aFile"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2749
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2750
    self writingFile:aFileName for:image do:[:stream |
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2751
	self save:image onStream:stream.
5567
7a7a10a2e29c changed: #save:onFile:
Claus Gittinger <cg@exept.de>
parents: 5527
diff changeset
  2752
    ].
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2753
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2754
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2755
save:image onFile:aFileName quality:qualityPercentOrNil
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2756
    "save image in my format on aFile"
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2757
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2758
    self compressQuality:qualityPercentOrNil.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2759
    self save:image onFile:aFileName
3933
10147dc53aef image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3932
diff changeset
  2760
5567
7a7a10a2e29c changed: #save:onFile:
Claus Gittinger <cg@exept.de>
parents: 5527
diff changeset
  2761
    "Modified: / 01-06-2010 / 19:02:17 / cg"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2762
!
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2763
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2764
save:image onStream:aStream
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2765
    "save image in my file-format onto aStream"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2766
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2767
    ^ Image cannotRepresentImageSignal
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2768
	raiseWith:image
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2769
	errorString:('image save not implemented/supported for this format').
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2770
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2771
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2772
save:image onStream:aStream quality:qualityPercentOrNil
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2773
    "save image in my format on a Stream.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2774
     QualityPercent is ignored by lossless formats (jpg uses it)"
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2775
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2776
    self compressQuality:qualityPercentOrNil.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2777
    self save:image onStream:aStream
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2778
!
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2779
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2780
saveAll:aCollectionOfImages onFile:aFileName
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2781
    "save a collection of images in my format on aFile.
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2782
     Not all file formats support multiple images,
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2783
     so be prepared for an exception to be raised."
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2784
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2785
    self writingFile:aFileName for:aCollectionOfImages do:[:stream |
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2786
	self saveAll:aCollectionOfImages onStream:stream.
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2787
    ].
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2788
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2789
    "Modified: / 01-06-2010 / 19:02:17 / cg"
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2790
    "Modified (comment): / 22-02-2017 / 01:00:03 / cg"
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2791
!
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2792
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2793
saveAll:aCollectionOfImages onStream:aStream
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2794
    "save an image collection in my format on a Stream.
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2795
     Not all file formats support multiple images,
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2796
     so be prepared for an exception to be raised."
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2797
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2798
    ^ Image cannotRepresentImageSignal
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2799
	raiseWith:aCollectionOfImages
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2800
	errorString:('save of imageSequence not implemented/supported for this format').
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2801
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2802
    "Modified (comment): / 22-02-2017 / 01:00:11 / cg"
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2803
!
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2804
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2805
writingFile:aFileName for:something do:aBlock
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2806
    "helper for save image"
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2807
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2808
    |stream|
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2809
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2810
    [
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2811
	stream := aFileName asFilename newReadWriteStream.
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2812
    ] on:FileStream openErrorSignal do:[:ex|
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2813
	^ Image fileCreationErrorSignal
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2814
	    raiseWith:something
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2815
	    errorString:('file creation error: ' , ex description).
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2816
    ].
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2817
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2818
    [
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2819
	[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2820
	    aBlock value: stream
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2821
	] ensure:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2822
	    stream close.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2823
	].
6377
7546e57a7035 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
  2824
    ] ifCurtailed:[
8101
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2825
	OsError catch:[
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2826
	    aFileName asFilename delete.
89a8d155c22a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8095
diff changeset
  2827
	]
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2828
    ].
8060
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2829
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2830
    "Modified: / 04-08-2017 / 11:28:41 / stefan"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2831
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2832
1358
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2833
!ImageReader methodsFor:'initialization'!
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2834
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2835
initialize
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2836
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2837
    "Created: 18.2.1997 / 17:08:31 / cg"
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2838
! !
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2839
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2840
!ImageReader methodsFor:'progress reporting'!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2841
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2842
dimensionCallBack:aBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2843
    "set the block, which is evaluated during the readProcess, as soon as
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2844
     the images dimension is known. This is useful for background image reading,
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2845
     if the size is need to be known (for example: for formatting purposes).
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2846
     Obsoleted by dimensionHolder."
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2847
4177
7c3612e35974 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4055
diff changeset
  2848
    <resource:#obsolete>
3965
8c9c9e08880c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3957
diff changeset
  2849
    self obsoleteMethodWarning:'use #dimensionHolder'.
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2850
    dimensionCallBack := aBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2851
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2852
    "Created: 14.9.1996 / 17:10:58 / cg"
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2853
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2854
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2855
dimensionHolder:aValueHolderOrBlock
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2856
    "set the valueHolder or block, which is evaluated during the readProcess,
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2857
     as soon as the images dimension is known.
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2858
     Useful for background image reading, if the size is need to be known (for example: for formatting purposes)."
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2859
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2860
    dimensionHolder := aValueHolderOrBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2861
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2862
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2863
progressHolder:aValueHolderOrBlock
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2864
    "set the valueHolder or block, which is evaluated during the readProcess,
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2865
     and set with progress information (0..100 percent).
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2866
     Useful for user feedback"
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2867
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2868
    progressHolder := aValueHolderOrBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2869
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2870
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2871
reportDimension
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2872
    dimensionCallBack notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2873
	dimensionCallBack value:self
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2874
    ].
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2875
    dimensionHolder notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2876
	dimensionHolder value:(width @ height)
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2877
    ].
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2878
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2879
3957
ffe8a76fae45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
  2880
reportProgress:fraction
ffe8a76fae45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
  2881
    "can be used by a GUI application to indicate loading progress (0..1)"
ffe8a76fae45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
  2882
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2883
    progressHolder notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2884
	progressHolder value:fraction
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2885
    ].
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2886
! !
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2887
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  2888
!ImageReader class methodsFor:'documentation'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2889
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2890
version
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2891
    ^ '$Header$'
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  2892
!
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  2893
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  2894
version_CVS
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2895
    ^ '$Header$'
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2896
! !
8110
19a15da94872 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8107
diff changeset
  2897