JPEGReader.st
author Claus Gittinger <cg@exept.de>
Thu, 07 Dec 1995 11:34:06 +0100
changeset 134 f83c245371c2
parent 114 e577a2f332d0
child 199 d80a247e0cfe
permissions -rw-r--r--
checkin from browser

"
 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.
"
!

version
    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.11 1995-11-11 16:04:36 cg Exp $'
!

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.
"
! !

!JPEGReader class methodsFor:'initialization'!

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

!JPEGReader class methodsFor:'reading from file'!

fromFile:aFileName
    "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 ..' errorPrintNL.
    (OperatingSystem executeCommand:'djpeg -gif ' , aFileName , ' > ' , tempFileName)
    ifTrue:[
	reader := GIFReader fromFile:tempFileName.
	OperatingSystem executeCommand:'rm ' , tempFileName.
	^ reader
    ].
    'JPEGREADER: conversion failed ..' errorPrintNL.
    self warn:'cannot execute jpeg converter: djpeg'.
    ^ nil

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