JPEGReader.st
author Claus Gittinger <cg@exept.de>
Sat, 26 Oct 1996 19:17:33 +0200
changeset 346 1612c23d9c5d
parent 306 6d55c68f83f9
child 398 aef700d15416
permissions -rw-r--r--
pass all dropInfo to an end-action

"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

ImageReader subclass:#JPEGReader
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Graphics-Images-Support'
!

!JPEGReader class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    Reader for JPEG images.

    This is a quick&dirty hack, using the PD djpeg tool to convert 
    the JPG image to GIF first, then reads the GIF image using GIFReader.

    Of course, this is slower than it should be. If lots of JPG reading
    is done, this class should be rewritten, to directly call the (C) JPG
    decoding functions.

    Only reading of files is supported.

    CAVEAT:
        you have to have the djpeg program installed.

    [See also:]
        Image Form Icon
        BlitImageReader FaceReader GIFReader PBMReader PCXReader 
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
        XBMReader XPMReader XWDReader 
"
! !

!JPEGReader class methodsFor:'initialization'!

initialize
    "install myself in the Image classes fileFormat table
     for the `.jpg', '.jpeg' and '.JPG' extensions."

    Image fileFormats at:'.jpg'  put:self.
    Image fileFormats at:'.jpeg'  put:self.
    Image fileFormats at:'.JPG'  put:self.

    "Modified: 23.4.1996 / 12:28:03 / cg"
! !

!JPEGReader class methodsFor:'reading from file'!

fromFile:aFileName
    "read a jpg image from a file.
     Make it the easy way: let djpeg convert it to gif,
     then let GIFReader read the file."

    |tempFileName reader|

    tempFileName := '/tmp/img' , (OperatingSystem getProcessId printString).
    'JPEGREADER: converting to gif ..' errorPrintCR.
    (OperatingSystem executeCommand:'djpeg -gif ' , aFileName , ' > ' , tempFileName)
    ifTrue:[
        reader := GIFReader fromFile:tempFileName.
        OperatingSystem executeCommand:'rm ' , tempFileName.
        ^ reader
    ].
    'JPEGREADER: conversion failed ..' errorPrintCR.
    'JPEGREADER: .. cannot execute jpeg converter: djpeg' errorPrintCR.
    ^ nil

    "
     JPEGReader fromFile:'bitmaps/testimg.jpg'
    "

    "Modified: 23.4.1996 / 12:30:12 / cg"
! !

!JPEGReader class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.17 1996-06-18 21:53:37 cg Exp $'
! !
JPEGReader initialize!