The Trunk: Graphics-nice.298.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Graphics-nice.298.mcz

commits-2
Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.298.mcz

==================== Summary ====================

Name: Graphics-nice.298
Author: nice
Time: 27 July 2014, 4:20:11.638 pm
UUID: 170cf894-37d9-4c00-adc3-8531594246dc
Ancestors: Graphics-nice.297

Rather than commenting uggliness, remove it.

Compatibility notes:
>From now on, DON'T expect (ImageReadWriter formFromStream: yourStream) to reset yourStream. It's not its business, besides it does not work for every kind of Stream.
Resetting a Stream was only ever required for constructs like (ReadWriteStream with: 'someData') reset.
But you DON'T have to use a ReadWriteStream if it's just for reading. Rather use a ReadStream, this way, no reset is required.
If really ReadWriteStream is what fits (why?) then you'll now have to perform the reset by yourself.

=============== Diff against Graphics-nice.297 ===============

Item was changed:
  ----- Method: Form>>readNativeResourceFrom: (in category 'resources') -----
  readNativeResourceFrom: byteStream
  | img aStream |
+ aStream := byteStream.
- (byteStream isKindOf: FileStream) ifTrue:[
- "Ugly, but ImageReadWriter will send #reset which is implemented as #reopen and we may not be able to do so."
- aStream := RWBinaryOrTextStream with: byteStream contents.
- ] ifFalse:[
- aStream := byteStream.
- ].
  img := [ImageReadWriter formFromStream: aStream] on: Error do:[:ex| nil].
  img ifNil:[^nil].
  (img isColorForm and:[self isColorForm]) ifTrue:[
  | cc |
  cc := img colors.
  img colors: nil.
  img displayOn: self.
  img colors: cc.
  ] ifFalse:[
  img displayOn: self.
  ].
  img := nil.!

Item was changed:
  ----- Method: ImageReadWriter class>>formFromStream: (in category 'image reading/writing') -----
  formFromStream: aBinaryStream
  "Answer a ColorForm stored on the given stream.  closes the stream"
  | reader readerClass form  |
 
  readerClass := self withAllSubclasses
  detect: [:subclass | subclass understandsImageFormat: aBinaryStream]
  ifNone: [
  aBinaryStream close.
  ^self error: 'image format not recognized'].
+ reader := readerClass new on: aBinaryStream.
- reader := readerClass new on: aBinaryStream reset.
  Cursor read showWhile: [
  form := reader nextImage.
  reader close].
  ^ form
  !


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Graphics-nice.298.mcz

Levente Uzonyi-2
On Sun, 27 Jul 2014, [hidden email] wrote:

> Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
> http://source.squeak.org/trunk/Graphics-nice.298.mcz
>
> ==================== Summary ====================
>
> Name: Graphics-nice.298
> Author: nice
> Time: 27 July 2014, 4:20:11.638 pm
> UUID: 170cf894-37d9-4c00-adc3-8531594246dc
> Ancestors: Graphics-nice.297
>
> Rather than commenting uggliness, remove it.
>
> Compatibility notes:
>> From now on, DON'T expect (ImageReadWriter formFromStream: yourStream) to reset yourStream. It's not its business, besides it does not work for every kind of Stream.
> Resetting a Stream was only ever required for constructs like (ReadWriteStream with: 'someData') reset.
> But you DON'T have to use a ReadWriteStream if it's just for reading. Rather use a ReadStream, this way, no reset is required.
> If really ReadWriteStream is what fits (why?) then you'll now have to perform the reset by yourself.

The stream will still receive #reset many times from
#understandsImageFormat, #understandsImageFormat: and the instance side
#on: methods.
So I think this change may break #readNativeResourceFrom:.


Levente

