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