ImageReader.st
author Stefan Vogel <sv@exept.de>
Fri, 04 Aug 2017 22:02:58 +0200
changeset 8060 009e27b016b1
parent 8026 532ccce8b1fd
child 8095 7d4b25655182
permissions -rw-r--r--
#QUALITY by stefan class: ImageReader changed: #writingFile:for:do: better exception info
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
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    17
	instanceVariableNames:'width height data byteOrder inStream outStream photometric
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'
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    21
	classVariableNames:'ReverseBits'
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    22
	poolDictionaries:''
3843
57d7f752c63b code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 3839
diff changeset
    23
	category:'Graphics-Images-Readers'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    24
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    25
189
claus
parents: 153
diff changeset
    26
!ImageReader primitiveDefinitions!
claus
parents: 153
diff changeset
    27
%{
1891
0dc56210cbfb VMS stuff
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    28
6062
dc9d34b204a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6061
diff changeset
    29
# define STDC_HEADERS
189
claus
parents: 153
diff changeset
    30
#ifndef _STDIO_H_INCLUDED_
claus
parents: 153
diff changeset
    31
# include <stdio.h>
claus
parents: 153
diff changeset
    32
# define _STDIO_H_INCLUDED_
claus
parents: 153
diff changeset
    33
#endif
5973
028f7d7e7e73 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5927
diff changeset
    34
6061
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    35
#if defined(__osx__)
6062
dc9d34b204a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6061
diff changeset
    36
# include <stdlib.h>
6061
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    37
# define _MALLOC_H_INCLUDED_
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    38
#endif
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    39
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
    40
#ifndef _MALLOC_H_INCLUDED_
5973
028f7d7e7e73 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5927
diff changeset
    41
# if !defined(FREEBSD)
6061
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    42
#  include <malloc.h>
285d08698c88 osx include
Claus Gittinger <cg@exept.de>
parents: 6060
diff changeset
    43
#  define _MALLOC_H_INCLUDED_
5527
216f389ffe42 freebsd changes
Michael Beyl <mb@exept.de>
parents: 5481
diff changeset
    44
# endif
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
    45
#endif
2423
416882dbf8cf changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents: 2261
diff changeset
    46
416882dbf8cf changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents: 2261
diff changeset
    47
189
claus
parents: 153
diff changeset
    48
%}
claus
parents: 153
diff changeset
    49
