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