>
> =============== Diff against Graphics-nice.297 ===============
>
> Item was changed:
>  ----- Method: Form>>readNativeResourceFrom: (in category 'resources') -----
>  readNativeResourceFrom: byteStream
>   | img aStream |
> + aStream := byteStream.
> - (byteStream isKindOf: FileStream) ifTrue:[
> - "Ugly, but ImageReadWriter will send #reset which is implemented as #reopen and we may not be able to do so."
> - aStream := RWBinaryOrTextStream with: byteStream contents.
> - ] ifFalse:[
> - aStream := byteStream.
> - ].
>   img := [ImageReadWriter formFromStream: aStream] on: Error do:[:ex| nil].
>   img ifNil:[^nil].
>   (img isColorForm and:[self isColorForm]) ifTrue:[
>   | cc |
>   cc := img colors.
>   img colors: nil.
>   img displayOn: self.
>   img colors: cc.
>   ] ifFalse:[
>   img displayOn: self.
>   ].
>   img := nil.!
>
> Item was changed:
>  ----- Method: ImageReadWriter class>>formFromStream: (in category 'image reading/writing') -----
>  formFromStream: aBinaryStream
>   "Answer a ColorForm stored on the given stream.  closes the stream"
>   | reader readerClass form  |
>
>   readerClass := self withAllSubclasses
>   detect: [:subclass | subclass understandsImageFormat: aBinaryStream]
>   ifNone: [
>   aBinaryStream close.
>   ^self error: 'image format not recognized'].
> + reader := readerClass new on: aBinaryStream.
> - reader := readerClass new on: aBinaryStream reset.
>   Cursor read showWhile: [
>   form := reader nextImage.
>   reader close].
>   ^ form
>  !
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Graphics-nice.298.mcz

Nicolas Cellier



2014-07-28 2:16 GMT+02:00 Levente Uzonyi <[hidden email]>:
On Sun, 27 Jul 2014, [hidden email] wrote:

Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.298.mcz

==================== Summary ====================

Name: Graphics-nice.298
Author: nice
Time: 27 July 2014, 4:20:11.638 pm
UUID: 170cf894-37d9-4c00-adc3-8531594246dc
Ancestors: Graphics-nice.297

Rather than commenting uggliness, remove it.

Compatibility notes:
>From now on, DON'T expect (ImageReadWriter formFromStream: yourStream) to reset yourStream. It's not its business, besides it does not work for every kind of Stream.
Resetting a Stream was only ever required for constructs like (ReadWriteStream with: 'someData') reset.
But you DON'T have to use a ReadWriteStream if it's just for reading. Rather use a ReadStream, this way, no reset is required.
If really ReadWriteStream is what fits (why?) then you'll now have to perform the reset by yourself.

The stream will still receive #reset many times from #understandsImageFormat, #understandsImageFormat: and the instance side #on: methods.
So I think this change may break #readNativeResourceFrom:.


Levente


Thanks Levente, this requires more patching and testing.
 


=============== Diff against Graphics-nice.297 ===============

Item was changed:
 ----- Method: Form>>readNativeResourceFrom: (in category 'resources') -----
 readNativeResourceFrom: byteStream
        | img aStream |
+       aStream := byteStream.
-       (byteStream isKindOf: FileStream) ifTrue:[
-               "Ugly, but ImageReadWriter will send #reset which is implemented as #reopen and we may not be able to do so."
-               aStream := RWBinaryOrTextStream with: byteStream contents.
-       ] ifFalse:[
-               aStream := byteStream.
-       ].
        img := [ImageReadWriter formFromStream: aStream] on: Error do:[:ex| nil].
        img ifNil:[^nil].
        (img isColorForm and:[self isColorForm]) ifTrue:[
                | cc |
                cc := img colors.
                img colors: nil.
                img displayOn: self.
                img colors: cc.
        ] ifFalse:[
                img displayOn: self.
        ].
        img := nil.!

Item was changed:
 ----- Method: ImageReadWriter class>>formFromStream: (in category 'image reading/writing') -----
 formFromStream: aBinaryStream
        "Answer a ColorForm stored on the given stream.  closes the stream"
        | reader readerClass form  |

        readerClass := self withAllSubclasses
                detect: [:subclass | subclass understandsImageFormat: aBinaryStream]
                ifNone: [
                        aBinaryStream close.
                        ^self error: 'image format not recognized'].
+       reader := readerClass new on: aBinaryStream.
-       reader := readerClass new on: aBinaryStream reset.
        Cursor read showWhile: [
                form := reader nextImage.
                reader close].
        ^ form
 !