JPEGReader.st
author Claus Gittinger <cg@exept.de>
Mon, 12 Dec 2011 21:25:19 +0100
changeset 2973 b708ff319811
parent 2972 c9b3ef795181
child 2974 9d47730e05e0
permissions -rw-r--r--
comment/format in: #fromStream:
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
"
1558
1ae43779327f #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 1094
diff changeset
    12
"{ Package: 'stx:libview2' }"
1ae43779327f #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 1094
diff changeset
    13
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    14
ImageReader subclass:#JPEGReader
537
2d96caf2536d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 536
diff changeset
    15
	instanceVariableNames:'jpeg_decompress_struct jpeg_error_mgr_struct colorComponents
2971
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
    16
		forceGrayscale forceDitherMode app1SegmentHandler'
576
4b81823c3fc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 542
diff changeset
    17
	classVariableNames:'ErrorPrinting'
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    18
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1698
diff changeset
    19
	category:'Graphics-Images-Readers'
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    20
!
842b6a603cdc Initial revision
claus
parents:
diff changeset
    21
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    22
!JPEGReader primitiveDefinitions!
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
/*
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    26
 * includes, defines, structure definitions
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    27
 * and typedefs come here.
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    28
 */
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
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
542
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    36
#include <jpeglib.h>
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    37
#include <jerror.h>
5eeab29c23cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 538
diff changeset
    38
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    39
struct my_error_mgr {
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    40
	struct jpeg_error_mgr pub;
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    41
	jmp_buf setjmp_buffer;
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    42
};
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    43
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    44
%}
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
!JPEGReader primitiveFunctions!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    48
%{
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    49
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    50
/*
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    51
 * any local C (helper) functions
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    52
 * come here (please, define as static)
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    53
 */
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    54
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    55
static
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    56
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
    57
    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
    58
{
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    59
    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
    60
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    61
    if (@global(ErrorPrinting) == true) {
2283
a1aa773edb4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2282
diff changeset
    62
	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
    63
    }
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    64
    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
    65
}
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
static
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    68
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
    69
    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
    70
{
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    71
    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
    72
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    73
    if (@global(ErrorPrinting) == true) {
2283
a1aa773edb4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2282
diff changeset
    74
	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
    75
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    76
       /* Create the message */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    77
       (*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
    78
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
    79
       /* Send it to stderr, adding a newline */
2283
a1aa773edb4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2282
diff changeset
    80
       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
    81
    }
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
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    84
/*
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    85
 * Optional progress monitor: display a percent-done figure on stderr.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    86
 */
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
#ifdef PROGRESS_REPORT
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    89
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    90
void
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    91
JPG_progress_monitor (j_common_ptr cinfo)
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
  cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    94
  int total_passes = prog->pub.total_passes + prog->total_extra_passes;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    95
  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
    96
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    97
  if (percent_done != prog->percent_done) {
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    98
    prog->percent_done = percent_done;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    99
    if (total_passes > 1) {
2283
a1aa773edb4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2282
diff changeset
   100
      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
   101
	      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
   102
	      total_passes, percent_done);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   103
    } else {
2283
a1aa773edb4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2282
diff changeset
   104
      console_fprintf("\r %3d%% ", percent_done);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   105
    }
2283
a1aa773edb4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2282
diff changeset
   106
    console_fflush(stderr);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   107
  }
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
void
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   112
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
   113
{
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   114
  /* Enable progress display, unless trace output is on */
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   115
  if (cinfo->err->trace_level == 0) {
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   116
    progress->pub.progress_monitor = progress_monitor;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   117
    progress->completed_extra_passes = 0;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   118
    progress->total_extra_passes = 0;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   119
    progress->percent_done = -1;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   120
    cinfo->progress = &progress->pub;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   121
  }
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
void
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   126
JPG_end_progress_monitor (j_common_ptr cinfo)
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
  /* Clear away progress display */
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   129
  if (cinfo->err->trace_level == 0) {
2283
a1aa773edb4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2282
diff changeset
   130
    console_fprintf(stderr, "\r                \r");
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   131
  }
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
2971
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   134
#endif /* PROGRESS_REPORT */
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   135
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   136
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   137
/* fetch a byte from the stream */
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   138
unsigned int
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   139
JPG_jpeg_getc (j_decompress_ptr cinfo)
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   140
/* Read next byte */
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   141
{
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   142
  struct jpeg_source_mgr *datasrc = cinfo->src;
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   143
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   144
  if (datasrc->bytes_in_buffer == 0) {
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   145
    if (! (*datasrc->fill_input_buffer) (cinfo))
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   146
      return -1;
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   147
  }
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   148
  datasrc->bytes_in_buffer--;
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   149
  return (*datasrc->next_input_byte++) & 0xFF;
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   150
}
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   151
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   152
%}
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   153
! !
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   154
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   155
!JPEGReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   156
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   157
copyright
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   158
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   159
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   160
	      All Rights Reserved
16
42d4754a035f *** empty log message ***
claus
parents: 6
diff changeset
   161
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   162
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   163
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   164
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   165
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   166
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   167
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   168
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   169
!
16
42d4754a035f *** empty log message ***
claus
parents: 6
diff changeset
   170
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   171
documentation
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   172
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   173
    Reader for JPEG images.
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   174
532
66aa3109df17 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   175
    This uses the libpeg library to read the image
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   176
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   177
    Only reading of files is supported.
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   178
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   179
    [See also:]
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   180
	Image Form Icon
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   181
	BlitImageReader FaceReader GIFReader PBMReader PCXReader
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   182
	ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   183
	XBMReader XPMReader XWDReader
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   184
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   185
! !
16
42d4754a035f *** empty log message ***
claus
parents: 6
diff changeset
   186
28
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   187
!JPEGReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   188
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   189
initialize
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   190
    "install myself in the Image classes fileFormat table
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   191
     for the `.jpg' and '.jpeg' extensions."
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   192
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   193
    MIMETypes defineImageType:'image/jpeg' suffix:'jpg'  reader:self.
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   194
    MIMETypes defineImageType:nil          suffix:'jpeg' reader:self.
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   195
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   196
    "Modified: 1.2.1997 / 15:01:55 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   197
! !
8daff0234d2e *** empty log message ***
claus
parents: 23
diff changeset
   198
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   199
!JPEGReader class methodsFor:'testing'!
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   200
2768
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   201
isValidImageFile:aFilenameOrString
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   202
    "return true, if aFileName contains a JPG image.
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   203
     Only look at the files name here ..."
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   204
2768
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   205
    |suffix|
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   206
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   207
    suffix := aFilenameOrString asFilename suffix asLowercase.
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   208
    ^ suffix = 'jpg' or:[suffix = 'jpeg'].
522
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   209
93a9f3a8caae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   210
    "Created: 11.4.1997 / 16:26:25 / cg"
2768
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   211
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   212
    "
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   213
      self isValidImageFile:'xxx.jpg'
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   214
    "
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   215
! !
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   216
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   217
!JPEGReader methodsFor:'accessing'!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   218
2971
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   219
app1SegmentHandler:aBlock
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   220
    "set a handler block for app1 segment data (geolocation in exif format)"
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   221
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   222
    app1SegmentHandler := aBlock
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   223
!
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   224
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   225
forceDitherMode:something
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   226
    "set the dither mode, to one of #none or #ordered"
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
    forceDitherMode := something.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   229
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   230
    "Modified: 16.4.1997 / 20:34:59 / cg"
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
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   233
forceGrayscale:something
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   234
    "set the forceGrayscale mode; if true, grayScale images are
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   235
     returned, even if the input contains a color image."
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   236
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   237
    forceGrayscale := something.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   238
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   239
    "Created: 16.4.1997 / 20:33:44 / cg"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   240
    "Modified: 16.4.1997 / 20:34:29 / cg"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   241
! !
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   242
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   243
!JPEGReader methodsFor:'private'!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   244
2971
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   245
app1SegmentCallback
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   246
    "return a callback function which invokes the app1SegmentHandlerBlock if defined.
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   247
     This will be called to handle the exif segment, containing geolocation tags.
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   248
     Return nil, if there is no handler blcok defined"
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   249
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   250
    |cb|
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   251
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   252
    app1SegmentHandler isNil ifTrue:[^ nil].
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   253
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   254
    cb := ExternalFunctionCallback new.
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   255
    cb returnType:#bool argumentTypes:#(pointer).
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   256
    cb generateClosure.
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   257
    cb action:[:args | self fetchApp1SegmentData. true].
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   258
    ^ cb code.  'can be passed to C'.
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   259
!
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   260
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   261
create_jpeg_decompress_struct
2971
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   262
    |errMgrStructSize decompressStructSize fp errorOccurred app1SegmentCallbackFunction|
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   263
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   264
    fp := inStream filePointer.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   265
    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
   266
	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
   267
	^ self.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   268
    ].
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   269
2971
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   270
    app1SegmentCallbackFunction := self app1SegmentCallback.
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   271
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   272
%{
2050
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   273
    errMgrStructSize = __mkSmallInteger(sizeof(struct my_error_mgr));
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   274
    decompressStructSize = __mkSmallInteger(sizeof(struct jpeg_decompress_struct));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   275
%}.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   276
532
66aa3109df17 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   277
    jpeg_error_mgr_struct := ExternalBytes unprotectedNew:errMgrStructSize.
66aa3109df17 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   278
    jpeg_decompress_struct := ExternalBytes unprotectedNew:decompressStructSize.
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   279
    errorOccurred := false.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   280
1698
0512e160a112 more stack - to make sure
Claus Gittinger <cg@exept.de>
parents: 1558
diff changeset
   281
%{  /* STACK: 400000 */
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   282
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   283
    struct my_error_mgr *jerrPtr;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   284
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   285
    OBJ j_d_s = __INST(jpeg_decompress_struct);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   286
    FILE *f = __FILEVal(fp);
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   287
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   288
    if (__isExternalBytesLike(j_d_s)
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   289
     && __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
   290
	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
   291
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   292
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   293
	/*
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   294
	 * 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
   295
	 */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   296
	cinfoPtr->err = jpeg_std_error(jerrPtr);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   297
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   298
	/*
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   299
	 * prepare to handle errors smoothly ...
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   300
	 */
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   301
	jerrPtr->pub.error_exit = my_error_exit;
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   302
	if (setjmp(jerrPtr->setjmp_buffer)) {
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   303
	    /*
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   304
	     * error occurred ...
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   305
	     */
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   306
	    jpeg_destroy_decompress(cinfoPtr);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   307
	    RETURN (false);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   308
	}
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   309
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   310
       /*
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   311
	* use my message print function
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   312
	*/
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   313
       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
   314
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   315
	jpeg_create_decompress(cinfoPtr);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   316
#if 0
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   317
	/*
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   318
	 * 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
   319
	 */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   320
	jpeg_set_marker_processor(cinfoPtr, JPEG_COM, COM_handler);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   321
#endif
2971
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   322
	if (app1SegmentCallbackFunction != nil) {
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   323
	    jpeg_marker_parser_method cb = NULL;
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   324
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   325
	    if (__isExternalFunction(app1SegmentCallbackFunction)) {
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   326
		cb = (jpeg_marker_parser_method)__externalFunctionVal(app1SegmentCallbackFunction);
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   327
	    } else if (__isExternalAddress(app1SegmentCallbackFunction)) {
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   328
		cb = (jpeg_marker_parser_method)__externalAddressVal(app1SegmentCallbackFunction);
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   329
	    } else {
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   330
		/* ignore, but should report an error... */
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   331
	    }
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   332
	    jpeg_set_marker_processor(cinfoPtr, JPEG_APP0+1, cb);
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   333
	}
07bd4e98036e hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents: 2768
diff changeset
   334
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   335
	cinfoPtr->err->trace_level = 0;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   336
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   337
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   338
	/* colors setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   339
	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
   340
	cinfoPtr->quantize_colors = TRUE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   341
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   342
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   343
	/* dct setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   344
	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
   345
	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
   346
	or: cinfoPtr->dct_method = JDCT_FLOAT;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   347
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   348
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   349
	/* dither setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   350
	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
   351
	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
   352
	    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
   353
	} else {
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   354
	    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
   355
		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
   356
	    }
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   357
	}
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   358
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   359
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   360
	/* fast setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   361
	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
   362
	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
   363
	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
   364
	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
   365
	cinfoPtr->do_fancy_upsampling = FALSE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   366
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   367
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   368
	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
   369
	    /* grayscale setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   370
	    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
   371
	}
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   372
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   373
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   374
	/* maxmemory setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   375
	cinfoPtr->mem->max_memory_to_use = lval * 1000L;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   376
#endif
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   377
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   378
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   379
	/* nosmooth setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   380
	cinfoPtr->do_fancy_upsampling = FALSE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   381
#endif
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   382
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   383
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   384
	/* onepass setting */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   385
	cinfoPtr->two_pass_quantize = FALSE;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   386
#endif
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
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
	/* 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
   389
	jpeg_stdio_src(cinfoPtr, f);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   390
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   391
	/* 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
   392
	(void) jpeg_read_header(cinfoPtr, TRUE);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   393
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   394
	/* 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
   395
	jpeg_calc_output_dimensions(cinfoPtr);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   396
2050
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   397
	__INST(width) = __mkSmallInteger(cinfoPtr->output_width);
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   398
	__INST(height) = __mkSmallInteger(cinfoPtr->output_height);
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   399
	__INST(colorComponents) = __mkSmallInteger(cinfoPtr->output_components);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   400
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   401
#if 0
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   402
	/* 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
   403
	 * (colormap)
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   404
	 */
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   405
#endif
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   406
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   407
    }
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   408
%}.
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   409
    ^ true
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   410
!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   411
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   412
decompressChunkInto:aByteArray startingAt:index
1698
0512e160a112 more stack - to make sure
Claus Gittinger <cg@exept.de>
parents: 1558
diff changeset
   413
%{  /* STACK: 400000 */
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   414
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   415
    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
   416
    char *rowPtr = NULL;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   417
    OBJ j_d_s = __INST(jpeg_decompress_struct);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   418
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   419
    int num_scanlines;
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   420
    char *rowPointers[4];
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   421
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   422
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   423
    if (__isByteArray(aByteArray)) {
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   424
	rowPtr = (char *)(__ByteArrayInstPtr(aByteArray)->ba_element);
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   425
    } else if (__isExternalBytesLike(aByteArray)) {
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   426
	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
   427
    }
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   428
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   429
    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
   430
     && (rowPtr != NULL)
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   431
     && __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
   432
	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
   433
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   434
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   435
	rowPtr += __intVal(index) - 1;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   436
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   437
	rowPointers[0] = rowPtr;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   438
	rowPointers[1] = NULL;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   439
	rowPointers[2] = NULL;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   440
	rowPointers[3] = NULL;
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   441
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   442
	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
   443
	    if (setjmp(jerrPtr->setjmp_buffer)) {
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   444
		/*
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   445
		 * error occurred ...
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   446
		 */
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   447
		jpeg_destroy_decompress(cinfoPtr);
2050
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   448
		RETURN (__mkSmallInteger(-1));
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   449
	    }
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   450
	    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
   451
						rowPointers,
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   452
						1);
2050
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   453
	    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
   454
	}
2050
a955518cdad4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   455
	RETURN (__mkSmallInteger(0));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   456
    }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   457
%}.
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   458
    self halt:'bad arguments'.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   459
!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   460
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   461
extractApp1DataFrom:data
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   462
    (data startsWith:#[16r45 16r78 16r69 16r66 16r0] " = 'Exif' + 0-byte" ) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   463
        self extractExifDataFrom:data.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   464
    ].
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   465
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   466
    "Created: / 12-12-2011 / 21:22:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   467
!
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   468
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   469
extractExifDataFrom:data
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   470
    self halt
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   471
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   472
    "Created: / 12-12-2011 / 21:22:32 / cg"
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   473
!
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   474
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   475
fetchApp1SegmentData
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   476
    |byte1 byte2 count|
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   477
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   478
    byte1 := self jpeg_getc.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   479
    byte2 := self jpeg_getc.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   480
    count := (byte1 bitShift:8) + byte2. "/ msb first
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   481
    count := count - 2. "/ count itself is included
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   482
    data := ByteArray new:count.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   483
    1 to: count do:[:i |
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   484
	data at:i put:(self jpeg_getc).
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   485
    ].
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   486
    self halt.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   487
    app1SegmentHandler value:data.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   488
!
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   489
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   490
finish_decompress
1698
0512e160a112 more stack - to make sure
Claus Gittinger <cg@exept.de>
parents: 1558
diff changeset
   491
%{  /* STACK: 400000 */
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   492
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   493
    struct my_error_mgr *jerrPtr;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   494
    OBJ j_d_s = __INST(jpeg_decompress_struct);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   495
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   496
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   497
    if (__isExternalBytesLike(j_d_s)
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   498
     && __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
   499
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   500
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   501
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   502
	if (setjmp(jerrPtr->setjmp_buffer)) {
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   503
	    jpeg_destroy_decompress(cinfoPtr);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   504
	    RETURN (false);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   505
	}
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   506
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   507
	/* finish decompressor */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   508
	(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
   509
	(void) jpeg_destroy_decompress(cinfoPtr);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   510
	RETURN (true);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   511
    }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   512
%}
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   513
!
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   514
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   515
get_error_message
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   516
%{
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   517
    struct jpeg_decompress_struct *cinfoPtr;
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   518
    OBJ j_d_s = __INST(jpeg_decompress_struct);
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   519
    char buffer[JMSG_LENGTH_MAX+1];
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   520
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   521
    if (__isExternalBytesLike(j_d_s)) {
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   522
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   523
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   524
	(*cinfoPtr->err->format_message) (cinfoPtr, buffer);
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   525
	buffer[JMSG_LENGTH_MAX] = '\0';
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   526
	RETURN ( __MKSTRING(buffer));
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   527
    }
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   528
%}.
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   529
    ^ nil
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   530
!
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   531
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   532
jpeg_getc
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   533
%{
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   534
    OBJ j_d_s = __INST(jpeg_decompress_struct);
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   535
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   536
    if (__isExternalBytesLike(j_d_s)) {
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   537
	struct jpeg_decompress_struct *cinfoPtr;
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   538
	int byte;
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   539
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   540
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   541
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   542
	byte = JPG_jpeg_getc (cinfoPtr);
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   543
	RETURN( __MKSMALLINT(byte) );
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   544
    }
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   545
%}.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   546
    self primitiveFailed
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   547
!
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   548
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   549
start_decompress
1698
0512e160a112 more stack - to make sure
Claus Gittinger <cg@exept.de>
parents: 1558
diff changeset
   550
%{  /* STACK: 400000 */
536
b88ac48a1ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 535
diff changeset
   551
    struct jpeg_decompress_struct *cinfoPtr;
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   552
    struct my_error_mgr *jerrPtr;
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   553
    OBJ j_d_s = __INST(jpeg_decompress_struct);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   554
    OBJ j_e_m = __INST(jpeg_error_mgr_struct);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   555
1747
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   556
    if (__isExternalBytesLike(j_d_s)
90a5fcae4b4b also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   557
     && __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
   558
	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   559
	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   560
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   561
	if (setjmp(jerrPtr->setjmp_buffer)) {
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   562
	    jpeg_destroy_decompress(cinfoPtr);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   563
	    RETURN (false);
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   564
	}
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   565
1061
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   566
	/* Start decompressor */
e487ecc3d506 define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents: 951
diff changeset
   567
	(void) jpeg_start_decompress(cinfoPtr);
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   568
	RETURN (true);
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   569
    }
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   570
%}
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
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1747
diff changeset
   573
!JPEGReader methodsFor:'reading'!
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
fromStream:aStream
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   576
    "read a JPG image from a stream"
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   577
951
de8417214dfd read from an internal stream (save to tempfile, then read)
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
   578
    |dataIdx bytesPerRow returnCode pos1 ok tmpFile s|
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   579
895
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   580
    aStream isExternalStream ifFalse:[
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   581
        "/ 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
   582
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   583
        tmpFile := Filename newTemporary.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   584
        [
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   585
            s := tmpFile writeStream binary.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   586
            s nextPutAll:aStream contents.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   587
            s close.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   588
            s := tmpFile readStream binary.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   589
            ^ self fromStream:s.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   590
        ] ensure:[
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   591
            s notNil ifTrue:[s close].
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   592
            tmpFile delete.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   593
        ].
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   594
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   595
        "/ 'JPEGReader [info]: can only read from real streams' infoPrintCR.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   596
        "/ ^ nil
895
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   597
    ].
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   598
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   599
    inStream := aStream.
669
d38a796ad10b care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   600
    pos1 := inStream position.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   601
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   602
    "/ to extract app1 data (for example, exif geolocation tags),
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   603
    "/ uncomment the following and implement the exif tag reader...
2973
b708ff319811 comment/format in: #fromStream:
Claus Gittinger <cg@exept.de>
parents: 2972
diff changeset
   604
    "/ Warning: this does not yet work as expected.
b708ff319811 comment/format in: #fromStream:
Claus Gittinger <cg@exept.de>
parents: 2972
diff changeset
   605
    "/ app1SegmentHandler := [:data | self halt. self extractApp1DataFrom:data].
895
ebac67edf08e check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents: 669
diff changeset
   606
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   607
    (self create_jpeg_decompress_struct not
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   608
    or:[self start_decompress not]) ifTrue:[
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   609
        ok := false.
669
d38a796ad10b care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   610
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   611
        "/ if there was no SOI marker,
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   612
        "/ try again, skipping first 128 bytes
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   613
        "/ (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
   614
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   615
        inStream position:pos1.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   616
        ((inStream nextByte ~~ 16rFF)
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   617
        or:[inStream nextByte ~~ 16rD8]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   618
            inStream position:pos1 + 128.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   619
            ((inStream nextByte == 16rFF)
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   620
            and:[inStream nextByte == 16rD8]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   621
                inStream position:pos1 + 128.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   622
                ok := self create_jpeg_decompress_struct
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   623
                      and:[self start_decompress]
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   624
            ].
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   625
        ].
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   626
        ok ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   627
            'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   628
            ^ nil
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   629
        ]
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   630
    ].
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   631
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   632
    data := ByteArray uninitializedNew:(width * height * colorComponents).
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   633
    dataIdx := 1.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   634
    bytesPerRow := colorComponents * width.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   635
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   636
    [(returnCode := self decompressChunkInto:data startingAt:dataIdx) > 0] whileTrue:[
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   637
        "/ got a row in the buffer ...
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   638
        dataIdx := dataIdx + bytesPerRow
2282
ec2ab83c4b1b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
   639
    ].
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   640
    returnCode < 0 ifTrue:[
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   641
        'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   642
        ^ nil
534
d59b2e2b4fa9 error handling
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   643
    ].
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   644
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   645
    (self finish_decompress) ifFalse:[
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   646
        'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   647
        ^ nil
535
f6a45bb3aa4c error message
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   648
    ].
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   649
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   650
    colorComponents == 3 ifTrue:[
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   651
        photometric := #rgb.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   652
        samplesPerPixel := 3.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   653
        bitsPerSample := #(8 8 8).
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   654
    ] ifFalse:[
2972
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   655
        photometric := #blackIs0.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   656
        samplesPerPixel := 1.
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   657
        bitsPerSample := #(8).
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   658
    ].
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   659
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   660
    "
2768
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   661
     JPEGReader fromFile:'../../support/libjpeg-7/testimg.jpg'
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   662
    "
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   663
    "
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   664
     |stream reader|
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   665
2768
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   666
     stream := '../../support/libjpeg-7/testimg.jpg' asFilename readStream.
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   667
     reader := JPEGReader new.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   668
     reader forceGrayscale:true.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   669
     reader forceDitherMode:#ordered.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   670
     reader fromStream:stream.
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   671
     ^ reader image
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   672
    "
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   673
2973
b708ff319811 comment/format in: #fromStream:
Claus Gittinger <cg@exept.de>
parents: 2972
diff changeset
   674
    "Modified (comment): / 12-12-2011 / 21:25:09 / cg"
528
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   675
! !
e7bc0efceac9 interface to libjpeg
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
   676
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   677
!JPEGReader class methodsFor:'documentation'!
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   678
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   679
version
2973
b708ff319811 comment/format in: #fromStream:
Claus Gittinger <cg@exept.de>
parents: 2972
diff changeset
   680
    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.53 2011-12-12 20:25:19 cg Exp $'
2768
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   681
!
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   682
38e9b42f2af8 #isValidImageFile:
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   683
version_CVS
2973
b708ff319811 comment/format in: #fromStream:
Claus Gittinger <cg@exept.de>
parents: 2972
diff changeset
   684
    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.53 2011-12-12 20:25:19 cg Exp $'
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   685
! !
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1698
diff changeset
   686
199
d80a247e0cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   687
JPEGReader initialize!