[squeak-dev] The Inbox: Graphics-ct.443.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Oct 9 14:15:27 UTC 2020


Christoph Thiede uploaded a new version of Graphics to project The Inbox:
http://source.squeak.org/inbox/Graphics-ct.443.mcz

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

Name: Graphics-ct.443
Author: ct
Time: 9 October 2020, 4:15:09.97236 pm
UUID: 897346b7-ceaa-1a43-874f-3571d893309c
Ancestors: Graphics-pre.439

Adds basic support for storing an animated GIF file via AnimatedGIFReadWriter.

Note that this implementation indeed is very rudimentary only. I found several GIF files on my computer that cannot be saved as a GIF correctly (something is wrong with the encoding of the background/alpha color). But on the other hand, I also met a number of GIF files that cannot be read by the AnimatedGIFReadWriter ("error: improper store") ...
For a potentially relevant reference implementtion, I found this one, but I did not yet find the time apply it: https://gist.github.com/JimBobSquarePants/cac72c4e7d9f05f13ac9

Following the idea of "baby steps", I'd like to get this into the Trunk at this early state however. The motivation behind this is that I would like to use this concept from another project so establishing the protocol as soon as possible would be helpful for me to write tests.

=============== Diff against Graphics-pre.439 ===============

Item was added:
+ ----- Method: AnimatedGIFReadWriter class>>exampleAnim (in category 'examples') -----
+ exampleAnim
+ 	"AnimatedGIFReadWriter exampleAnim"
+ 
+ 	| extent center frames |
+ 	extent := 42 @ 42.
+ 	center := extent // 2.
+ 	frames := (2 to: center x - 1 by: 2) collect: [:r |
+ 		"Make a fancy anim without using Canvas - inefficient as hell"
+ 		| image |
+ 		image := ColorForm extent: extent depth: 8.
+ 		0.0 to: 359.0 do: [:theta |
+ 			image
+ 				colorAt: (center + (Point r: r degrees: theta)) rounded
+ 				put: Color red].
+ 		image].
+ 	
+ 	^ FileStream newFileNamed: 'anim.gif' do: [:stream |
+ 		self
+ 			putForms: frames
+ 			andDelays: (frames withIndexCollect: [:frame :index |
+ 				10 + (index / frames size * 100)]) "Start fast, end slow"
+ 			onStream: stream]!

Item was added:
+ ----- Method: AnimatedGIFReadWriter class>>putForms:andDelays:onStream: (in category 'image reading/writing') -----
+ putForms: forms andDelays: delays onStream: aWriteStream
+ 	"Store the given form sequence as an animation on the given stream."
+ 
+ 	| writer canvas |
+ 	self assert: forms size = delays size.
+ 	
+ 	writer := self on: aWriteStream.
+ 	canvas := Form extent: forms first extent depth: 32.
+ 	[Cursor write showWhile: [
+ 		writer loopCount: -1.
+ 		forms with: delays do: [:form :delay |
+ 			writer delay: delay; flag: #todo. "ct: Does not work"
+ 			form displayOn: canvas at: 0 @ 0 rule: Form over.
+ 			writer nextPutImage: canvas]]]
+ 		ensure: [writer close].!

Item was added:
+ ----- Method: AnimatedGIFReadWriter class>>putForms:onFileNamed: (in category 'image reading/writing') -----
+ putForms: formSequence onFileNamed: fileName
+ 	"Store the given form sequence as an animation on a file of the given name."
+ 
+ 	FileStream newFileNamed: fileName do: [:stream |
+ 		self putForms: formSequence onStream: stream].!

Item was added:
+ ----- Method: AnimatedGIFReadWriter class>>putForms:onStream: (in category 'image reading/writing') -----
+ putForms: forms onStream: aWriteStream
+ 	"Store the given form sequence as an animation on the given stream."
+ 
+ 	^ self
+ 		putForms: forms
+ 		andDelays: ((1 to: forms size) collect: [:i | 20])
+ 		onStream: aWriteStream!

Item was changed:
  ----- Method: BMPReadWriter class>>readAllFrom: (in category 'testing') -----
  readAllFrom: fd
  	"MessageTally spyOn:[BMPReadWriter readAllFrom: FileDirectory default]"
  	fd fileNames do:[:fName|
  		(fName endsWith: '.bmp') ifTrue:[
+ 			[Form fromBinaryStream: (fd readOnlyFileNamed: fName)] ifError: [].
- 			[Form fromBinaryStream: (fd readOnlyFileNamed: fName)] on: Error do:[:nix].
  		].
  	].
  	fd directoryNames do:[:fdName|
  		self readAllFrom: (fd directoryNamed: fdName)
  	].!

Item was removed:
- ----- Method: GIFReadWriter class>>exampleAnim (in category 'examples') -----
- exampleAnim
- 	"GIFReadWriter exampleAnim"
- 
- 	| writer extent center |
- 	writer := GIFReadWriter on: (FileStream newFileNamed: 'anim.gif').
- 	writer loopCount: 20.		"Repeat 20 times"
- 	writer delay: 10.		"Wait 10/100 seconds"
- 	extent := 42 at 42.
- 	center := extent / 2.
- 	Cursor write showWhile: [
- 		[2 to: center x - 1 by: 2 do: [:r |
- 			"Make a fancy anim without using Canvas - inefficient as hell"
- 			| image |
- 			image := ColorForm extent: extent depth: 8.
- 			0.0 to: 359.0 do: [:theta | image colorAt: (center + (Point r: r degrees: theta)) rounded put: Color red].
- 			writer nextPutImage: image]
- 		]	ensure: [writer close]].!



More information about the Squeak-dev mailing list