JPEGReader.st
author Claus Gittinger <cg@exept.de>
Sat, 08 Dec 2001 01:36:32 +0100
changeset 1537 364eabac0aec
parent 1094 b861869852b5
child 1558 1ae43779327f
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     1
"
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
     3
	      All Rights Reserved
6
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     4
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     5
 This software is furnished under a license and may be used
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     6
 only in accordance with the terms of that license and with the
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     8
 be provided or otherwise made available to, or used by, any
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
     9
 other person.  No title to or ownership of the software is
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
    10
 hereby transferred.
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
    11
"
4ac87e6bf82f *** empty log message ***
claus
parents: 2
diff changeset
    12
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    13
ImageReader subclass:#JPEGReader
537
2d96caf2536d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 536
diff changeset
    14
	instanceVariableNames:'jpeg_decompress_struct jpeg_error_mgr_struct colorComponents
2d96caf2536d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 536
diff changeset
    15
		forceGrayscale forceDitherMode'
576
4b81823c3fc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 542
diff changeset
    16
	classVariableNames:'ErrorPrinting'
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    17
	poolDictionaries:''
259
62b1bbafd9ba category change
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
    18
	category:'Graphics-Images-Support'
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    19
!
842b6a603cdc Initial revision
claus
parents:
diff changeset
    20
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    21
!JPEGReader primitiveDefinitions!
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    22
%{
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    23
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    24
/*
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    25
 * includes, defines, structure definitions
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    26
 * and typedefs come here.
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    27
 */
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    28
1083
707e5156278e changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
    29
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    30
#include <stdio.h>
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    31
542
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    32
#ifdef sunos
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    33
# include <sys/types.h>
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    34
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    35
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    36
#ifdef WIN32
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    37
# undef longjmp
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    38
# undef setjmp
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    39
#endif
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    40
542
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    41
#include <jpeglib.h>
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    42
#include <jerror.h>
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    43
1083
707e5156278e changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
    44
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    45
struct my_error_mgr {
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    46
	struct jpeg_error_mgr pub;
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    47
	jmp_buf setjmp_buffer;
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    48
};
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    49
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    50
%}
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    51
! !
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    52
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    53
!JPEGReader primitiveFunctions!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    54
%{
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    55
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    56
/*
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    57
 * any local C (helper) functions
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    58
 * come here (please, define as static)
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    59
 */
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    60
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    61
static
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    62
my_error_exit(cinfo)
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    63
    j_common_ptr cinfo;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    64
{
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    65
    struct my_error_mgr *myerrPtr = (struct my_error_mgr *) cinfo->err;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    66
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    67
    if (@global(ErrorPrinting) == true) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    68
	fprintf(stderr, "JPEGReader [warning]: jpeg error\n");
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    69
    }
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    70
    longjmp(myerrPtr->setjmp_buffer, 1);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    71
}
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    72
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    73
static
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    74
my_output_message(cinfo)
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    75
    j_common_ptr cinfo;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    76
{
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    77
    char buffer[JMSG_LENGTH_MAX];
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    78
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    79
    if (@global(ErrorPrinting) == true) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    80
	fprintf(stderr, "libJPEG [error]: ");
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    81
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    82
       /* Create the message */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    83
       (*cinfo->err->format_message) (cinfo, buffer);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    84
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    85
       /* Send it to stderr, adding a newline */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    86
       fprintf(stderr, "%s\n", buffer);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    87
    }
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    88
}
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    89
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    90
/*
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    91
 * Optional progress monitor: display a percent-done figure on stderr.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    92
 */
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    93
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    94
#ifdef PROGRESS_REPORT
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    95
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    96
void
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    97
JPG_progress_monitor (j_common_ptr cinfo)
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    98
{
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    99
  cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   100
  int total_passes = prog->pub.total_passes + prog->total_extra_passes;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   101
  int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   102
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   103
  if (percent_done != prog->percent_done) {
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   104
    prog->percent_done = percent_done;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   105
    if (total_passes > 1) {
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   106
      fprintf(stderr, "\rPass %d/%d: %3d%% ",
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   107
	      prog->pub.completed_passes + prog->completed_extra_passes + 1,
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   108
	      total_passes, percent_done);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   109
    } else {
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   110
      fprintf(stderr, "\r %3d%% ", percent_done);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   111
    }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   112
    fflush(stderr);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   113
  }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   114
}
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   115
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   116
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   117
void
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   118
JPG_start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   119
{
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   120
  /* Enable progress display, unless trace output is on */
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   121
  if (cinfo->err->trace_level == 0) {
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   122
    progress->pub.progress_monitor = progress_monitor;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   123
    progress->completed_extra_passes = 0;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   124
    progress->total_extra_passes = 0;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   125
    progress->percent_done = -1;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   126
    cinfo->progress = &progress->pub;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   127
  }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   128
}
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   129
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   130
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   131
void
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   132
JPG_end_progress_monitor (j_common_ptr cinfo)
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   133
{
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   134
  /* Clear away progress display */
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   135
  if (cinfo->err->trace_level == 0) {
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   136
    fprintf(stderr, "\r                \r");
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   137
    fflush(stderr);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   138
  }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   139
}
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   140
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   141
#endif
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   142
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   143
%}
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   144
! !
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   145
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   146
!JPEGReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   147
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   148
copyright
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   149
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   150
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   151
	      All Rights Reserved