! !
claus
parents: 153
diff changeset
    50
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    51
!ImageReader primitiveFunctions!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    52
%{
48194c26a46c Initial revision
claus
parents:
diff changeset
    53
48194c26a46c Initial revision
claus
parents:
diff changeset
    54
/*
48194c26a46c Initial revision
claus
parents:
diff changeset
    55
 * ccitt decompression
48194c26a46c Initial revision
claus
parents:
diff changeset
    56
 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    57
static short *whiteCountTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    58
static char  *whiteShiftTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    59
static short *blackCountTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    60
static char  *blackShiftTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
    61
48194c26a46c Initial revision
claus
parents:
diff changeset
    62
struct ccitt_def {
48194c26a46c Initial revision
claus
parents:
diff changeset
    63
    unsigned short bits;
48194c26a46c Initial revision
claus
parents:
diff changeset
    64
    short nBits;
48194c26a46c Initial revision
claus
parents:
diff changeset
    65
};
48194c26a46c Initial revision
claus
parents:
diff changeset
    66
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    67
static struct ccitt_def
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    68
whiteDef[] = {
48194c26a46c Initial revision
claus
parents:
diff changeset
    69
    { 0x3500, 8 }, /* 0 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    70
    { 0x1c00, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    71
    { 0x7000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    72
    { 0x8000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    73
    { 0xb000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    74
    { 0xc000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    75
    { 0xe000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    76
    { 0xf000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    77
    { 0x9800, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    78
    { 0xA000, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    79
    { 0x3800, 5 }, /* 10 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    80
    { 0x4000, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    81
    { 0x2000, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    82
    { 0x0c00, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    83
    { 0xd000, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    84
    { 0xd400, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    85
    { 0xa800, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    86
    { 0xac00, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    87
    { 0x4e00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    88
    { 0x1800, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    89
    { 0x1000, 7 }, /* 20 */
48194c26a46c Initial revision
claus
parents:
diff changeset
    90
    { 0x2e00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    91
    { 0x0600, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    92
    { 0x0800, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    93
    { 0x5000, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    94
    { 0x5600, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    95
    { 0x2600, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    96
    { 0x4800, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    97
    { 0x3000, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
    98
    { 0x0200, 8 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
    99
    { 0x0300, 8 }, /* 30 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   100
    { 0x1a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   101
    { 0x1b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   102
    { 0x1200, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   103
    { 0x1300, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   104
    { 0x1400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   105
    { 0x1500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   106
    { 0x1600, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   107
    { 0x1700, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   108
    { 0x2800, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   109
    { 0x2900, 8 }, /* 40 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   110
    { 0x2a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   111
    { 0x2b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   112
    { 0x2c00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   113
    { 0x2d00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   114
    { 0x0400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   115
    { 0x0500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   116
    { 0x0a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   117
    { 0x0b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   118
    { 0x5200, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   119
    { 0x5300, 8 }, /* 50 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   120
    { 0x5400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   121
    { 0x5500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   122
    { 0x2400, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   123
    { 0x2500, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   124
    { 0x5800, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   125
    { 0x5900, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   126
    { 0x5a00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   127
    { 0x5b00, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   128
    { 0x4a00, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   129
    { 0x4b00, 8 }, /* 60 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   130
    { 0x3200, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   131
    { 0x3300, 8 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   132
    { 0x3400, 8 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   133
/* ---------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   134
    { 0xd800, 5 }, /* 64 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   135
    { 0x9000, 5 }, /* 128 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   136
    { 0x5c00, 6 }, /* 192 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   137
    { 0x6e00, 7 }, /* 256 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   138
    { 0x3600, 8 }, /* 320 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   139
    { 0x3700, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   140
    { 0x6400, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   141
    { 0x6500, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   142
    { 0x6800, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   143
    { 0x6700, 8 }, /* 640 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   144
    { 0x6600, 9 }, /* 704 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   145
    { 0x6680, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   146
    { 0x6900, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   147
    { 0x6980, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   148
    { 0x6a00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   149
    { 0x6a80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   150
    { 0x6b00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   151
    { 0x6b80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   152
    { 0x6c00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   153
    { 0x6c80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   154
    { 0x6d00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   155
    { 0x6d80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   156
    { 0x4c00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   157
    { 0x4c80, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   158
    { 0x4d00, 9 }, /* 1600 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   159
    { 0x6000, 6 }, /* 1664 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   160
    { 0x4d80, 9 }, /* 1728 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   161
/* -------------------------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   162
    { 0x0100, 11 }, /* 1792 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   163
    { 0x0180, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   164
    { 0x01a0, 11 }, /* 1920 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   165
    { 0x0120, 12 }, /* 1984 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   166
    { 0x0130, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   167
    { 0x0140, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   168
    { 0x0150, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   169
    { 0x0160, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   170
    { 0x0170, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   171
    { 0x01c0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   172
    { 0x01d0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   173
    { 0x01e0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   174
    { 0x01f0, 12 }, /* 2560 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   175
/* -------------------------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   176
    { 0x0010, 12 }, /* EOL */
48194c26a46c Initial revision
claus
parents:
diff changeset
   177
};
48194c26a46c Initial revision
claus
parents:
diff changeset
   178
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   179
static struct ccitt_def
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   180
blackDef[] = {
48194c26a46c Initial revision
claus
parents:
diff changeset
   181
    { 0x0dc0, 10 }, /* 0 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   182
    { 0x4000, 3 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   183
    { 0xc000, 2 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   184
    { 0x8000, 2 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   185
    { 0x6000, 3 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   186
    { 0x3000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   187
    { 0x2000, 4 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   188
    { 0x1800, 5 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   189
    { 0x1400, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   190
    { 0x1000, 6 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   191
    { 0x0800, 7 }, /* 10 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   192
    { 0x0a00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   193
    { 0x0e00, 7 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   194
    { 0x0400, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   195
    { 0x0700, 8 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   196
    { 0x0c00, 9 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   197
    { 0x05c0, 10 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   198
    { 0x0600, 10 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   199
    { 0x0200, 10 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   200
    { 0x0ce0, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   201
    { 0x0d00, 11 }, /* 20 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   202
    { 0x0d80, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   203
    { 0x06e0, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   204
    { 0x0500, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   205
    { 0x02e0, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   206
    { 0x0300, 11 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   207
    { 0x0ca0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   208
    { 0x0cb0, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   209
    { 0x0cc0, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   210
    { 0x0cd0, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   211
    { 0x0680, 12 }, /* 30 */
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   212
    { 0x0690, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   213
    { 0x06a0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   214
    { 0x06b0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   215
    { 0x0d20, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   216
    { 0x0d30, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   217
    { 0x0d40, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   218
    { 0x0d50, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   219
    { 0x0d60, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   220
    { 0x0d70, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   221
    { 0x06c0, 12 }, /* 40 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   222
    { 0x06d0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   223
    { 0x0da0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   224
    { 0x0db0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   225
    { 0x0540, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   226
    { 0x0550, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   227
    { 0x0560, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   228
    { 0x0570, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   229
    { 0x0640, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   230
    { 0x0650, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   231
    { 0x0520, 12 }, /* 50 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   232
    { 0x0530, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   233
    { 0x0240, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   234
    { 0x0370, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   235
    { 0x0380, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   236
    { 0x0270, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   237
    { 0x0280, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   238
    { 0x0580, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   239
    { 0x0590, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   240
    { 0x02b0, 12 },
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   241
    { 0x02c0, 12 }, /* 60 */
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   242
    { 0x05a0, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   243
    { 0x0660, 12 },
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   244
    { 0x0670, 12 },
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   245
/* ---------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   246
    { 0x03c0, 10 }, /* 64 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   247
    { 0x0c80, 12 }, /* 128 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   248
    { 0x0c90, 12 }, /* 192 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   249
    { 0x05b0, 12 }, /* 256 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   250
    { 0x0330, 12 }, /* 320 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   251
    { 0x0340, 12 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   252
    { 0x0350, 12 }, /* 448 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   253
    { 0x0360, 13 }, /* 512 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   254
    { 0x0368, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   255
    { 0x0250, 13 }, /* 640 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   256
    { 0x0258, 13 }, /* 704 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   257
    { 0x0260, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   258
    { 0x0268, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   259
    { 0x0390, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   260
    { 0x0398, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   261
    { 0x03a0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   262
    { 0x03a8, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   263
    { 0x03b0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   264
    { 0x03b8, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   265
    { 0x0290, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   266
    { 0x0298, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   267
    { 0x02a0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   268
    { 0x02a8, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   269
    { 0x02d0, 13 },
48194c26a46c Initial revision
claus
parents:
diff changeset
   270
    { 0x02d8, 13 }, /* 1600 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   271
    { 0x0320, 13 }, /* 1664 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   272
    { 0x0328, 13 }, /* 1728 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   273
/* -------------------------------- */
48194c26a46c Initial revision
claus
parents:
diff changeset
   274
};
48194c26a46c Initial revision
claus
parents:
diff changeset
   275
6761
7307a75477f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6618
diff changeset
   276
static void
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   277
initCCITTTables() {
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   278
    register int cnt, bits, value;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   279
    int nBits, index;
48194c26a46c Initial revision
claus
parents:
diff changeset
   280
48194c26a46c Initial revision
claus
parents:
diff changeset
   281
    if (whiteCountTable != (short *)0) return;
48194c26a46c Initial revision
claus
parents:
diff changeset
   282
48194c26a46c Initial revision
claus
parents:
diff changeset
   283
    whiteCountTable = (short *) malloc(sizeof(short) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   284
    if (! whiteCountTable) return;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   285
    whiteShiftTable = (char *) malloc(sizeof(char) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   286
    if (! whiteShiftTable) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   287
	goto fail1;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   288
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   289
    blackCountTable = (short *) malloc(sizeof(short) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   290
    if (! blackCountTable) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   291
	goto fail2;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   292
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   293
    blackShiftTable = (char *) malloc(sizeof(char) * 8192);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   294
    if (! blackShiftTable) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   295
	free(blackCountTable); blackCountTable = (short *)0;
95
47ac85948d38 asText eliminated
claus
parents: 89
diff changeset
   296
fail2:
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   297
	free(whiteShiftTable); whiteShiftTable = (char *)0;
95
47ac85948d38 asText eliminated
claus
parents: 89
diff changeset
   298
fail1:
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   299
	free(whiteCountTable); whiteCountTable = (short *)0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   300
	return;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   301
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   302
48194c26a46c Initial revision
claus
parents:
diff changeset
   303
    for (index = 0; index < 8192; index++) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   304
	whiteCountTable[index] = -1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   305
	blackCountTable[index] = -1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   306
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   307
48194c26a46c Initial revision
claus
parents:
diff changeset
   308
    for (value = 0; value <= 63; value++) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   309
	nBits = whiteDef[value].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   310
	bits = whiteDef[value].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   311
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   312
	    whiteCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   313
	    whiteShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   314
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   315
	nBits = blackDef[value].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   316
	bits = blackDef[value].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   317
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   318
	    blackCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   319
	    blackShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   320
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   321
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   322
    index = value;
48194c26a46c Initial revision
claus
parents:
diff changeset
   323
48194c26a46c Initial revision
claus
parents:
diff changeset
   324
    for (; value <= 1728; value += 64) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   325
	nBits = whiteDef[index].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   326
	bits = whiteDef[index].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   327
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   328
	    whiteCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   329
	    whiteShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   330
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   331
	nBits = blackDef[index].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   332
	bits = blackDef[index].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   333
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   334
	    blackCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   335
	    blackShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   336
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   337
	index++;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   338
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   339
48194c26a46c Initial revision
claus
parents:
diff changeset
   340
    for (; value <= 2560; value += 64) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   341
	nBits = whiteDef[index].nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   342
	bits = whiteDef[index].bits >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   343
	for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   344
	    whiteCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   345
	    whiteShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   346
	    blackCountTable[bits] = value;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   347
	    blackShiftTable[bits] = nBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   348
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   349
	index++;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   350
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   351
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   352
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   353
static short
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   354
leftBits[] = {
48194c26a46c Initial revision
claus
parents:
diff changeset
   355
     0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF
48194c26a46c Initial revision
claus
parents:
diff changeset
   356
};
48194c26a46c Initial revision
claus
parents:
diff changeset
   357
189
claus
parents: 153
diff changeset
   358
static int
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   359
__decodeCCITTgroup3__(unsigned char *from, unsigned char *to, int len)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   360
{
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   361
    register int cnt;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   362
    register short *countPtr;
48194c26a46c Initial revision
claus
parents:
diff changeset
   363
    register char *shiftPtr;
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   364
    unsigned int bits, bits13;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   365
    int shift, outCount, nBitsLess13;
48194c26a46c Initial revision
claus
parents:
diff changeset
   366
    int outBitOffset;
48194c26a46c Initial revision
claus
parents:
diff changeset
   367
    int nLeft, t;
48194c26a46c Initial revision
claus
parents:
diff changeset
   368
48194c26a46c Initial revision
claus
parents:
diff changeset
   369
    if (! whiteCountTable) initCCITTTables();
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   370
    if (! whiteCountTable) return 0; /* malloc failed */
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   371
48194c26a46c Initial revision
claus
parents:
diff changeset
   372
    countPtr = whiteCountTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
   373
    shiftPtr = whiteShiftTable;
48194c26a46c Initial revision
claus
parents:
diff changeset
   374
    outCount = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   375
    outBitOffset = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   376
    bits = *from++;
48194c26a46c Initial revision
claus
parents:
diff changeset
   377
    bits = (bits << 8) | *from++;
48194c26a46c Initial revision
claus
parents:
diff changeset
   378
    nBitsLess13 = 3;
48194c26a46c Initial revision
claus
parents:
diff changeset
   379
    for (;;) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   380
	bits13 = (bits >> nBitsLess13) & 0x1FFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   381
	cnt = countPtr[bits13];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   382
	if (cnt < 0) return 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   383
	shift = shiftPtr[bits13];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   384
	outCount += cnt;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   385
	if (countPtr == blackCountTable) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   386
	    /* toggle if it was a terminating code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   387
	    if (cnt < 64) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   388
		countPtr = whiteCountTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   389
		shiftPtr = whiteShiftTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   390
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   391
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   392
	    /* draw cnt black bits */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   393
	    if (cnt) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   394
		if (outBitOffset) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   395
		    nLeft = 8 - outBitOffset;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   396
		    if (cnt < nLeft) nLeft = cnt;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   397
		    t = leftBits[nLeft] >> outBitOffset;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   398
		    *to |= t;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   399
		    cnt -= nLeft;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   400
		    outBitOffset += nLeft;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   401
		    if (outBitOffset >= 8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   402
			to++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   403
			outBitOffset -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   404
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   405
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   406
		if (cnt > 256) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   407
		    while ((INT)to & 3) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   408
			*to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   409
			cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   410
		    }
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
   411
#if __POINTER_SIZE__ == 8
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   412
		    while ((INT)to & 7) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   413
			*to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   414
			cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   415
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   416
		    while (cnt >= 64) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   417
			(*(INT *)to) = 0xFFFFFFFFFFFFFFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   418
			to += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   419
			cnt -= 64;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   420
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   421
		    if (cnt >= 32) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   422
			(*(long *)to) = 0xFFFFFFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   423
			to += 4;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   424
			cnt -= 32;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   425
		    }
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
   426
#else
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   427
		    while ((INT)to & 3) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   428
			*to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   429
			cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   430
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   431
		    while (cnt >= 32) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   432
			(*(long *)to) = 0xFFFFFFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   433
			to += 4;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   434
			cnt -= 32;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   435
		    }
4401
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
   436
#endif
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   437
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   438
		while (cnt >= 8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   439
		    *to++ = 0xFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   440
		    cnt -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   441
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   442
		*to |= leftBits[cnt];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   443
		outBitOffset += cnt;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   444
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   445
	} else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   446
	    /* toggle if it was a terminating code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   447
	    if (cnt < 64) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   448
		countPtr = blackCountTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   449
		shiftPtr = blackShiftTable;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   450
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   451
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   452
	    /* skip cnt bits */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   453
	    to += cnt >> 3;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   454
	    outBitOffset += cnt & 7;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   455
	    if (outBitOffset >= 8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   456
		to++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   457
		outBitOffset -= 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   458
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   459
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   460
	if (outCount >= len) return 1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   461
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   462
	nBitsLess13 -= shift;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   463
	while (nBitsLess13 < 0) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   464
	    bits = (bits << 8) | *from++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   465
	    nBitsLess13 += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   466
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   467
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   468
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   469
48194c26a46c Initial revision
claus
parents:
diff changeset
   470
/*
48194c26a46c Initial revision
claus
parents:
diff changeset
   471
 * LZW decompression
48194c26a46c Initial revision
claus
parents:
diff changeset
   472
 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   473
struct buffer {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   474
	struct buffer *prev;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   475
	unsigned char chars[8192 - 4];
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   476
};
189
claus
parents: 153
diff changeset
   477
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   478
static int
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   479
__decodeLZW__(unsigned char *from, unsigned char *to, int inCount, int fromSize, int toSize)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   480
{
48194c26a46c Initial revision
claus
parents:
diff changeset
   481
    register unsigned code;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   482
    unsigned char **strings;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   483
    short *stringLen;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   484
    struct buffer *scratchBuffer;
48194c26a46c Initial revision
claus
parents:
diff changeset
   485
    struct buffer *newBuffer;
48194c26a46c Initial revision
claus
parents:
diff changeset
   486
    unsigned char *scratchPtr;
48194c26a46c Initial revision
claus
parents:
diff changeset
   487
    int nScratch;
1262
61bbba463582 lzw_decode caused a SIGSEGV.
Stefan Vogel <sv@exept.de>
parents: 1175
diff changeset
   488
    unsigned nextCode;
61bbba463582 lzw_decode caused a SIGSEGV.
Stefan Vogel <sv@exept.de>
parents: 1175
diff changeset
   489
    int oldCode = -1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   490
    register unsigned bits;
48194c26a46c Initial revision
claus
parents:
diff changeset
   491
    int nBits, mask, shift;
48194c26a46c Initial revision
claus
parents:
diff changeset
   492
    int i;
48194c26a46c Initial revision
claus
parents:
diff changeset
   493
    int len;
48194c26a46c Initial revision
claus
parents:
diff changeset
   494
    int codeLen = 9;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   495
    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
   496
    int ret = 1;        /* return success */
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   497
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   498
    fromEnd = from + fromSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   499
    toEnd = to + toSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   500
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   501
    scratchBuffer = (struct buffer *)malloc(sizeof(struct buffer));
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   502
    if (! scratchBuffer) return 0;
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   503
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   504
    strings = (unsigned char **)malloc(sizeof(unsigned char *) * 4096);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   505
    if (! strings) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   506
	free(scratchBuffer);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   507
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   508
    }
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   509
    stringLen = (short *)malloc(sizeof(short) * 4096);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   510
    if (! stringLen) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   511
	free(strings);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   512
	free(scratchBuffer);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   513
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   514
    }
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   515
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   516
    scratchBuffer->prev = (struct buffer *)0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   517
    scratchPtr = scratchBuffer->chars;
48194c26a46c Initial revision
claus
parents:
diff changeset
   518
    nScratch = sizeof(scratchBuffer->chars);
48194c26a46c Initial revision
claus
parents:
diff changeset
   519
48194c26a46c Initial revision
claus
parents:
diff changeset
   520
    for (i = 0; i < 256; i++) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   521
	*scratchPtr = i;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   522
	strings[i] = scratchPtr++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   523
	stringLen[i] = 1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   524
    }
48194c26a46c Initial revision
claus
parents:
diff changeset
   525
48194c26a46c Initial revision
claus
parents:
diff changeset
   526
    nextCode = 258;
48194c26a46c Initial revision
claus
parents:
diff changeset
   527
    nScratch -= 256;
48194c26a46c Initial revision
claus
parents:
diff changeset
   528
    mask = 0x1FF;
48194c26a46c Initial revision
claus
parents:
diff changeset
   529
    nBits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   530
    bits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   531
    while (inCount) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   532
	/* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   533
	while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   534
	    bits = (bits<<8) | *from++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   535
	    inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   536
	    nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   537
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   538
	shift = nBits - codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   539
	code = (bits >> shift) & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   540
	bits &= ~(mask << shift);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   541
	nBits -= codeLen;
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   542
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   543
	if (code == 257) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   544
	if (code == 256) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   545
	    if (! inCount)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   546
		break;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   547
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   548
	    /* free stuff */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   549
	    while (scratchBuffer->prev) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   550
		newBuffer = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   551
		scratchBuffer = scratchBuffer->prev;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   552
		free(newBuffer);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   553
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   554
	    /* reset everything */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   555
	    scratchPtr = scratchBuffer->chars + 256;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   556
	    nScratch = sizeof(scratchBuffer->chars) - 256;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   557
	    codeLen = 9;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   558
	    nextCode = 258;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   559
	    mask = 0x1FF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   560
	    /* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   561
	    while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   562
		bits = (bits<<8) | *from++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   563
		inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   564
		nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   565
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   566
	    shift = nBits - codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   567
	    code = (bits >> shift) & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   568
	    bits &= ~(mask << shift);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   569
	    nBits -= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   570
	    if (code == 257) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   571
	    /* add to output */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   572
	    if (to >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   573
		if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   574
		    console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   575
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   576
		ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   577
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   578
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   579
	    *to++ = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   580
	    oldCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   581
	} else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   582
	    if (code < nextCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   583
		/* writeString(string[code]) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   584
		len = stringLen[code];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   585
		bcopy(strings[code], to, len);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   586
		to += len;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   587
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   588
		if (oldCode != -1) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   589
		    /* add( string[oldcode] + first(string[code]) ) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   590
		    len = stringLen[oldCode] + 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   591
		    if (nScratch < len) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   592
			newBuffer = (struct buffer *)malloc(sizeof(struct buffer));
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   593
			if (! newBuffer) goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   594
			newBuffer->prev = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   595
			scratchBuffer = newBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   596
			scratchPtr = scratchBuffer->chars;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   597
			nScratch = sizeof(scratchBuffer->chars);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   598
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   599
		    stringLen[nextCode] = len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   600
		    strings[nextCode] = scratchPtr;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   601
		    bcopy(strings[oldCode], scratchPtr, len-1);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   602
		    scratchPtr += len-1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   603
		    *scratchPtr++ = strings[code][0];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   604
		    nScratch -= len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   605
		    nextCode++;
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
	    } else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   608
		if (oldCode == -1) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   609
		    /* bad input */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   610
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   611
		    goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   612
		}
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
   613
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   614
		/* writeString(string[oldCode] + first(string[oldCode]) ) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   615
		len = stringLen[oldCode];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   616
		if ((to+len) >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   617
		    if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   618
			console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   619
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   620
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   621
		    goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   622
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   623
		bcopy(strings[oldCode], to, len);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   624
		to += len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   625
		*to++ = strings[oldCode][0];
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   626
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   627
		/* add( string[oldcode] + first(string[oldCode]) ) */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   628
		len++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   629
		if (nScratch < len) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   630
		    newBuffer = (struct buffer *)malloc(sizeof(struct buffer));
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   631
		    if (! newBuffer) goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   632
		    newBuffer->prev = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   633
		    scratchBuffer = newBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   634
		    scratchPtr = scratchBuffer->chars;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   635
		    nScratch = sizeof(scratchBuffer->chars);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   636
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   637
		stringLen[nextCode] = len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   638
		strings[nextCode] = scratchPtr;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   639
		bcopy(strings[oldCode], scratchPtr, len-1);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   640
		scratchPtr += len-1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   641
		*scratchPtr++ = strings[oldCode][0];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   642
		nScratch -= len;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   643
		nextCode++;
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
	    oldCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   646
	    if (nextCode >= 511) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   647
		if (nextCode == 511) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   648
		    codeLen = 10;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   649
		    mask = 0x3FF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   650
		} else if (nextCode >= 1023) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   651
		    if (nextCode == 1023) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   652
			codeLen = 11;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   653
			mask = 0x7FF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   654
		    } else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   655
			if (nextCode == 2047) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   656
			    codeLen = 12;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   657
			    mask = 0xFFF;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   658
			}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   659
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   660
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   661
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   662
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   663
    }
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   664
out: ;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   665
    /* free stuff */
48194c26a46c Initial revision
claus
parents:
diff changeset
   666
    while (scratchBuffer) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   667
	newBuffer = scratchBuffer;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   668
	scratchBuffer = scratchBuffer->prev;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   669
	free(newBuffer);
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   670
    }
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   671
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   672
    free(strings);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   673
    free(stringLen);
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   674
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   675
    if (from > fromEnd) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   676
	if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   677
	    console_fprintf(stderr, "ImageReader [warning]: LZW inBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   678
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   679
	ret = 0;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   680
    }
1262
61bbba463582 lzw_decode caused a SIGSEGV.
Stefan Vogel <sv@exept.de>
parents: 1175
diff changeset
   681
    return ret;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   682
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   683
48194c26a46c Initial revision
claus
parents:
diff changeset
   684
/*
48194c26a46c Initial revision
claus
parents:
diff changeset
   685
 * delta decoding (TIFF predictor = 2)
48194c26a46c Initial revision
claus
parents:
diff changeset
   686
 */
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   687
static void
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   688
__decodeDelta__(register unsigned char *bytes, int width, int height)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   689
{
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   690
	register int w;
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   691
	unsigned char r, g, b;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   692
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   693
	while (height--) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   694
	    r = g = b = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   695
	    for (w = width; w; w--) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   696
		r += *bytes;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   697
		*bytes++ = r;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   698
		g += *bytes;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   699
		*bytes++ = g;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   700
		b += *bytes;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   701
		*bytes++ = b;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   702
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   703
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   704
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   705
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   706
/*
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   707
 * GIF decompression
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   708
 */
189
claus
parents: 153
diff changeset
   709
static int
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
   710
__decodeGIF__(unsigned char *from, unsigned char *to, int inCount, int initialCodeLen, int fromSize, int toSize)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   711
{
48194c26a46c Initial revision
claus
parents:
diff changeset
   712
    register unsigned code;
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   713
    // #define GIF_PREFIX_SUFFIX_SIZE 4096
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   714
    #define GIF_PREFIX_SUFFIX_SIZE (4096*2)
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   715
    unsigned short *prefix;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   716
    unsigned short *suffix;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   717
    unsigned short *outCode;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   718
    int outCount;
48194c26a46c Initial revision
claus
parents:
diff changeset
   719
    unsigned maxCode, oldCode, fin, inCode, curCode;
48194c26a46c Initial revision
claus
parents:
diff changeset
   720
    register unsigned bits;
48194c26a46c Initial revision
claus
parents:
diff changeset
   721
    register int nBits, mask, shift;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   722
    int ret = 1;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   723
    int i;
48194c26a46c Initial revision
claus
parents:
diff changeset
   724
    int len;
48194c26a46c Initial revision
claus
parents:
diff changeset
   725
    int endCode, clearCode, freeCode;
48194c26a46c Initial revision
claus
parents:
diff changeset
   726
    int codeLen = initialCodeLen;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   727
    unsigned char *fromEnd, *toEnd;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   728
    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
   729
			   128, 256, 512, 1024, 2048 };
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   730
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   731
    fromEnd = from + fromSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   732
    toEnd = to + toSize;
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   733
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
   734
    if ((unsigned)codeLen > 12) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   735
	if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   736
	    console_fprintf(stderr, "ImageReader [warning]: GIF bad codelen (>12)\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   737
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   738
	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
   739
    }
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   740
    prefix = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   741
    if (! prefix) return 0;
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   742
    suffix  = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   743
    if (! suffix) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   744
	free(prefix);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   745
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   746
    }
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   747
    outCode = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   748
    if (! outCode) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   749
	free(prefix);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   750
	free(suffix);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   751
	return 0;
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   752
    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   753
    clearCode = ranges[codeLen]; /* 256 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   754
    endCode = clearCode + 1;     /* 257 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   755
    freeCode = clearCode + 2;    /* 258 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   756
    maxCode = clearCode << 1;    /* 512 */
48194c26a46c Initial revision
claus
parents:
diff changeset
   757
    outCount = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   758
48194c26a46c Initial revision
claus
parents:
diff changeset
   759
    mask = maxCode - 1;          /* 1FF */
48194c26a46c Initial revision
claus
parents:
diff changeset
   760
    nBits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   761
    bits = 0;
48194c26a46c Initial revision
claus
parents:
diff changeset
   762
    while (inCount) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   763
	/* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   764
	while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   765
	    bits = bits | (*from++ << nBits);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   766
	    inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   767
	    nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   768
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   769
	if (inCount <= 0)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   770
	    break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   771
	code = bits & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   772
	bits >>= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   773
	nBits -= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   774
	if (code == endCode) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   775
	if (code == clearCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   776
	    if (inCount <= 0)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   777
		break;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   778
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   779
	    codeLen = initialCodeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   780
	    maxCode = clearCode<<1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   781
	    mask = maxCode - 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   782
	    freeCode = clearCode + 2;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   783
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   784
	    /* fetch code */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   785
	    while (nBits < codeLen) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   786
		bits = bits | (*from++ << nBits);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   787
		inCount--;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   788
		nBits += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   789
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   790
	    if (inCount <= 0)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   791
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   792
	    code = bits & mask;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   793
	    bits >>= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   794
	    nBits -= codeLen;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   795
	    if (code == endCode) break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   796
	    /* add to output */
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   797
	    if (to >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   798
		if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   799
		    console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n");
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
		ret = 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
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   804
	    *to++ = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   805
	    oldCode = fin = curCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   806
	} else {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   807
	    curCode = inCode = code;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   808
	    if (curCode >= freeCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   809
		curCode = oldCode;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   810
		outCode[outCount++] = fin;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   811
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   812
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   813
	    while (curCode >= clearCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   814
		if (outCount > 1024) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   815
		    goto out;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   816
		}
2261
740be162343e check to avoid overwriting
Claus Gittinger <cg@exept.de>
parents: 2152
diff changeset
   817
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   818
		/* debugging and protecting myself from overwrites */
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   819
		if (curCode > (GIF_PREFIX_SUFFIX_SIZE-1)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   820
		    if (@global(InfoPrinting) == true) {
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   821
			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
   822
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   823
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   824
		    break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   825
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   826
		outCode[outCount++] = suffix[curCode];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   827
		curCode = prefix[curCode];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   828
	    }
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   829
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   830
	    fin = curCode;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   831
	    outCode[outCount++] = fin;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   832
2014
bcae1c2c32e4 fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents: 1988
diff changeset
   833
#if 0
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   834
	    if ((to+outCount) >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   835
		if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   836
		    console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   837
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   838
		ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   839
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   840
	    }
2014
bcae1c2c32e4 fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents: 1988
diff changeset
   841
#endif
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   842
	    for (i = outCount - 1; i >= 0; i--) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   843
		if (to >= toEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   844
		    if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   845
			console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   846
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   847
		    ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   848
		    break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   849
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   850
		*to++ = outCode[i];
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   851
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   852
	    outCount = 0;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   853
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   854
	    /* debugging and protecting myself from overwrites */
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   855
	    if (freeCode > (GIF_PREFIX_SUFFIX_SIZE-1)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   856
		if (@global(InfoPrinting) == true) {
7894
16136333fe33 increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents: 7859
diff changeset
   857
		    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
   858
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   859
		ret = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   860
		break;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   861
	    }
2261
740be162343e check to avoid overwriting
Claus Gittinger <cg@exept.de>
parents: 2152
diff changeset
   862
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   863
	    prefix[freeCode] = oldCode;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   864
	    suffix[freeCode] = fin;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   865
	    oldCode = inCode;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   866
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   867
	    freeCode++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   868
	    if (freeCode >= maxCode) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   869
		if (codeLen < 12) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   870
		    codeLen++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   871
		    maxCode *= 2;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   872
		    mask = (1 << codeLen) - 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   873
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   874
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   875
	}
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   876
    }
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   877
out: ;
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   878
    free(prefix);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   879
    free(suffix);
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   880
    free(outCode);
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   881
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   882
    if (from > fromEnd) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   883
	if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   884
	    console_fprintf(stderr, "ImageReader [warning]: GIF inBuffer overrun\n");
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   885
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   886
	ret = 0;
1988
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   887
    }
528dbff6ca26 do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   888
    return ret;
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   889
}
48194c26a46c Initial revision
claus
parents:
diff changeset
   890
48194c26a46c Initial revision
claus
parents:
diff changeset
   891
%}
77
da4678fae5c8 *** empty log message ***
claus
parents: 72
diff changeset
   892
! !
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   893
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   894
!ImageReader class methodsFor:'documentation'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   895
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   896
copyright
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   897
"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   898
 COPYRIGHT (c) 1991 by Claus Gittinger
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   899
	      All Rights Reserved
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   900
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   901
 This software is furnished under a license and may be used
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   902
 only in accordance with the terms of that license and with the
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   903
 inclusion of the above copyright notice.   This software may not
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   904
 be provided or otherwise made available to, or used by, any
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   905
 other person.  No title to or ownership of the software is
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   906
 hereby transferred.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   907
"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   908
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   909
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   910
documentation
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   911
"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   912
    Abstract class to provide common functions for image-readers/writers.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   913
    (i.e. TIFFReader, GIFReader etc.).
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   914
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   915
    In contrast to what the name suggests, ImageReaders are supposed to support
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   916
    both reading and writing of images
6058
7c5c40861f50 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6057
diff changeset
   917
    (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
   918
    compatibility reasons).
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   919
    They provide functionality similar to Squeak's ImageReaderWriter classes.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   920
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   921
    ImageReaders are created temporary to read an image from a stream.
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   922
    Normally, they are not directly used - instead, the image class is
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   923
    asked to read some file, and return an instance for it:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   924
	Image fromFile:<someFileName>
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   925
    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
   926
    some concrete ImageReaderClass.
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
   927
    If that class thinks, that the file's format is incorrect,
6508
589f02f1a068 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6377
diff changeset
   928
    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
   929
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   930
    Image readers read the stream and collect all relevant information internally.
118
25e775072a89 *** empty log message ***
claus
parents: 105
diff changeset
   931
    Once done with reading, the actual image object is created and
25e775072a89 *** empty log message ***
claus
parents: 105
diff changeset
   932
    data filled in from the imageReaders collected info.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   933
618
5d5277119897 commentart
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   934
    See the implementation of #fromStream: in concrete subclasses.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   935
    The public interfaces are:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   936
	 <ConcreteReaderClass> fromFile:aFilename
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   937
    or:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   938
	 <ConcreteReaderClass> fromStream:aStream
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   939
6058
7c5c40861f50 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6057
diff changeset
   940
    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
   941
    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
   942
7c5c40861f50 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6057
diff changeset
   943
    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
   944
    #canRepresent:anImage and return true from this method.
593
a3264954cf83 commentary
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   945
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
   946
    writing:
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   947
	tell the image, to save itself, via <image> saveOn:fileName
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   948
	or <image> saveOn:fileName using:<readerClass>
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   949
593
a3264954cf83 commentary
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   950
    [See also:]
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   951
	Image Icon Form
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   952
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   953
    [author:]
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
   954
	Claus Gittinger
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   955
"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   956
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   957
1358
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   958
!ImageReader class methodsFor:'instance creation'!
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   959
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   960
new
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   961
    ^ self basicNew initialize
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   962
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   963
    "Created: 18.2.1997 / 17:08:45 / cg"
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   964
! !
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
   965
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   966
!ImageReader class methodsFor:'cleanup'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   967
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   968
lowSpaceCleanup
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   969
    "cleanup things we do not need"
118
25e775072a89 *** empty log message ***
claus
parents: 105
diff changeset
   970
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   971
    ReverseBits := nil
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   972
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   973
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   974
!ImageReader class methodsFor:'constants'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   975
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   976
reverseBits
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   977
    "return a table filled with bit reverse information.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   978
     To convert from msbit-first to lsbit-first bytes, use
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   979
     the value as index into the table, retrieving the reverse
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   980
     value. Since indexing must start at 1, use (value + 1) as
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   981
     index."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   982
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   983
    |val "{ Class: SmallInteger }" |
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   984
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   985
    ReverseBits isNil ifTrue:[
153
claus
parents: 134
diff changeset
   986
	ReverseBits := ByteArray uninitializedNew:256.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   987
	0 to:255 do:[:i |
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   988
	    val := 0.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   989
	    (i bitTest:16r01) ifTrue:[val := val bitOr:16r80].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   990
	    (i bitTest:16r02) ifTrue:[val := val bitOr:16r40].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   991
	    (i bitTest:16r04) ifTrue:[val := val bitOr:16r20].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   992
	    (i bitTest:16r08) ifTrue:[val := val bitOr:16r10].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   993
	    (i bitTest:16r10) ifTrue:[val := val bitOr:16r08].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   994
	    (i bitTest:16r20) ifTrue:[val := val bitOr:16r04].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   995
	    (i bitTest:16r40) ifTrue:[val := val bitOr:16r02].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   996
	    (i bitTest:16r80) ifTrue:[val := val bitOr:16r01].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   997
	    ReverseBits at:(i + 1) put:val
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   998
	]
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
   999
    ].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1000
    ^ ReverseBits
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1001
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1002
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1003
!ImageReader class methodsFor:'decompression support'!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1004
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1005
decodeDelta:step in:data width:width height:height
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1006
    "perform NeXT special predictor delta decoding inplace in data.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1007
     Calls primitive c function for speed"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1008
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1009
    (step ~~ 3) ifTrue:[
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1010
	^ self error:'only rgb pictures supported'
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1011
    ].
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1012
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1013
%{
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1014
    if (__isByteArray(data)
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1015
     && __bothSmallInteger(width, height)) {
2043
7b8d741538a0 single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents: 2039
diff changeset
  1016
	__decodeDelta__(__ByteArrayInstPtr(data)->ba_element,
2044
9ea84b4ba249 more single-underline macros
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
  1017
		    __intVal(width), __intVal(height));
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1018
	RETURN ( self );
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1019
    }
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1020
%}
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1021
.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1022
    self primitiveFailed
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1023
!
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1024
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1025
decompressCCITT3From:srcBytes into:dstBytes startingAt:offset count:count
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1026
    "decompress CCITT Group 3 compressed image data.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1027
     count bytes from srcBytes are decompressed into dstBytes.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1028
     Calls primitive c function for speed"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1029
%{
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  1030
    if (__isByteArrayLike(srcBytes)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1031
     && __isByteArray(dstBytes)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1032
     && __bothSmallInteger(offset, count)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1033
	if (__decodeCCITTgroup3__(__ByteArrayInstPtr(srcBytes)->ba_element,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1034
				  __ByteArrayInstPtr(dstBytes)->ba_element
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1035
				  + __intVal(offset) - 1,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1036
				  __intVal(count))) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1037
	    RETURN ( self );
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1038
	}
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1039
    }
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1040
%}
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1041
.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1042
    self primitiveFailed
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1043
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1044
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1045
decompressGIFFrom:srcBytes count:count into:dstBytes startingAt:offset codeLen:codeLen
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1046
    "decompress GIF compressed image data.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1047
     count bytes from srcBytes are decompressed into dstBytes.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1048
     Calls primitive c function for speed"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1049
%{
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  1050
    if (__isByteArrayLike(srcBytes)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1051
     && __isByteArray(dstBytes)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1052
     && __bothSmallInteger(codeLen, offset)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1053
     && __isSmallInteger(count)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1054
	if (__decodeGIF__(__ByteArrayInstPtr(srcBytes)->ba_element,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1055
			  __ByteArrayInstPtr(dstBytes)->ba_element
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1056
						+__intVal(offset) - 1,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1057
			  __intVal(count),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1058
			  __intVal(codeLen),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1059
			  __byteArraySize(srcBytes),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1060
			  __byteArraySize(dstBytes)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1061
			 )) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1062
	    RETURN ( self );
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1063
	}
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1064
    }
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1065
%}
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1066
.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1067
    self primitiveFailed
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1068
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1069
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1070
decompressLZWFrom:srcBytes count:count into:dstBytes startingAt:offset
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1071
    "decompress LZW (tiff) compressed image data.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1072
     count bytes from srcBytes are decompressed into dstBytes.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1073
     Calls primitive c function for speed"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1074
%{
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  1075
    if (__isByteArrayLike(srcBytes)
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1076
     && __isByteArray(dstBytes)
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1077
     && __bothSmallInteger(offset, count)) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1078
	if (__decodeLZW__(__ByteArrayInstPtr(srcBytes)->ba_element,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1079
			  __ByteArrayInstPtr(dstBytes)->ba_element
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1080
					      + __intVal(offset) - 1,
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1081
			  __intVal(count),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1082
			  __byteArraySize(srcBytes),
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1083
			  __byteArraySize(dstBytes)
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1084
			)) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1085
	    RETURN ( self );
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1086
	}
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1087
    }
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1088
%}
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1089
.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1090
    self primitiveFailed
189
claus
parents: 153
diff changeset
  1091
!
claus
parents: 153
diff changeset
  1092
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1093
decompressPackBits:nIn from:srcBytes to:dstBytes startingAt:dstOffset
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1094
    "decompress a number of input bytes.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1095
     Used by tiff and some mac image formats.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1096
     Return the number of decompressed output bytes."
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1097
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1098
    |i b n v dstOffs|
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1099
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1100
    dstOffs := dstOffset.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1101
    i := 1.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1102
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1103
    [i <= nIn] whileTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1104
	b := srcBytes at:i.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1105
	i := i + 1.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1106
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1107
	b ~~ 16rFF ifTrue:[   "/ not a NOP
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1108
	    b <= 127 ifTrue:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1109
		"/ 0..127 literal bytes
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1110
		n := b + 1.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1111
		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
  1112
		i := i + n.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1113
	    ] ifFalse:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1114
		"/ 128..254 a run
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1115
		n := b - 125.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1116
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1117
		v := srcBytes at:i.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1118
		i := i + 1.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1119
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1120
		dstBytes from:dstOffs to:dstOffs+n put:v.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1121
	    ].
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1122
	    dstOffs := dstOffs + n.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1123
	]
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1124
    ].
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1125
    ^ dstOffs - dstOffset
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1126
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1127
    "Created: / 1.12.1997 / 18:39:23 / cg"
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1128
    "Modified: / 1.12.1997 / 18:49:58 / cg"
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1129
!
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1130
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1131
decompressPackBitsFrom:srcBytes at:srcStart to:dstBytes at:dstStart count:outCount
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1132
    "decompress until a number of output bytes has been decompressed.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1133
     Used by some mac image formats.
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1134
     Return the number of processed input bytes.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1135
     This DOES TREAT FF as a noop."
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1136
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1137
    |i b n v dstOffs nRemaining|
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1138
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1139
    dstOffs := dstStart.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1140
    i := srcStart.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1141
    nRemaining := outCount.
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1142
    [nRemaining > 0] whileTrue:[
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1143
        b := srcBytes at:i.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1144
        i := i + 1.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1145
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1146
        "/ mhmh - other packbits decoders seem to treat FF as a noop
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1147
        "/ here, we do. 
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1148
        b ~~ 16rFF ifTrue:[   "/ not a NOP
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1149
            b <= 127 ifTrue:[
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1150
                "/ 0..127: 1..128 literal bytes
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1151
                n := b + 1.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1152
                dstBytes replaceFrom:dstOffs to:dstOffs+b with:srcBytes startingAt:i.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1153
                nRemaining := nRemaining - n.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1154
                i := i + n.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1155
            ] ifFalse:[
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1156
                "/ 128..255 a run of length 3..130
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1157
                n := b - 125.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1158
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1159
                v := srcBytes at:i.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1160
                i := i + 1.
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1161
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1162
                dstBytes from:dstOffs to:dstOffs+n-1 put:v.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1163
                nRemaining := nRemaining - n.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1164
            ].
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1165
            dstOffs := dstOffs + n.
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1166
        ] ifFalse:[
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1167
            self halt
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1168
        ].    
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1169
    ].
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1170
    ^ i-srcStart
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  1171
7926
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1172
    "Modified: / 22-02-2017 / 12:05:50 / cg"
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1173
!
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1174
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1175
decompressPackBitsV2From:srcBytes at:srcStart to:dstBytes at:dstStart count:outCount
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1176
    "decompress until a number of output bytes has been decompressed.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1177
     Used by some mac image formats.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1178
     Return the number of processed input bytes.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1179
     This does NOT treat FF as a noop."
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1180
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1181
    |i b n v dstOffs nRemaining|
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1182
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1183
    dstOffs := dstStart.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1184
    i := srcStart.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1185
    nRemaining := outCount.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1186
    [nRemaining > 0] whileTrue:[
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1187
        b := srcBytes at:i.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1188
        i := i + 1.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1189
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1190
        "/ mhmh - other packbits decoders seem to treat FF as a noop
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1191
        "/ here, we do not. 
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1192
        true "b ~~ 16rFF" ifTrue:[   "/ not a NOP
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1193
            b <= 127 ifTrue:[
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1194
                "/ 0..127: 1..128 literal bytes
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1195
                n := b + 1.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1196
                dstBytes replaceFrom:dstOffs to:dstOffs+b with:srcBytes startingAt:i.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1197
                nRemaining := nRemaining - n.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1198
                i := i + n.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1199
            ] ifFalse:[
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1200
                "/ 128..255 a run of length 3..130
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1201
                n := b - 125.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1202
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1203
                v := srcBytes at:i.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1204
                i := i + 1.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1205
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1206
                dstBytes from:dstOffs to:dstOffs+n-1 put:v.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1207
                nRemaining := nRemaining - n.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1208
            ].
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1209
            dstOffs := dstOffs + n.
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1210
        ] ifFalse:[
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1211
            self halt
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1212
        ].    
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1213
    ].
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1214
    ^ i-srcStart
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1215
b83ef852a991 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7925
diff changeset
  1216
    "Created: / 22-02-2017 / 12:05:26 / cg"
6585
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1217
!
6fc5ec1f3398 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6508
diff changeset
  1218
1648
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1219
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
  1220
    "common helper to expand RLE encoded data"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1221
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1222
    "/ 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
  1223
    "/ 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
  1224
    "/ 1 means: count verbatim bytes follow;
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1225
    "/ 0 means: repeat the next byte count times.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1226
    "/ Decoding stops when a 0-count is encountered.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1227
    "/ srcBytes and dstBytes should not overlap.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1228
    "/ 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
  1229
    "/
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1230
    "/ 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
  1231
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1232
    |srcIdx "{Class: SmallInteger }"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1233
     dstIdx "{Class: SmallInteger }"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1234
     pixel  "{Class: SmallInteger }"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1235
     count  "{Class: SmallInteger }"|
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1236
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1237
    srcIdx := srcStartIndex.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1238
    dstIdx := dstStartIndex.
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1239
    [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
  1240
	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
  1241
	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
  1242
	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
  1243
	    ^ self
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1244
	].
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1245
	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
  1246
	(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
  1247
	    "/ run bytes
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1248
	    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
  1249
	    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
  1250
	    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
  1251
		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
  1252
		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
  1253
	    ] ifFalse:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1254
		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
  1255
		    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
  1256
		    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
  1257
		]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1258
	    ]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1259
	] ifFalse:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1260
	    "/ verbatim bytes
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1261
	    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
  1262
		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
  1263
		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
  1264
		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
  1265
	    ] ifFalse:[
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1266
		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
  1267
		    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
  1268
		    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
  1269
		    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
  1270
		]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1271
	    ]
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1272
	]
1648
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1273
    ].
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1274
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1275
    "Modified: 23.4.1997 / 18:54:05 / cg"
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1276
!
cbb3f0d60617 prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents: 1633
diff changeset
  1277
7501
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1278
swap:nBytes bytesFromRGBA_to_BGRA_in:data startingAt:startIndex
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1279
    "swap bytes from RGBA into BGRA order.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1280
     The argument is a pixel data buffer (byteArray)"
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1281
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1282
    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
  1283
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1284
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1285
     |bytes|
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1286
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1287
     bytes := #[ 0 1 2 3 4 5 6 7 8 9 ].
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1288
     self swap:6 bytesFromRGB_to_BGR_in:bytes startingAt:1.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1289
     bytes.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1290
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1291
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1292
     |bytes|
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1293
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1294
     bytes := ByteArray new:1000000.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1295
     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
  1296
     Time millisecondsToRun:[
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
  1297
	self swap:1000000 bytesFromRGB_to_BGR_in:bytes.
7501
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1298
     ].
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1299
     bytes copyTo:10.
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1300
    "
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1301
!
ddcd558eda4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7375
diff changeset
  1302
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1303
swap:nBytes bytesFromRGB_to_BGR_in:data
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1304
    "swap bytes from RGB into BGR order.
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1305
     The argument is a pixel data buffer (byteArray)"
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1306
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1307
    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
  1308
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1309
    "
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1310
     |bytes|
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1311
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1312
     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
  1313
     self swap:6 bytesFromRGB_to_BGR_in:bytes.
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1314
     bytes.
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1315
    "
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1316
    "
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1317
     |bytes|
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1318
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1319
     bytes := ByteArray new:1000000.
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1320
     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
  1321
     Time millisecondsToRun:[
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
  1322
	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
  1323
     ].
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1324
     bytes copyTo:10.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1325
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1326
!
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1327
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1328
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
  1329
    "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
  1330
     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
  1331
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1332
    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
  1333
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1334
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1335
     |bytes|
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1336
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1337
     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
  1338
     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
  1339
     bytes.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1340
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1341
    "
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1342
     |bytes|
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1343
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1344
     bytes := ByteArray new:1000000.
1f80ff25b6a5 BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
  1345
     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
  1346
     Time millisecondsToRun:[
7539
cf0fed88ba16 warnings eliminated
Claus Gittinger <cg@exept.de>
parents: 7501
diff changeset
  1347
	self swap:1000000 bytesFromRGB_to_BGR_in:bytes.
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1348
     ].
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1349
     bytes copyTo:10.
3835
8b203fa57396 swap_RGB_BGR support
Claus Gittinger <cg@exept.de>
parents: 3605
diff changeset
  1350
    "
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1351
!
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1352
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1353
swap:count pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:bpp
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1354
    "swap bytes from RGB into BGR order.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1355
     The argument is a pixel data buffer (byteArray).
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1356
     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
  1357
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1358
    |t idx|
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1359
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1360
%{  /* OPTIONAL */
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1361
    if (__isByteArray(data)
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1362
     && __isSmallInteger(count)
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1363
     && __isSmallInteger(startIndex)
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1364
     && __isSmallInteger(bpp)) {
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1365
	INT __count = __intVal(count);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1366
	INT __startOffset = __intVal(startIndex) - 1;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1367
	INT __dataSize = __byteArraySize(data);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1368
	int __bpp = __intVal(bpp);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1369
	INT __nBytes = __count * __bpp;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1370
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1371
	if ((__startOffset + __nBytes) <= __dataSize) {
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1372
	    unsigned char *__cp = __ByteArrayInstPtr(data)->ba_element + __startOffset;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1373
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1374
	    while (__count-- > 0) {
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1375
		unsigned char __t;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1376
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1377
		__t = __cp[0];
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1378
		__cp[0] = __cp[2];
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1379
		__cp[2] = __t;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1380
		__cp += __bpp;
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1381
	    }
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1382
	    RETURN (true);
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1383
	}
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1384
    }
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1385
%}.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1386
    idx := startIndex.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1387
    1 to:count do:[:i |
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1388
	t := data at:idx.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1389
	data at:idx put:(data at:idx+2).
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1390
	data at:idx+2 put:t.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1391
	idx := idx + bpp.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1392
    ].
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1393
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1394
    "
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1395
     |bytes|
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1396
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1397
     bytes := #[ 0 1 2  3 4 5  6 7 8  9 ].
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1398
     self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:3.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1399
     bytes.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1400
    "
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1401
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1402
    "
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1403
     |bytes|
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1404
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1405
     bytes := #[ 0 1 2 3  4 5 6 7  8 9 ].
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1406
     self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:4.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1407
     bytes.
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1408
    "
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1409
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1410
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1411
!ImageReader class methodsFor:'i/o support'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1412
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1413
streamReadingFile:aFilename
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1414
    "return a stream to read aFilename.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1415
     If the filename ends with '.Z' or '.gz', return a stream
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1416
     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
  1417
     the file directly."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1418
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1419
    |inStream name fn|
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1420
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1421
    name := aFilename asString.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1422
    ((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
  1423
	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
  1424
	inStream := PipeStream readingFrom:'gunzip < ' , fn.
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1425
    ] ifFalse:[
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  1426
	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
  1427
	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
  1428
	    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
  1429
	]
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1430
    ].
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1431
    inStream isNil ifTrue:[
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1432
	'ImageReader [warning]: open error on: ' infoPrint. aFilename infoPrintCR.
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1433
    ].
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1434
    ^ inStream
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
  1435
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1436
    "Modified: 31.1.1997 / 10:37:24 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1437
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1438
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1439
!ImageReader class methodsFor:'image reading'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1440
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1441
fromBytes:aByteArray
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1442
    "read an image (in my format) from aByteArray.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1443
     Return the image or nil (if unrecognized format or error)"
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1444
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1445
    |reader|
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1446
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1447
    reader := self readStream:aByteArray readStream.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1448
    ^ reader image
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1449
!
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1450
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1451
fromFile:aFileName
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1452
    "read an image (in my format) from aFileName.
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1453
     Return the image or nil on error."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1454
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1455
    |reader|
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1456
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1457
    reader := self readFile:aFileName.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1458
    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
  1459
	^ reader image
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1460
    ].
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1461
    ^ nil
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1462
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1463
    "
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1464
     XBMReader fromFile:'bitmaps/SBrowser.xbm'
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  1465
     XPMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  1466
     XBMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
  1467
    "
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
  1468
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1469
    "Modified: 4.4.1997 / 22:09:49 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1470
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1471
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1472
fromStream:aStream
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1473
    "read an image (in my format) from aStream.
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1474
     Return the image or nil (if unrecognized format or error).
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1475
     The stream remains open."
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1476
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1477
    |reader|
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1478
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1479
    reader := self readStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1480
    ^ reader image
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1481
!
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1482
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1483
fromURL:url
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1484
    "read an image (in my format) from url.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1485
     Return the image or nil (if unrecognized format or error)"
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1486
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1487
    |readerClass response|
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1488
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1489
    self == ImageReader ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1490
	"select a reader supporting this file format"
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1491
	readerClass := self readerClassForFilename:url asURL path.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1492
	readerClass ~~ self ifTrue:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1493
	    ^ readerClass fromURL:url.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1494
	].
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1495
    ].
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1496
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1497
    response := HTTPInterface get:url.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1498
    response isErrorResponse ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1499
	self error:'failed to read url' mayProceed:true.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1500
	^ nil
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1501
    ].
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1502
    ^ self fromBytes:(response data).
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1503
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1504
    "
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1505
     self fromURL:'http://www.lutece.paris.fr/tech/images/helloworld.png'
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1506
    "
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1507
!
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1508
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1509
imagesFromFile:aFileName
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1510
    "read all images (in my format) from aFileName.
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1511
     Return a collection of images or nil on error.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1512
     Not all reader may support multiple images."
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1513
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1514
    |reader|
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1515
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1516
    reader := self readFile:aFileName.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1517
    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
  1518
	^ reader images
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1519
    ].
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1520
    ^ nil
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1521
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1522
    "Modified: 4.4.1997 / 22:11:01 / cg"
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1523
!
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1524
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1525
imagesFromStream:aStream
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1526
    "read all images (in my format) from aStream.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1527
     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
  1528
     The stream remains open.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1529
     Not all reader may support multiple images."
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1530
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1531
    |reader|
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1532
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1533
    reader := self new.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1534
    reader inStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1535
    reader fromStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1536
    ^ reader images
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1537
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1538
    "Modified: 4.4.1997 / 22:11:40 / cg"
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1539
!
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1540
4912
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  1541
readFile:aFilename
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  1542
    "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
  1543
     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
  1544
     so it can be asked with 'reader image')."
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1545
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1546
    |readerClass reader inStream|
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1547
4912
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  1548
    self == ImageReader ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1549
	"select a reader supporting this file format"
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1550
	readerClass := self readerClassForFilename:aFilename.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1551
	readerClass ~~ self ifTrue:[
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1552
	    ^ readerClass readFile:aFilename.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1553
	].
