RIFFReader.st
author Claus Gittinger <cg@exept.de>
Mon, 14 Apr 1997 15:09:09 +0200
changeset 526 263d3775d846
parent 525 59e97643a8bc
child 541 9b654ff94202
permissions -rw-r--r--
*** empty log message ***

'From Smalltalk/X, Version:3.1.5 on 11-apr-1997 at 6:49:46 pm'                  !

ImageReader subclass:#RIFFReader
	instanceVariableNames:'chunkSize streamTypes'
	classVariableNames:'UnsupportedFormatErrorSignal'
	poolDictionaries:''
	category:'Graphics-Images-Support'
!

!RIFFReader class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG
              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
"
    Helper to read RIFF files.
"
! !

!RIFFReader class methodsFor:'class initialization'!

initialize
    UnsupportedFormatErrorSignal isNil ifTrue:[
        UnsupportedFormatErrorSignal := ErrorSignal newSignalMayProceed:true.
        UnsupportedFormatErrorSignal nameClass:self message:#unsupportedFormatErrorSignal.
    ].

    "
     RIFFReader initialize
    "

    "Created: 4.4.1997 / 22:35:52 / cg"
    "Modified: 5.4.1997 / 16:12:16 / cg"
! !

!RIFFReader class methodsFor:'testing'!

isRIFFFile:aFileName
    "return true, if aFileName contains RIFF-encoded data"

    |data1 inStream|

    inStream := self streamReadingFile:aFileName.
    inStream isNil ifTrue:[^ false].
    inStream binary.

    data1 := String new:4.
    inStream nextBytes:4 into:data1.
    inStream close.

    ^ (data1 = 'RIFF')

    "
     RIFFReader isRIFFFile:'bitmaps/magtape.xpm'    
     RIFFReader isRIFFFile:'/home2/pd_stuff/movies/avi/drlair.avi'      
    "

    "Created: 4.4.1997 / 22:35:52 / cg"
    "Modified: 5.4.1997 / 16:12:16 / cg"
! !

!RIFFReader methodsFor:'reading from stream'!

getChunk
    "get a single chunk"

    |id s sel streamNr streamType|

    'getChunk -> ' infoPrint.

    id := '    '.
    inStream nextBytes:4 into:id startingAt:1.
    chunkSize := inStream nextLongMSB:false.

    (id at:4) == Character space ifTrue:[
        id := id copyTo:3
    ].

    (id at:1) isDigit ifTrue:[
        streamNr := Number readFrom:(id copyTo:2).
        streamType := streamTypes at:(streamNr + 1).
        s := 'getChunk_' , streamType , '_' , (id copyFrom:3).       
    ] ifFalse:[
        s := 'getChunk_' , id.
    ].
    sel := s asSymbolIfInterned.
    (sel isNil or:[(self respondsTo:sel) not]) ifTrue:[
        '[' infoPrint. s infoPrint. '] ' infoPrint.
        sel := #'getChunk_Unknown'    
    ].

    self perform:sel.

    '' infoPrintCR.

    "Created: 5.4.1997 / 16:29:40 / cg"
    "Modified: 11.4.1997 / 14:00:42 / cg"
!

getChunk_LIST
    "process a LIST chunk"

    'getChunk_LIST' infoPrint.

    inStream skip:4.

    "
     AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'      
    "

    "Created: 4.4.1997 / 23:18:33 / cg"
    "Modified: 5.4.1997 / 16:12:16 / cg"
!

getChunk_RIFF
    "process a RIFF chunk"

    'getChunk_RIFF' infoPrint.

    inStream skip:4.

    "
     AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'      
    "

    "Created: 4.4.1997 / 23:18:08 / cg"
    "Modified: 5.4.1997 / 16:12:16 / cg"
!

getChunk_Unknown
    "ignore any other chunk"

    'getChunk_Unknown -> ' infoPrint.

    self skipChunk

    "
     AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'      
    "

    "Created: 5.4.1997 / 00:03:43 / cg"
    "Modified: 5.4.1997 / 16:12:16 / cg"
!

skipChunk
    "skip a chunk"

    |sz|

    'skipChunk' infoPrint.

    sz := chunkSize.
    (sz bitTest:1) ifTrue:[
        sz := sz + 1
    ].

    inStream skip:sz.

    "
     AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'      
    "

    "Created: 5.4.1997 / 14:13:43 / cg"
    "Modified: 5.4.1997 / 16:12:16 / cg"
! !

!RIFFReader class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/RIFFReader.st,v 1.2 1997-04-14 13:09:09 cg Exp $'
! !
RIFFReader initialize!