16
42d4754a035f *** empty log message ***
claus
parents: 6
diff changeset
   152
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   153
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   154
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   155
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   156
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   157
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   158
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   159
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   160
!
16
42d4754a035f *** empty log message ***
claus
parents: 6
diff changeset
   161
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   162
documentation
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   163
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   164
    Reader for JPEG images.
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   165
532
66aa3109df17 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   166
    This uses the libpeg library to read the image
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   167
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   168
    Only reading of files is supported.
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   169
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   170
    [See also:]
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   171
	Image Form Icon
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   172
	BlitImageReader FaceReader GIFReader PBMReader PCXReader 
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   173
	ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   174
	XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   175
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   176
! !
16
42d4754a035f *** empty log message ***
claus
parents: 6
diff changeset
   177
28
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   178
!JPEGReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   179
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   180
initialize
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   181
    "install myself in the Image classes fileFormat table
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   182
     for the `.jpg' and '.jpeg' extensions."
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   183
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   184
    MIMETypes defineImageType:'image/jpeg' suffix:'jpg'  reader:self.
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   185
    MIMETypes defineImageType:nil          suffix:'jpeg' reader:self.
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   186
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   187
    "Modified: 1.2.1997 / 15:01:55 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   188
! !
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   189
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   190
!JPEGReader class methodsFor:'testing'!
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   191
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   192
isValidImageFile:aFileName
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   193
    "return true, if aFileName contains a JPG image.
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   194
     Only look at the files name here ..."
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   195
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   196
    (aFileName asLowercase endsWith:'.jpg') ifTrue:[^ true].
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   197
    (aFileName asLowercase endsWith:'.jpeg') ifTrue:[^ true].
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   198
    ^ false
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   199
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   200
    "Created: 11.4.1997 / 16:26:25 / cg"
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   201
! !
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   202
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   203
!JPEGReader methodsFor:'accessing'!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   204
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   205
forceDitherMode:something
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   206
    "set the dither mode, to one of #none or #ordered"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   207
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   208
    forceDitherMode := something.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   209
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   210
    "Modified: 16.4.1997 / 20:34:59 / cg"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   211
!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   212
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   213
forceGrayscale:something
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   214
    "set the forceGrayscale mode; if true, grayScale images are
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   215
     returned, even if the input contains a color image."
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   216
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   217
    forceGrayscale := something.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   218
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   219
    "Created: 16.4.1997 / 20:33:44 / cg"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   220
    "Modified: 16.4.1997 / 20:34:29 / cg"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   221
! !
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   222
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   223
!JPEGReader methodsFor:'private'!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   224
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   225
create_jpeg_decompress_struct
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   226
    |errMgrStructSize decompressStructSize fp errorOccurred|
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   227
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   228
    fp := inStream filePointer.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   229
    fp isNil ifTrue:[
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   230
	self error:'can only read from an external stream'.
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   231
	^ self.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   232
    ].
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   233
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   234
%{
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   235
    errMgrStructSize = __MKSMALLINT(sizeof(struct my_error_mgr));
532
66aa3109df17 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   236
    decompressStructSize = __MKSMALLINT(sizeof(struct jpeg_decompress_struct));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   237
%}.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   238
532
66aa3109df17 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   239
    jpeg_error_mgr_struct := ExternalBytes unprotectedNew:errMgrStructSize.
66aa3109df17 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   240
    jpeg_decompress_struct := ExternalBytes unprotectedNew:decompressStructSize.
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   241
    errorOccurred := false.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   242
1080
3be38bb2d33c declared stack for jpeg functions (they seem to need some)
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   243
%{  /* STACK: 200000 */
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   244
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   245
    struct my_error_mgr *jerrPtr;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   246
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   247
    OBJ j_d_s = __INST(jpeg_decompress_struct);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   248
    FILE *f = __FILEVal(fp);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   249
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   250
    if (__isExternalBytes(j_d_s)
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   251
     && __isExternalBytes(j_e_m)) {
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   252
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   253
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   254
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   255
	/* 
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   256
	 * Initialize the JPEG decompression object with default error handling.
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   257
	 */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   258
	cinfoPtr->err = jpeg_std_error(jerrPtr);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   259
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   260
	/*
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   261
	 * prepare to handle errors smoothly ...
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   262
	 */
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   263
	jerrPtr->pub.error_exit = my_error_exit;
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   264
	if (setjmp(jerrPtr->setjmp_buffer)) {
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   265
	    /* 
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   266
	     * error occurred ...
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   267
	     */
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   268
	    jpeg_destroy_decompress(cinfoPtr);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   269
	    RETURN (false);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   270
	}
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   271
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   272
       /*
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   273
        * use my message print function
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   274
        */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   275
       jerrPtr->pub.output_message = my_output_message;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   276
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   277
	jpeg_create_decompress(cinfoPtr);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   278
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   279
	/* 
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   280
	 * Insert custom COM marker processor.
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   281
	 */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   282
	jpeg_set_marker_processor(cinfoPtr, JPEG_COM, COM_handler);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   283
#endif
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   284
	cinfoPtr->err->trace_level = 0;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   285
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   286
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   287
	/* colors setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   288
	cinfoPtr->desired_number_of_colors = val;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   289
	cinfoPtr->quantize_colors = TRUE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   290
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   291
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   292
	/* dct setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   293
	cinfoPtr->dct_method = JDCT_ISLOW;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   294
	or: cinfoPtr->dct_method = JDCT_IFAST;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   295
	or: cinfoPtr->dct_method = JDCT_FLOAT;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   296
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   297
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   298
	/* dither setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   299
	cinfoPtr->dither_mode = JDITHER_FS;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   300
	if (__INST(forceDitherMode) == @symbol(none)) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   301
	    cinfoPtr->dither_mode = JDITHER_NONE;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   302
	} else {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   303
	    if (__INST(forceDitherMode) == @symbol(ordered)) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   304
		cinfoPtr->dither_mode = JDITHER_ORDERED;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   305
	    }
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   306
	}
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   307
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   308
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   309
	/* fast setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   310
	cinfoPtr->two_pass_quantize = FALSE;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   311
	cinfoPtr->dither_mode = JDITHER_ORDERED;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   312
	cinfoPtr->desired_number_of_colors = 216;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   313
	cinfoPtr->dct_method = JDCT_FASTEST;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   314
	cinfoPtr->do_fancy_upsampling = FALSE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   315
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   316
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   317
	if (__INST(forceGrayscale) == true) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   318
	    /* grayscale setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   319
	    cinfoPtr->out_color_space = JCS_GRAYSCALE;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   320
	}
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   321
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   322
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   323
	/* maxmemory setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   324
	cinfoPtr->mem->max_memory_to_use = lval * 1000L;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   325
#endif
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   326
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   327
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   328
	/* nosmooth setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   329
	cinfoPtr->do_fancy_upsampling = FALSE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   330
#endif
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   331
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   332
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   333
	/* onepass setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   334
	cinfoPtr->two_pass_quantize = FALSE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   335
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   336
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   337
	/* Specify data source for decompression */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   338
	jpeg_stdio_src(cinfoPtr, f);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   339
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   340
	/* Read file header, set default decompression parameters */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   341
	(void) jpeg_read_header(cinfoPtr, TRUE);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   342
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   343
	/* Calculate output image dimensions so we can allocate space */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   344
	jpeg_calc_output_dimensions(cinfoPtr);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   345
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   346
	__INST(width) = __MKSMALLINT(cinfoPtr->output_width);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   347
	__INST(height) = __MKSMALLINT(cinfoPtr->output_height);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   348
	__INST(colorComponents) = __MKSMALLINT(cinfoPtr->output_components);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   349
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   350
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   351
	/* could now set additional values in cinfo
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   352
	 * (colormap)
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   353
	 */
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   354
#endif
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   355
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   356
    }
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   357
%}.
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   358
    ^ true
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   359
!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   360
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   361
decompressChunkInto:aByteArray startingAt:index
1080
3be38bb2d33c declared stack for jpeg functions (they seem to need some)
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   362
%{  /* STACK: 200000 */
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   363
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   364
    struct my_error_mgr *jerrPtr;
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   365
    char *rowPtr = NULL;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   366
    OBJ j_d_s = __INST(jpeg_decompress_struct);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   367
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   368
    int num_scanlines;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   369
    char *rowPointers[4];
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   370
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   371
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   372
    if (__isByteArray(aByteArray)) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   373
        rowPtr = (char *)(__ByteArrayInstPtr(aByteArray)->ba_element);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   374
    } else if (__isExternalBytes(aByteArray)) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   375
        rowPtr = __externalBytesAddress(aByteArray);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   376
    }
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   377
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   378
    if (__isExternalBytes(j_d_s)
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   379
     && (rowPtr != NULL)
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   380
     && __isExternalBytes(j_e_m)) {
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   381
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   382
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   383
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   384
	rowPtr += __intVal(index) - 1;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   385
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   386
	rowPointers[0] = rowPtr;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   387
	rowPointers[1] = NULL;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   388
	rowPointers[2] = NULL;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   389
	rowPointers[3] = NULL;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   390
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   391
	if (cinfoPtr->output_scanline < cinfoPtr->output_height) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   392
	    if (setjmp(jerrPtr->setjmp_buffer)) {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   393
		/* 
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   394
		 * error occurred ...
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   395
		 */
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   396
		jpeg_destroy_decompress(cinfoPtr);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   397
		RETURN (__MKSMALLINT(-1));
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   398
	    }
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   399
	    num_scanlines = jpeg_read_scanlines(cinfoPtr, 
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   400
						rowPointers,
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   401
						1);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   402
	    RETURN (__MKSMALLINT(num_scanlines));
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   403
	}
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   404
	RETURN (__MKSMALLINT(0));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   405
    }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   406
%}.
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   407
    self halt:'bad arguments'.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   408
!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   409
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   410
finish_decompress
1080
3be38bb2d33c declared stack for jpeg functions (they seem to need some)
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   411
%{  /* STACK: 200000 */
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   412
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   413
    struct my_error_mgr *jerrPtr;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   414
    OBJ j_d_s = __INST(jpeg_decompress_struct);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   415
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   416
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   417
    if (__isExternalBytes(j_d_s)
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   418
     && __isExternalBytes(j_e_m)) {
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   419
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   420
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   421
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   422
	if (setjmp(jerrPtr->setjmp_buffer)) {
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   423
	    jpeg_destroy_decompress(cinfoPtr);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   424
	    RETURN (false);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   425
	}
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   426
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   427
	/* finish decompressor */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   428
	(void) jpeg_finish_decompress(cinfoPtr);
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   429
	(void) jpeg_destroy_decompress(cinfoPtr);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   430
	RETURN (true);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   431
    }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   432
%}
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   433
!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   434
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   435
get_error_message
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   436
%{
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   437
    struct jpeg_decompress_struct *cinfoPtr;
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   438
    OBJ j_d_s = __INST(jpeg_decompress_struct);
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   439
    char buffer[JMSG_LENGTH_MAX+1];
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   440
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   441
    if (__isExternalBytes(j_d_s)) {
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   442
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   443
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   444
	(*cinfoPtr->err->format_message) (cinfoPtr, buffer);
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   445
	buffer[JMSG_LENGTH_MAX] = '\0';
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   446
	RETURN ( __MKSTRING(buffer));
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   447
    }
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   448
%}.
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   449
    ^ nil
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   450
!
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   451
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   452
start_decompress
1080
3be38bb2d33c declared stack for jpeg functions (they seem to need some)
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   453
%{  /* STACK: 200000 */
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   454
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   455
    struct my_error_mgr *jerrPtr;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   456
    OBJ j_d_s = __INST(jpeg_decompress_struct);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   457
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   458
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   459
    if (__isExternalBytes(j_d_s)
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   460
     && __isExternalBytes(j_e_m)) {
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   461
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   462
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   463
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   464
	if (setjmp(jerrPtr->setjmp_buffer)) {
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   465
	    jpeg_destroy_decompress(cinfoPtr);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   466
	    RETURN (false);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   467
	}
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   468
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   469
	/* Start decompressor */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   470
	(void) jpeg_start_decompress(cinfoPtr);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   471
	RETURN (true);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   472
    }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   473
%}
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   474
! !
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   475
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   476
!JPEGReader methodsFor:'reading from stream'!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   477
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   478
fromStream:aStream
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   479
    "read a JPG image from a stream"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   480
951
de8417214dfd read from an internal stream (save to tempfile, then read)
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
   481
    |dataIdx bytesPerRow returnCode pos1 ok tmpFile s|
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   482
895
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   483
    aStream isExternalStream ifFalse:[
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   484
        "/ libJpeg can only handle real OS-streams
951
de8417214dfd read from an internal stream (save to tempfile, then read)
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
   485
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   486
        tmpFile := Filename newTemporary.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   487
        [
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   488
            s := tmpFile writeStream binary.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   489
            s nextPutAll:aStream contents.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   490
            s close.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   491
            s := tmpFile readStream binary.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   492
            ^ self fromStream:s.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   493
        ] valueNowOrOnUnwindDo:[
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   494
            s notNil ifTrue:[s close].
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   495
            tmpFile delete.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   496
        ].
951
de8417214dfd read from an internal stream (save to tempfile, then read)
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
   497
        
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   498
        "/ 'JPEGReader [info]: can only read from real streams' infoPrintCR.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   499
        "/ ^ nil
895
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   500
    ].
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   501
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   502
    inStream := aStream.
669
d38a796ad10b care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   503
    pos1 := inStream position.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   504
895
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   505
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   506
    (self create_jpeg_decompress_struct not
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   507
    or:[self start_decompress not]) ifTrue:[
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   508
        ok := false.
669
d38a796ad10b care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   509
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   510
        "/ if there was no SOI marker,
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   511
        "/ try again, skipping first 128 bytes
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   512
        "/ (seems to be generated by some jpg writers)
669
d38a796ad10b care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   513
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   514
        inStream position:pos1.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   515
        ((inStream nextByte ~~ 16rFF)
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   516
        or:[inStream nextByte ~~ 16rD8]) ifTrue:[
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   517
            inStream position:pos1 + 128.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   518
            ((inStream nextByte == 16rFF)
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   519
            and:[inStream nextByte == 16rD8]) ifTrue:[
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   520
                inStream position:pos1 + 128.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   521
                ok := self create_jpeg_decompress_struct
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   522
                      and:[self start_decompress]
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   523
            ].
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   524
        ].
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   525
        ok ifFalse:[
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   526
            'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   527
            ^ nil
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   528
        ]
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   529
    ].
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   530
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   531
    data := ByteArray uninitializedNew:(width * height * colorComponents).
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   532
    dataIdx := 1.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   533
    bytesPerRow := colorComponents * width.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   534
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   535
    [(returnCode := self decompressChunkInto:data startingAt:dataIdx) > 0] whileTrue:[
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   536
        "/ got a row in the buffer ...
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   537
        dataIdx := dataIdx + bytesPerRow
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   538
    ].    
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   539
    returnCode < 0 ifTrue:[
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   540
        'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   541
        ^ nil
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   542
    ].
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   543
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   544
    (self finish_decompress) ifFalse:[
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   545
        'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   546
        ^ nil
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   547
    ].
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   548
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   549
    colorComponents == 3 ifTrue:[
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   550
        photometric := #rgb.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   551
        samplesPerPixel := 3.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   552
        bitsPerSample := #(8 8 8).
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   553
    ] ifFalse:[
1070
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   554
        photometric := #blackIs0.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   555
        samplesPerPixel := 1.
9c845473f95d oops - fileName delete; not destroy
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   556
        bitsPerSample := #(8).
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   557
    ].
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   558
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   559
    "
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   560
     JPEGReader fromFile:'../../support/libjpeg-6a/testimg.jpg'
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   561
    "
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   562
    "
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   563
     |stream reader|
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   564
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   565
     stream := '../../support/libjpeg-6a/testimg.jpg' asFilename readStream.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   566
     reader := JPEGReader new.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   567
     reader forceGrayscale:true.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   568
     reader forceDitherMode:#ordered.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   569
     reader fromStream:stream.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   570
     ^ reader image
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   571
    "
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   572
895
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   573
    "Modified: / 4.4.1998 / 18:48:46 / cg"
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   574
! !
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   575
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   576
!JPEGReader class methodsFor:'documentation'!
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   577
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   578
version
1094
b861869852b5 renamed __new() to __STX___new()
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   579
    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.39 1999-02-12 14:59:12 cg Exp $'
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   580
! !
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   581
JPEGReader initialize!