4912
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  1554
    ].
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  1555
b2fd9c2d5e11 #fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents: 4776
diff changeset
  1556
    inStream := self streamReadingFile:aFilename.
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1557
    inStream isNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1558
	'ImageReader [warning]: file open error' errorPrintCR.
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1559
	^ nil
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1560
    ].
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1561
    reader := self new.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1562
    reader inStream:inStream.
3489
60e6b6ded0b3 close inStream on unwind
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
  1563
    [
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1564
	reader fromStream:inStream.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3489
diff changeset
  1565
    ] ensure:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1566
	inStream close.
3489
60e6b6ded0b3 close inStream on unwind
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
  1567
    ].
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1568
    ^ reader
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1569
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1570
    "
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1571
     XPMReader readFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1572
     (XPMReader readFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm') image
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1573
    "
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1574
5737
f39cc6dc9848 raise different error in #readFile: for unsupported filetypes
Claus Gittinger <cg@exept.de>
parents: 5567
diff changeset
  1575
    "Modified: / 04-04-2011 / 14:16:56 / cg"
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1576
!
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1577
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1578
readStream:aStream
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1579
    "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
  1580
     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
  1581
     so it can be asked with 'reader image').
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1582
     The stream remains open."
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1583
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1584
    |reader|
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1585
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1586
    reader := self new.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1587
    reader fromStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1588
    ^ reader
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1589
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1590
    "Created: 4.4.1997 / 22:08:13 / cg"
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1591
!
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1592
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1593
readerClassForFilename:aStringOrFilename
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1594
    "return a reader class, determined by the file's name"
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1595
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1596
    |mime reader|
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1597
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1598
    mime := aStringOrFilename asFilename mimeTypeFromName.
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1599
    mime isNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1600
	mime := aStringOrFilename asFilename mimeTypeOfContents.
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1601
    ].
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1602
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1603
    mime notNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1604
	reader := MIMETypes imageReaderForType:mime.
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1605
    ].
