JPEGReader.st
changeset 1747 90a5fcae4b4b
parent 1745 4fa0fad2a463
child 1805 93f557cbe600
--- a/JPEGReader.st	Fri Apr 11 01:14:09 2003 +0200
+++ b/JPEGReader.st	Fri Apr 11 01:42:19 2003 +0200
@@ -249,8 +249,8 @@
     OBJ j_d_s = __INST(jpeg_decompress_struct);
     FILE *f = __FILEVal(fp);
 
-    if (__isExternalBytes(j_d_s)
-     && __isExternalBytes(j_e_m)) {
+    if (__isExternalBytesLike(j_d_s)
+     && __isExternalBytesLike(j_e_m)) {
 	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
 	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
 
@@ -272,8 +272,8 @@
 	}
 
        /*
-        * use my message print function
-        */
+	* use my message print function
+	*/
        jerrPtr->pub.output_message = my_output_message;
 
 	jpeg_create_decompress(cinfoPtr);
@@ -372,14 +372,14 @@
 
 
     if (__isByteArray(aByteArray)) {
-        rowPtr = (char *)(__ByteArrayInstPtr(aByteArray)->ba_element);
-    } else if (__isExternalBytes(aByteArray)) {
-        rowPtr = __externalBytesAddress(aByteArray);
+	rowPtr = (char *)(__ByteArrayInstPtr(aByteArray)->ba_element);
+    } else if (__isExternalBytesLike(aByteArray)) {
+	rowPtr = __externalBytesAddress(aByteArray);
     }
 
-    if (__isExternalBytes(j_d_s)
+    if (__isExternalBytesLike(j_d_s)
      && (rowPtr != NULL)
-     && __isExternalBytes(j_e_m)) {
+     && __isExternalBytesLike(j_e_m)) {
 	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
 	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
 
@@ -416,8 +416,8 @@
     OBJ j_d_s = __INST(jpeg_decompress_struct);
     OBJ j_e_m = __INST(jpeg_error_mgr_struct);
 
-    if (__isExternalBytes(j_d_s)
-     && __isExternalBytes(j_e_m)) {
+    if (__isExternalBytesLike(j_d_s)
+     && __isExternalBytesLike(j_e_m)) {
 	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
 	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
 
@@ -440,7 +440,7 @@
     OBJ j_d_s = __INST(jpeg_decompress_struct);
     char buffer[JMSG_LENGTH_MAX+1];
 
-    if (__isExternalBytes(j_d_s)) {
+    if (__isExternalBytesLike(j_d_s)) {
 	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
 
 	(*cinfoPtr->err->format_message) (cinfoPtr, buffer);
@@ -458,8 +458,8 @@
     OBJ j_d_s = __INST(jpeg_decompress_struct);
     OBJ j_e_m = __INST(jpeg_error_mgr_struct);
 
-    if (__isExternalBytes(j_d_s)
-     && __isExternalBytes(j_e_m)) {
+    if (__isExternalBytesLike(j_d_s)
+     && __isExternalBytesLike(j_e_m)) {
 	cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s));
 	jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m));
 
@@ -483,22 +483,22 @@
     |dataIdx bytesPerRow returnCode pos1 ok tmpFile s|
 
     aStream isExternalStream ifFalse:[
-        "/ libJpeg can only handle real OS-streams
+	"/ libJpeg can only handle real OS-streams
 
-        tmpFile := Filename newTemporary.
-        [
-            s := tmpFile writeStream binary.
-            s nextPutAll:aStream contents.
-            s close.
-            s := tmpFile readStream binary.
-            ^ self fromStream:s.
-        ] ensure:[
-            s notNil ifTrue:[s close].
-            tmpFile delete.
-        ].
+	tmpFile := Filename newTemporary.
+	[
+	    s := tmpFile writeStream binary.
+	    s nextPutAll:aStream contents.
+	    s close.
+	    s := tmpFile readStream binary.
+	    ^ self fromStream:s.
+	] ensure:[
+	    s notNil ifTrue:[s close].
+	    tmpFile delete.
+	].
         
-        "/ 'JPEGReader [info]: can only read from real streams' infoPrintCR.
-        "/ ^ nil
+	"/ 'JPEGReader [info]: can only read from real streams' infoPrintCR.
+	"/ ^ nil
     ].
 
     inStream := aStream.
@@ -507,27 +507,27 @@
 
     (self create_jpeg_decompress_struct not
     or:[self start_decompress not]) ifTrue:[
-        ok := false.
+	ok := false.
 
-        "/ if there was no SOI marker,
-        "/ try again, skipping first 128 bytes
-        "/ (seems to be generated by some jpg writers)
+	"/ if there was no SOI marker,
+	"/ try again, skipping first 128 bytes
+	"/ (seems to be generated by some jpg writers)
 
-        inStream position:pos1.
-        ((inStream nextByte ~~ 16rFF)
-        or:[inStream nextByte ~~ 16rD8]) ifTrue:[
-            inStream position:pos1 + 128.
-            ((inStream nextByte == 16rFF)
-            and:[inStream nextByte == 16rD8]) ifTrue:[
-                inStream position:pos1 + 128.
-                ok := self create_jpeg_decompress_struct
-                      and:[self start_decompress]
-            ].
-        ].
-        ok ifFalse:[
-            'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
-            ^ nil
-        ]
+	inStream position:pos1.
+	((inStream nextByte ~~ 16rFF)
+	or:[inStream nextByte ~~ 16rD8]) ifTrue:[
+	    inStream position:pos1 + 128.
+	    ((inStream nextByte == 16rFF)
+	    and:[inStream nextByte == 16rD8]) ifTrue:[
+		inStream position:pos1 + 128.
+		ok := self create_jpeg_decompress_struct
+		      and:[self start_decompress]
+	    ].
+	].
+	ok ifFalse:[
+	    'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
+	    ^ nil
+	]
     ].
 
     data := ByteArray uninitializedNew:(width * height * colorComponents).
@@ -535,27 +535,27 @@
     bytesPerRow := colorComponents * width.
 
     [(returnCode := self decompressChunkInto:data startingAt:dataIdx) > 0] whileTrue:[
-        "/ got a row in the buffer ...
-        dataIdx := dataIdx + bytesPerRow
+	"/ got a row in the buffer ...
+	dataIdx := dataIdx + bytesPerRow
     ].    
     returnCode < 0 ifTrue:[
-        'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
-        ^ nil
+	'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
+	^ nil
     ].
 
     (self finish_decompress) ifFalse:[
-        'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
-        ^ nil
+	'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR.
+	^ nil
     ].
 
     colorComponents == 3 ifTrue:[
-        photometric := #rgb.
-        samplesPerPixel := 3.
-        bitsPerSample := #(8 8 8).
+	photometric := #rgb.
+	samplesPerPixel := 3.
+	bitsPerSample := #(8 8 8).
     ] ifFalse:[
-        photometric := #blackIs0.
-        samplesPerPixel := 1.
-        bitsPerSample := #(8).
+	photometric := #blackIs0.
+	samplesPerPixel := 1.
+	bitsPerSample := #(8).
     ].
 
     "
@@ -578,7 +578,7 @@
 !JPEGReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.42 2003-04-10 14:25:44 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.43 2003-04-10 23:42:19 cg Exp $'
 ! !
 
 JPEGReader initialize!