6167
baa4c9ec056a class: ImageReader
Stefan Vogel <sv@exept.de>
parents: 6062
diff changeset
  1606
    reader isNil ifTrue:[
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1607
	"answer the reader when proceeding form this error"
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1608
	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
  1609
    ].
baa4c9ec056a class: ImageReader
Stefan Vogel <sv@exept.de>
parents: 6062
diff changeset
  1610
    ^ reader
6060
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1611
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1612
    "
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1613
     self readerClassForFilename:('http://www.foo.bar/helloworld.png' asURL path)
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1614
     self readerClassForFilename:('http://www.foo.bar/helloworld.gif' asURL path)
96649bbbab0c class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6058
diff changeset
  1615
    "
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1616
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1617
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1618
!ImageReader class methodsFor:'image support'!
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1619
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1620
buildMaskFromColor:maskPixelValue for:pixels width:width height:height
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1621
    "helper for image formats, where an individual pixel value
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1622
     has been defined as a mask-pixel (i.e. GIF).
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1623
     Creates a maskImage, with zeros at positions where the image
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1624
     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
  1625
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1626
    |maskArray bytesPerMaskRow mask|
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1627
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1628
    bytesPerMaskRow := (width+7) // 8.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1629
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1630
    maskArray := ByteArray uninitializedNew:bytesPerMaskRow * height.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1631
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1632
%{
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1633
    int __w = __intVal(width);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1634
    int __h = __intVal(height);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1635
    int __x, __y;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1636
    int __outBits, __nOut;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1637
    unsigned char *__inP, *__outP, *__nextOutRow;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1638
    int __bpr = __intVal(bytesPerMaskRow);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1639
    int __maskPixel = __intVal(maskPixelValue);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1640
#ifdef DEBUG
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1641
    unsigned char *outEnd;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1642
#endif
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1643
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  1644
    if (! __isByteArrayLike(pixels)) goto fail;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1645
    if (! __isByteArray(maskArray)) goto fail;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1646
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1647
    __inP = __ByteArrayInstPtr(pixels)->ba_element;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1648
    __outP = __ByteArrayInstPtr(maskArray)->ba_element;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1649
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1650
#ifdef DEBUG
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1651
    outEnd = __outP + (__byteArraySize(maskArray));
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1652
#endif
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1653
/*
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1654
printf("outP: %x outEnd: %x sz: %d\n", __outP, outEnd, __byteArraySize(maskArray));
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1655
*/
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1656
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1657
    for (__y=__h; __y>0; __y--) {
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1658
	__outBits = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1659
	__nOut = 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1660
	__nextOutRow = __outP + __bpr;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1661
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1662
	for (__x=__w; __x>=8; __x-=8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1663
	    if (__inP[0] != __maskPixel) { __outBits |= 0x80; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1664
	    if (__inP[1] != __maskPixel) { __outBits |= 0x40; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1665
	    if (__inP[2] != __maskPixel) { __outBits |= 0x20; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1666
	    if (__inP[3] != __maskPixel) { __outBits |= 0x10; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1667
	    if (__inP[4] != __maskPixel) { __outBits |= 0x08; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1668
	    if (__inP[5] != __maskPixel) { __outBits |= 0x04; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1669
	    if (__inP[6] != __maskPixel) { __outBits |= 0x02; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1670
	    if (__inP[7] != __maskPixel) { __outBits |= 0x01; };
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1671
	    __inP += 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1672
	    *__outP++ = __outBits;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1673
	    __outBits = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1674
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1675
	for (; __x>0; __x--) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1676
	    __outBits <<= 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1677
	    if (*__inP != __maskPixel) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1678
		__outBits |= 1;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1679
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1680
	    __inP++;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1681
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1682
/*
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1683
 printf("x: %d  bits: %x\n", __x, __outBits);
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1684
*/
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1685
	    if (--__nOut == 0) {
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1686
#ifdef DEBUG
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1687
		if (__outP >= outEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1688
		    if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1689
			console_fprintf(stderr, "oops %d\n", __LINE__);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1690
		    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1691
		    goto fail;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1692
		}
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1693
#endif
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1694
		*__outP = __outBits;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1695
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1696
		__outP++;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1697
		__nOut = 8;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1698
		__outBits = 0;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1699
	    }
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1700
	}
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1701
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1702
	if (__nOut != 8) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1703
	    __outBits <<= __nOut;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1704
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1705
#ifdef DEBUG
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1706
	    if (__outP >= outEnd) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1707
		if (@global(InfoPrinting) == true) {
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1708
		    console_fprintf(stderr, "oops2 %d\n", __LINE__);
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1709
		}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1710
		goto fail;
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1711
	    }
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1712
#endif
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1713
	    *__outP = __outBits;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1714
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1715
	}
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  1716
	__outP = __nextOutRow;
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1717
    }
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1718
fail: ;
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1719
%}.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1720
    mask := ImageMask width:width height:height fromArray:maskArray.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1721
    ^ mask
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1722
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1723
    "Created: 21.6.1996 / 11:43:47 / cg"
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1724
! !
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  1725
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1726
!ImageReader class methodsFor:'image writing'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1727
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1728
save:anImage onFile:aFileName
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1729
    "save the image in my format on aFileName.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1730
     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
  1731
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1732
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1733
     or it is not support"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1734
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1735
    ^ (self basicNew) save:anImage onFile:aFileName
1574
7c25ed84ad12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1551
diff changeset
  1736
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1737
    "Modified: / 10-04-1997 / 17:42:57 / cg"
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1738
    "Modified (comment): / 05-02-2017 / 16:58:30 / cg"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1739
!
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1740
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1741
save:anImage onFile:aFileName quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1742
    "save the image in my format on aFileName.
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1743
     The qualityPercent argument is ignored by all lossless formats.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1744
     (however, JPG does care for it.)
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1745
     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
  1746
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1747
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1748
     or it is not support"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1749
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1750
    ^ (self basicNew) save:anImage onFile:aFileName quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1751
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1752
    "Modified: / 10-04-1997 / 17:42:57 / cg"
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1753
    "Modified (comment): / 05-02-2017 / 16:58:45 / cg"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1754
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1755
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1756
save:anImage onStream:aStream
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1757
    "save the image in my format on aStream.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1758
     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
  1759
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1760
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1761
     or it is not support"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1762
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1763
    ^ (self basicNew) save:anImage onStream:aStream
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1764
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1765
    "Modified: / 10-04-1997 / 17:42:57 / cg"
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1766
    "Modified (comment): / 05-02-2017 / 16:58:18 / cg"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1767
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1768
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1769
save:anImage onStream:aStream quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1770
    "save the image in my format on a Stream.
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1771
     The qualityPercent argument is ignored by all lossless formats.
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1772
     (however, JPG does care for it.)
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1773
     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
  1774
     May raise Image cannotRepresentImageSignal,
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1775
     if the image cannot be represented in that format,
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1776
     or it is not support"
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1777
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1778
    ^ (self basicNew) save:anImage onStream:aStream quality:qualityPercent
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1779
7174
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  1780
    "
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1781
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield.gif'
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  1782
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield.jpg'
7174
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  1783
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield50.jpg' quality:50
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  1784
     (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield100.jpg' quality:100
33fb4dc4b3d5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7172
diff changeset
  1785
    "
7839
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1786
98cc4414405e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7726
diff changeset
  1787
    "Modified (comment): / 05-02-2017 / 16:58:11 / cg"
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1788
!
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1789
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1790
saveAll:aCollectionOfImages onFile:aFilename
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1791
    "save an image collection in my format on a file.
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1792
     Not all file formats support multiple images, 
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1793
     so be prepared for an exception to be raised."
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1794
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1795
    ^ (self basicNew) saveAll:aCollectionOfImages onFile:aFilename
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1796
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1797
    "Created: / 22-02-2017 / 01:01:17 / cg"
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1798
!
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1799
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1800
saveAll:aCollectionOfImages onStream:aStream
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1801
    "save an image collection in my format on a Stream.
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1802
     Not all file formats support multiple images, 
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1803
     so be prepared for an exception to be raised."
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1804
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1805
    ^ (self basicNew) saveAll:aCollectionOfImages onStream:aStream
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1806
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  1807
    "Created: / 22-02-2017 / 01:00:44 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1808
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1809
7859
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1810
!ImageReader class methodsFor:'queries'!
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1811
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1812
isAbstract
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1813
    "Return if this class is an abstract class.
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1814
     True is returned here for myself only; false for subclasses.
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1815
     Abstract subclasses must redefine this again."
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1816
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1817
    ^ self == ImageReader.
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1818
! !
6778c78e74e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7839
diff changeset
  1819
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  1820
!ImageReader class methodsFor:'testing'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1821
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1822
canRepresent:anImage
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1823
    "return true, if anImage can be represented in my file format.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1824
     must be redefined in concrete subclasses which support saving."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1825
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1826
    ^ false
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1827
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1828
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1829
isValidImageFile:aFileName
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1830
    "return true, if aFileName contains an image this
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1831
     reader understands - must be redefined in concrete subclasses
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1832
     which support reading."
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1833
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1834
    ^ false
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1835
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1836
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1837
!ImageReader methodsFor:'accessing'!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1838
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1839
bitsPerPixel
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1840
    "return the number of bits per pixel"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1841
3386
b9294699dbcf care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1842
    bitsPerSample isNil ifTrue:[^ nil].
5927
eebe3a485637 changed: #bitsPerPixel
Stefan Vogel <sv@exept.de>
parents: 5737
diff changeset
  1843
    ^ bitsPerSample sum
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1844
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1845
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1846
bitsPerRow
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1847
    "return the number of bits in one scanline of the image"
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1848
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3843
diff changeset
  1849
    ^ width * (self bitsPerPixel).
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1850
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1851
    "Created: 31.1.1997 / 10:38:42 / cg"
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1852
!
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1853
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1854
bitsPerSample
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1855
    "return the number of bits per sample"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1856
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1857
    ^ bitsPerSample
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1858
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1859
    "Modified: 22.4.1996 / 19:15:18 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1860
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1861
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1862
bytesPerRow
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1863
    "return the number of bytes in one scanline of the image"
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1864
7897
de53f0853c91 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7894
diff changeset
  1865
    ^ Image bytesPerRowForWidth:width bitsPerPixel:(self bitsPerPixel)
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1866
7897
de53f0853c91 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7894
diff changeset
  1867
    "Created: / 31-01-1997 / 10:39:06 / cg"
de53f0853c91 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7894
diff changeset
  1868
    "Modified: / 16-02-2017 / 16:18:13 / cg"
1300
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1869
!
1416ad43b694 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
  1870
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1871
colorMap
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1872
    "return the colormap"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1873
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1874
    ^ colorMap
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1875
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1876
    "Modified: 22.4.1996 / 19:15:24 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1877
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1878
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1879
compressQuality:qualityPercentIgnoredHere
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1880
    "/ intentionally ignored here (redefined in JPEGReader)
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1881
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  1882
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1883
data
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1884
    "return the raw image data"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1885
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1886
    ^ data
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1887
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1888
    "Modified: 22.4.1996 / 19:15:31 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1889
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1890
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1891
hasMultipleImages
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1892
    ^ imageSequence size > 1
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1893
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1894
    "Created: 4.4.1997 / 21:37:06 / cg"
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1895
    "Modified: 24.6.1997 / 15:33:43 / cg"
1550
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1896
!
afee7c032a57 rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents: 1358
diff changeset
  1897
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  1898
height
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1899
    "return the height of the image"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1900
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1901
    ^ height
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1902
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1903
    "Modified: 22.4.1996 / 19:15:39 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1904
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1905
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1906
image
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  1907
    "return the image as represented by myself;
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  1908
     If my file contained multiple images, return the first one."
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1909
7908
84a8ad360ada #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7897
diff changeset
  1910
    imageSequence notEmptyOrNil ifTrue:[
84a8ad360ada #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7897
diff changeset
  1911
        ^ self images first.
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  1912
    ].
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1913
    ^ self makeImage.
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1914
7908
84a8ad360ada #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7897
diff changeset
  1915
    "Modified: / 15-01-1998 / 15:46:24 / stefan"
84a8ad360ada #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7897
diff changeset
  1916
    "Modified: / 17-02-2017 / 11:58:16 / cg"
7929
576cffea9ac5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7926
diff changeset
  1917
    "Modified (format): / 22-02-2017 / 18:07:45 / cg"
2082
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1918
!
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1919
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1920
imageFrames
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1921
    "return a collection of all imageFrames as represented by myself.
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1922
     ImageFrames are wrappers for individual images, which hold
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1923
     additional information (such as image delay time).
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1924
     Nil is return for single image formats/files."
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1925
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1926
    ^ imageSequence
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1927
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1928
    "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
  1929
!
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1930
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1931
images
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1932
    "return a collection of all images as represented by myself.
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1933
     For compatibility with single-image formats, return a collection
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1934
     containing my single image here if the reader does not support
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1935
     multiple images.
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1936
     Readers for formats with multiple images should leave the images
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1937
     in the imageSequence instVar as a side effect of reading."
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1938
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1939
    |img|
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1940
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1941
    imageSequence notNil ifTrue:[
2152
b071479dac57 check byteArray bounds in bmp-decompressors;
Claus Gittinger <cg@exept.de>
parents: 2082
diff changeset
  1942
	^ (imageSequence collect:[:aFrame | aFrame image])
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1943
    ].
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  1944
2082
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1945
    img := self makeImage.
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1946
    img isNil ifTrue:[
2152
b071479dac57 check byteArray bounds in bmp-decompressors;
Claus Gittinger <cg@exept.de>
parents: 2082
diff changeset
  1947
	^ img
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1948
    ].
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1949
    ^ Array with:img
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1950
2082
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1951
    "Modified: / 1.4.1998 / 14:36:23 / cg"
1551
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1952
!
1e1f4820b93a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1550
diff changeset
  1953
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1954
makeImage
2082
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1955
    "return the image as represented by the values found in my
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1956
     instvars; these have been typically set as a side effect of
e9dbcef26c9a fixed imageSequence reading
Claus Gittinger <cg@exept.de>
parents: 2080
diff changeset
  1957
     the fromStream:-method, which reads images."
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1958
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1959
    |image depth|
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1960
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1961
    depth := self bitsPerPixel.
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  1962
    (depth notNil and:[data notNil]) ifTrue:[
8026
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1963
        image := Image newForDepth:depth.
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1964
        image depth:depth.
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1965
        inStream isFileStream ifTrue:[
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1966
            image fileName:inStream pathName.
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1967
        ].
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1968
        image
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1969
            width:width
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1970
            height:height
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1971
            photometric:photometric
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1972
            samplesPerPixel:samplesPerPixel
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1973
            bitsPerSample:bitsPerSample
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1974
            colorMap:colorMap
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1975
            bits:data
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1976
            mask:mask.
3386
b9294699dbcf care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1977
8026
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1978
        imageSequence notNil ifTrue:[
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1979
            image imageSequence:imageSequence.
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1980
        ].
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1981
        metaData notEmptyOrNil ifTrue:[
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1982
            image metaData:metaData
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1983
        ].
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1984
    ].
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1985
    ^ image
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1986
8026
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1987
    "Modified: / 15-01-1998 / 15:46:24 / stefan"
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1988
    "Created: / 01-04-1998 / 14:09:45 / cg"
532ccce8b1fd #REFACTORING by mawalch
mawalch
parents: 7929
diff changeset
  1989
    "Modified: / 17-05-2017 / 14:37:16 / mawalch"
2080
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1990
!
5361e4ffaaaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1991
893
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1992
mask
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1993
    "return the image mask (or nil)"
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1994
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1995
    ^ mask
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1996
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1997
    "Modified: 22.4.1996 / 19:15:31 / cg"
24dc4b26a486 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  1998
    "Created: 20.6.1996 / 17:08:29 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  1999
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2000
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2001
numberOfImages
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2002
    "return the number of images as read.
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2003
     By default (here), I hold a single image;
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2004
     however, some fileFormats allow for multiple images"
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2005
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2006
    |n|
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2007
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2008
    (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
  2009
	^ n
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2010
    ].
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2011
    ^ 1
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2012
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2013
    "Created: 21.6.1997 / 18:33:45 / cg"
1773
e12d18fb2b4c multiple images changes
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
  2014
    "Modified: 24.6.1997 / 15:33:26 / cg"
1772
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2015
!
56b3ae478bbb changes to support multiple images
Claus Gittinger <cg@exept.de>
parents: 1661
diff changeset
  2016
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2017
photometric
6309
d12f01f0e52e class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6167
diff changeset
  2018
    "return the photometric interpretation of the image data.
d12f01f0e52e class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6167
diff changeset
  2019
     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
  2020
     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
  2021
     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
  2022
     - 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
  2023
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2024
    ^ photometric
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2025
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2026
    "Modified: 22.4.1996 / 19:15:57 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2027
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2028
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2029
samplesPerPixel
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2030
    "return the number of samples per pixel"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2031
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2032
    ^ samplesPerPixel
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2033
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2034
    "Modified: 22.4.1996 / 19:16:03 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2035
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2036
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2037
width
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2038
    "return the width of the image"
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2039
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2040
    ^ width
583
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2041
211abfdb4db5 commentary
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2042
    "Modified: 22.4.1996 / 19:16:10 / cg"
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2043
! !
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2044
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3260
diff changeset
  2045
!ImageReader methodsFor:'accessing-private'!
1355
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2046
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2047
byteOrder:aSymbol
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2048
    "set the byte order - either #lsb or #msb"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2049
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2050
    byteOrder := aSymbol
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2051
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2052
    "Created: 15.2.1997 / 13:58:50 / cg"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2053
!
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2054
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2055
inStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2056
    ^ inStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2057
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2058
    "Created: 15.2.1997 / 13:57:40 / cg"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2059
!
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2060
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2061
inStream:aStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2062
    inStream := aStream
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2063
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2064
    "Created: 15.2.1997 / 13:57:35 / cg"
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2065
! !
a7ec624230c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1300
diff changeset
  2066
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2067
!ImageReader methodsFor:'error reporting'!
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2068
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2069
fileFormatError:aMessage
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  2070
    "report a format error - no image could be read.
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  2071
     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
  2072
4055
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2073
    |errorString|
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2074
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2075
    errorString := self class name , ' [info]: ' , aMessage.
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2076
    inStream isFileStream ifTrue:[
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  2077
        errorString := errorString , ' [in ' , inStream pathName , ']'
4055
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2078
    ].
bb45fa7310eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4033
diff changeset
  2079
6618
9d377a77a1a1 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6585
diff changeset
  2080
    Image badImageFormatQuerySignal raiseRequestErrorString:errorString.
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2081
    ^ nil
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2082
7925
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  2083
    "Created: / 03-02-1998 / 17:50:06 / cg"
2c80806ec2de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7924
diff changeset
  2084
    "Modified (comment): / 22-02-2017 / 10:26:05 / cg"
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2085
! !
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2086
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2087
!ImageReader methodsFor:'i/o support'!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2088
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2089
readLong
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2090
    "return the next 4-byte long, honoring the byte-order"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2091
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2092
    ^ inStream nextInt32MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2093
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2094
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2095
readShort
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2096
    "return the next 2-byte short, honoring the byte-order"
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2097
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2098
    ^ inStream nextUnsignedInt16MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2099
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2100
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2101
readShortLong
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2102
    "return the next 2-byte short, honoring the byte-order.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2103
     There are actually 4 bytes read, but only 2 looked at."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2104
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2105
    |bytes val|
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2106
153
claus
parents: 134
diff changeset
  2107
    bytes := ByteArray uninitializedNew:4.
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2108
    inStream nextBytes:4 into:bytes.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2109
    (byteOrder == #lsb) ifTrue:[
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2110
	val := bytes at:2.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2111
	val := val * 256 + (bytes at:1)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2112
    ] ifFalse:[
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2113
	val := bytes at:3.
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2114
	val := val * 256 + (bytes at:4)
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2115
    ].
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2116
    ^ val
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2117
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2118
5318
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2119
readUnsignedLong
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2120
    "return the next 4-byte long, honoring the byte-order"
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2121
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2122
    ^ inStream nextUnsignedInt32MSB:(byteOrder ~~ #lsb)
5318
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2123
!
c1947a63d265 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5129
diff changeset
  2124
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2125
writeLong:anInteger
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2126
    "write a 4-byte long, honoring the byte-order."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2127
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2128
    outStream nextPutInt32:anInteger MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2129
!
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2130
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2131
writeShort:anInteger
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2132
    "write a 2-byte short, honoring the byte-order."
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2133
7142
439177d49d77 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 6902
diff changeset
  2134
    outStream nextPutInt16:anInteger MSB:(byteOrder ~~ #lsb)
105
6a4a21c17e5d *** empty log message ***
claus
parents: 97
diff changeset
  2135
! !
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2136
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2137
!ImageReader methodsFor:'image reading'!
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2138
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2139
fromStream:aStream
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2140
    "read an image in my format from aStream.
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2141
     Leave image description in instance variables."
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2142
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2143
    self inStream:aStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2144
    self readImage.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2145
!
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2146
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2147
readImage
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2148
    "read an image in my format from my inStream.
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2149
     Leave image description in instance variables."
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2150
3839
28440069abe4 refactorings
Claus Gittinger <cg@exept.de>
parents: 3836
diff changeset
  2151
    self subclassResponsibility.
2039
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2152
! !
00e10543cf57 added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 2014
diff changeset
  2153
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2154
!ImageReader methodsFor:'image reading support'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2155
929
f792d9689def Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents: 893
diff changeset
  2156
buildMaskFromColor:maskPixelValue
1631
fc944d181796 use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2157
    "helper for image formats, where an individual pixel value
fc944d181796 use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2158
     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
  2159
     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
  2160
     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
  2161
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2162
    mask := self class
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2163
		buildMaskFromColor:maskPixelValue
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2164
		for:data
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2165
		width:width
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2166
		height:height
929
f792d9689def Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents: 893
diff changeset
  2167
1983
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2168
    "Modified: / 14.1.1998 / 14:48:33 / cg"
03a93138c52a made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents: 1980
diff changeset
  2169
! !
929
f792d9689def Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents: 893
diff changeset
  2170
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2171
!ImageReader methodsFor:'image writing'!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2172
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2173
save:image onFile:aFileName
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2174
    "save image in my format on aFile"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2175
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2176
    self writingFile:aFileName for:image do:[:stream |
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2177
	self save:image onStream:stream.
5567
7a7a10a2e29c changed: #save:onFile:
Claus Gittinger <cg@exept.de>
parents: 5527
diff changeset
  2178
    ].
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2179
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2180
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2181
save:image onFile:aFileName quality:qualityPercentOrNil
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2182
    "save image in my format on aFile"
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2183
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2184
    self compressQuality:qualityPercentOrNil.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2185
    self save:image onFile:aFileName
3933
10147dc53aef image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3932
diff changeset
  2186
5567
7a7a10a2e29c changed: #save:onFile:
Claus Gittinger <cg@exept.de>
parents: 5527
diff changeset
  2187
    "Modified: / 01-06-2010 / 19:02:17 / cg"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2188
!
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2189
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2190
save:image onStream:aStream
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2191
    "save image in my file-format onto aStream"
3932
afa76a9c32eb +save:onStream:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2192
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2193
    ^ Image cannotRepresentImageSignal
7182
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2194
	raiseWith:image
60d1db16530b #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 7174
diff changeset
  2195
	errorString:('image save not implemented/supported for this format').
7172
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2196
!
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2197
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2198
save:image onStream:aStream quality:qualityPercentOrNil
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2199
    "save image in my format on a Stream.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2200
     QualityPercent is ignored by lossless formats (jpg uses it)"
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2201
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2202
    self compressQuality:qualityPercentOrNil.
6d903c0407fa #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7142
diff changeset
  2203
    self save:image onStream:aStream
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2204
!
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2205
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2206
saveAll:aCollectionOfImages onFile:aFileName
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2207
    "save a collection of images in my format on aFile.
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2208
     Not all file formats support multiple images, 
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2209
     so be prepared for an exception to be raised."
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2210
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2211
    self writingFile:aFileName for:aCollectionOfImages do:[:stream |
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2212
        self saveAll:aCollectionOfImages onStream:stream.
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2213
    ].
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2214
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2215
    "Modified: / 01-06-2010 / 19:02:17 / cg"
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2216
    "Modified (comment): / 22-02-2017 / 01:00:03 / cg"
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2217
!
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2218
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2219
saveAll:aCollectionOfImages onStream:aStream
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2220
    "save an image collection in my format on a Stream.
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2221
     Not all file formats support multiple images, 
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2222
     so be prepared for an exception to be raised."
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2223
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2224
    ^ Image cannotRepresentImageSignal
7924
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2225
        raiseWith:aCollectionOfImages
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2226
        errorString:('save of imageSequence not implemented/supported for this format').
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2227
ff2f12b98716 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7908
diff changeset
  2228
    "Modified (comment): / 22-02-2017 / 01:00:11 / cg"
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2229
!
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2230
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2231
writingFile:aFileName for:something do:aBlock
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2232
    "helper for save image"
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2233
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2234
    |stream|
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2235
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2236
    [
8060
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2237
        stream := aFileName asFilename newReadWriteStream.
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2238
    ] on:FileStream openErrorSignal do:[:ex|
8060
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2239
        ^ Image fileCreationErrorSignal
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2240
            raiseWith:something
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2241
            errorString:('file creation error: ' , ex description).
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2242
    ].
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2243
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2244
    [
8060
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2245
        [
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2246
            aBlock value: stream
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2247
        ] ensure:[
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2248
            stream close.
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2249
        ].
6377
7546e57a7035 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
  2250
    ] ifCurtailed:[
8060
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2251
        OsError catch:[
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2252
            aFileName asFilename delete.
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2253
        ]
6057
5d6464c7f936 class: ImageReader
Claus Gittinger <cg@exept.de>
parents: 6042
diff changeset
  2254
    ].
8060
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2255
009e27b016b1 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 8026
diff changeset
  2256
    "Modified: / 04-08-2017 / 11:28:41 / stefan"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2257
! !
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2258
1358
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2259
!ImageReader methodsFor:'initialization'!
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2260
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2261
initialize
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2262
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2263
    "Created: 18.2.1997 / 17:08:31 / cg"
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2264
! !
193570ad2ff5 added dummy #initialize
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
  2265
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2266
!ImageReader methodsFor:'progress reporting'!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2267
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2268
dimensionCallBack:aBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2269
    "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
  2270
     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
  2271
     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
  2272
     Obsoleted by dimensionHolder."
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2273
4177
7c3612e35974 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4055
diff changeset
  2274
    <resource:#obsolete>
3965
8c9c9e08880c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3957
diff changeset
  2275
    self obsoleteMethodWarning:'use #dimensionHolder'.
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2276
    dimensionCallBack := aBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2277
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2278
    "Created: 14.9.1996 / 17:10:58 / cg"
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2279
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2280
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2281
dimensionHolder:aValueHolderOrBlock
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2282
    "set the valueHolder or block, which is evaluated during the readProcess,
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2283
     as soon as the images dimension is known.
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2284
     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
  2285
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2286
    dimensionHolder := aValueHolderOrBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2287
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2288
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2289
progressHolder:aValueHolderOrBlock
4714
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2290
    "set the valueHolder or block, which is evaluated during the readProcess,
3ea57c207759 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4401
diff changeset
  2291
     and set with progress information (0..100 percent).
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2292
     Useful for user feedback"
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2293
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2294
    progressHolder := aValueHolderOrBlock
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2295
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2296
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2297
reportDimension
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2298
    dimensionCallBack notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2299
	dimensionCallBack value:self
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2300
    ].
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2301
    dimensionHolder notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2302
	dimensionHolder value:(width @ height)
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2303
    ].
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2304
!
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2305
3957
ffe8a76fae45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
  2306
reportProgress:fraction
ffe8a76fae45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
  2307
    "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
  2308
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2309
    progressHolder notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3965
diff changeset
  2310
	progressHolder value:fraction
3955
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2311
    ].
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2312
! !
6f48b9693fe5 dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents: 3933
diff changeset
  2313
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
  2314
!ImageReader class methodsFor:'documentation'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2315
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2316
version
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2317
    ^ '$Header$'
5481
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  2318
!
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  2319
93de6ee2ed5a __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5318
diff changeset
  2320
version_CVS
6902
6357c181c178 eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents: 6761
diff changeset
  2321
    ^ '$Header$'
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  2322
! !
7897
de53f0853c91 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7894
diff changeset
  2323