Skip to content

Commit

Permalink
Merge pull request #89 from hpi-swa-teaching/feature/71-jpg-import.b.b
Browse files Browse the repository at this point in the history
Add JPEG Import
  • Loading branch information
ClFeSc authored Jun 30, 2021
2 parents 56c19d4 + 8b32cef commit e134780
Show file tree
Hide file tree
Showing 46 changed files with 130 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ tool selection
commit: aForm at: aPoint
| magnifiedForm |
magnifiedForm := aForm magnifyBy: self viewPort scalar reciprocal.
self project: magnifiedForm at: aPoint.
self alphaBlend: magnifiedForm at: aPoint.
self
currentUserAction: (M2UserAction new backend: self);
saveStateInCurrentUserAction.
self currentUserAction addMethodCall: #project:at:
self currentUserAction addMethodCall: #alphaBlend:at:
withArguments: { magnifiedForm . aPoint }.
self finishUserAction
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
tool selection
importPNG: aFileName
importImage: aFileName
| tempForm |
self switchMode.
tempForm := (Form fromFileNamed: aFileName).
self form setExtent: (tempForm extent) depth: tempForm depth.
self project: tempForm at: 0 asPoint.
self form setExtent: (tempForm extent) depth: self defaultDepth.
self paint: tempForm at: 0 asPoint.
self
formChanged;
pushNewUndoLevelWithForm: self copyForm. "add an empty User Action to simulate importPNG being one"
pushNewUndoLevelWithForm: self copyForm. "add an empty User Action to simulate importImage being one"
self viewPort refresh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"cachedForm" : "mk 6/13/2020 14:39",
"clearCanvas" : "JP 6/26/2021 18:06",
"clearCanvasAndPushUndoLevel" : "mk 7/27/2020 20:29",
"commit:at:" : " 6/28/2021 21:03:28",
"commit:at:" : "CS 6/29/2021 11:35",
"createUserActionWithStart:" : "NC 8/5/2020 18:34",
"currentGeometricForm:" : "mp 5/22/2020 10:36",
"currentUserAction" : "mk 6/13/2020 13:12",
Expand All @@ -25,8 +25,8 @@
"exportAsPNG:" : "CS 6/1/2021 15:48",
"fillShape" : "CS 6/28/2021 21:24",
"finishUserAction" : "CS 6/1/2021 17:13",
"importPNG:" : "JP 5/31/2021 19:10",
"initialize" : " 6/28/2021 21:03:28",
"importImage:" : "JP 5/31/2021 19:10",
"initialize" : "6/28/2021 21:03:28",
"isErasing:" : "NC 7/24/2020 13:03",
"isFillingGeometricForm:" : "mp 7/27/2020 17:26",
"latestActionQueue" : "mk 6/13/2020 12:38",
Expand All @@ -51,5 +51,5 @@
"userActionClickAt:" : "CS 6/2/2021 11:57",
"userActionMoveDrawing:" : "CS 6/2/2021 20:21",
"userActionStopDrawing" : "JP 6/2/2021 18:37",
"viewPort" : " 6/28/2021 21:03:28",
"viewPort:" : " 6/28/2021 21:03:28" } }
"viewPort" : "6/28/2021 21:03:28",
"viewPort:" : "6/28/2021 21:03:28" } }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ setCanvasSize: aPoint
self backend
formChanged;
clearCanvas;
project: tempForm at: 0 asPoint;
paint: tempForm at: 0 asPoint;
pushNewUndoLevelWithForm: self backend copyForm.
self viewPort refresh
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"class" : {
"defaultCanvasSize" : " 6/28/2021 21:03:28",
"newWith:ofSize:" : " 6/28/2021 21:03:28" },
"defaultCanvasSize" : "6/28/2021 21:03:28",
"newWith:ofSize:" : "6/28/2021 21:03:28" },
"instance" : {
"addGripMorph:" : "JP 5/19/2021 00:31",
"backend" : "mk 7/27/2020 20:43",
"extent:" : "wr 6/22/2020 16:26",
"fastFramingOn" : "JP 5/19/2021 00:17",
"gripMorph" : "CS 5/16/2021 20:20",
"gripMorph:" : "CS 5/16/2021 20:21",
"handlesKeyboard:" : " 6/28/2021 21:03:28",
"handlesKeyboard:" : "6/28/2021 21:03:28",
"handlesMouseDown:" : "mp 5/17/2020 11:53",
"handlesMouseMove:" : "mp 5/17/2020 11:52",
"handlesMouseOver:" : "mFr 6/11/2021 15:31",
"handlesMouseOverDragging:" : "mp 5/17/2020 11:52",
"handlesMouseWheel:" : " 6/28/2021 21:03:28",
"handlesMouseWheel:" : "6/28/2021 21:03:28",
"initialize" : "CS 6/2/2021 14:41",
"isControlKeyEvent:" : " 6/28/2021 21:03:28",
"isCtrlPressed" : " 6/28/2021 21:03:28",
"isCtrlPressed:" : " 6/28/2021 21:03:28",
"isControlKeyEvent:" : "6/28/2021 21:03:28",
"isCtrlPressed" : "6/28/2021 21:03:28",
"isCtrlPressed:" : "6/28/2021 21:03:28",
"isMouseDown:" : "NC 5/16/2020 13:16",
"keyDown:" : " 6/28/2021 21:03:28",
"keyUp:" : " 6/28/2021 21:03:28",
"keyDown:" : "6/28/2021 21:03:28",
"keyUp:" : "6/28/2021 21:03:28",
"maximumSize" : "CS 5/19/2021 19:50",
"mouseDown:" : "mk 7/3/2020 18:38",
"mouseEnterDragging:" : "mp 7/27/2020 16:58",
"mouseLeave:" : "JP 6/26/2021 18:18",
"mouseLeaveDragging:" : "mFr 6/11/2021 14:36",
"mouseMove:" : "CS 6/28/2021 21:31",
"mouseUp:" : "mk 7/3/2020 19:27",
"mouseWheel:" : " 6/28/2021 21:03:28",
"mouseWheel:" : "6/28/2021 21:03:28",
"relativeMousePosition:" : "mp 5/15/2020 12:42",
"setCanvasSize:" : "CS 5/19/2021 19:50",
"updateExtent" : " 6/28/2021 21:03:28",
"updateExtent" : "6/28/2021 21:03:28",
"updateGripMorphPosition" : "CS 5/17/2021 10:50",
"viewPort" : " 6/28/2021 21:03:28",
"viewPort:" : " 6/28/2021 21:03:28",
"zoomDefault" : " 6/28/2021 21:03:28",
"zoomIn" : " 6/28/2021 21:03:28",
"zoomOut" : " 6/28/2021 21:03:28" } }
"viewPort" : "6/28/2021 21:03:28",
"viewPort:" : "6/28/2021 21:03:28",
"zoomDefault" : "6/28/2021 21:03:28",
"zoomIn" : "6/28/2021 21:03:28",
"zoomOut" : "6/28/2021 21:03:28" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
drawing
alphaBlend: aForm at: aPoint
self project: aForm at: aPoint rule: Form blendAlphaScaled
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
drawing
paint: aForm at: aPoint
self project: aForm at: aPoint rule: Form paint

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
drawing
project: aForm at: aPoint rule: aCombinationRule
self form
copyBits: (0 asPoint corner: aForm extent)
from: aForm
at: aPoint
clippingBox: (0 asPoint corner: self form extent)
rule: aCombinationRule
fillColor: nil
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"newWithExtent:context:" : "mFr 6/25/2021 08:52" },
"instance" : {
"addText" : "CS 6/28/2021 21:26",
"alphaBlend:at:" : "CS 6/29/2021 11:35",
"brushSize" : "CS 6/11/2021 18:19",
"clearCanvas" : "CS 6/11/2021 18:41",
"clickAt:" : "CS 6/11/2021 18:16",
Expand Down Expand Up @@ -38,6 +39,7 @@
"formSize" : "mFr 6/25/2021 08:54",
"formSize:" : "CS 6/11/2021 17:25",
"moveDrawing:" : "CS 6/23/2021 14:44",
"paint:at:" : "CS 6/29/2021 11:33",
"pen" : "CS 6/11/2021 17:31",
"pen:" : "CS 6/11/2021 17:31",
"penColor" : "CS 6/11/2021 17:32",
Expand All @@ -46,7 +48,7 @@
"pencilSize" : "CS 6/23/2021 14:11",
"prepareCirclePenOn:radius:" : "CS 6/11/2021 17:55",
"prepareTrianglePenSource" : "CS 6/11/2021 18:32",
"project:at:" : "ms 6/28/2021 18:16",
"project:at:rule:" : "CS 6/29/2021 11:35",
"projectUnclipped:at:" : "K.P. 6/26/2021 16:36",
"rectangleBrushSize" : "jb 6/16/2021 22:28",
"reloadCurrentPen" : "CS 6/11/2021 18:24",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
M2ImportImage is an M2IconMenuItem used to invoke the functionality to import an image.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
actionSelector
^ #importPNG
^ #importImage
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
label
^ 'Import Image'
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"class" : {
"actionSelector" : "mFr 5/19/2021 12:32",
"actionSelector" : "mFr 6/3/2021 21:16",
"icon" : "mFr 5/19/2021 10:50",
"isActivatable" : "mFr 5/19/2021 12:32",
"label" : "mFr 5/19/2021 12:32" },
"label" : "mFr 6/3/2021 21:19" },
"instance" : {
} }
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
],
"classvars" : [
],
"commentStamp" : "wr 8/4/2020 13:07",
"commentStamp" : "mFr 6/26/2021 21:13",
"instvars" : [
],
"name" : "M2ImportPNG",
"name" : "M2ImportImage",
"pools" : [
],
"super" : "M2IconMenuItem",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defaults
allowedFileExtensions
^ {'png' . 'jpg' . 'jpeg'}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
getNameOfFileToImport
^ FileChooserDialog openOn: FileDirectory default suffixList: {'png'} label: 'Import PNG'
^ FileChooserDialog openOn: FileDirectory default suffixList: self class allowedFileExtensions label: 'Import Image'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
accessing
importPNG: aString
self backend importPNG: aString.
importImage: aString
self backend importImage: aString.
self canvas
extent: self backend form extent;
changed;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
accessing
importPNG
importImage
| fileName |
fileName := self getNameOfFileToImport.
fileName ifNotNil: [self importPNG: fileName]
fileName ifNotNil: [self importImage: fileName]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ accessing
menuMiscCollection
^ menuMiscCollection ifNil: [menuMiscCollection := (OrderedCollection new)
add: (M2ClearCanvas getMenuItemForTarget: self);
add: (M2ImportPNG getMenuItemForTarget: self);
add: (M2ImportImage getMenuItemForTarget: self);
add: (M2ExportMorph getMenuItemForTarget: self backend);
add: (M2ExportPNG getMenuItemForTarget: self);
add: (M2Undo getMenuItemForTarget: self);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
event handling
pasteClipboard
self viewPort isInEditingTextMode ifTrue: [^ self].
self importPNG: Clipboard clipboardText asString.
self importImage: Clipboard clipboardText asString.
self canvas changed
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"class" : {
"addToWorldMenu" : "K.P. 5/27/2021 11:21",
"allowedFileExtensions" : "mFr 6/26/2021 21:07",
"borderColor" : "K.P. 5/29/2021 14:14",
"borderWidth" : "mFr 5/26/2021 12:11",
"canvasPanelBorder" : "mFr 5/26/2021 12:00",
"newWith:" : " 6/28/2021 21:03:28",
"newWith:" : "6/28/2021 21:03:28",
"open" : "K.P. 5/27/2021 11:22",
"openWith:" : " 6/28/2021 21:03:28",
"openWith:" : "6/28/2021 21:03:28",
"topPanelHeight" : "mFr 5/26/2021 12:02" },
"instance" : {
"activateDefaultItem" : "mFr 5/19/2021 11:03",
Expand All @@ -16,7 +17,7 @@
"brushSizeSlider" : "mFr 5/26/2021 11:30",
"brushSizeSlider:" : "mFr 5/26/2021 11:31",
"canvas" : "mFr 5/19/2021 10:58",
"canvas:" : " 6/28/2021 21:03:28",
"canvas:" : "6/28/2021 21:03:28",
"canvasPanel" : "mFr 5/19/2021 10:59",
"canvasPanel:" : "mFr 5/19/2021 10:59",
"chooseColor" : "CS 6/1/2021 19:10",
Expand All @@ -30,10 +31,10 @@
"exportPNG" : "mFr 5/19/2021 11:00",
"form" : "mFr 5/19/2021 11:00",
"getNameOfFileToExport" : "mFr 5/19/2021 11:00",
"getNameOfFileToImport" : "mFr 5/19/2021 11:00",
"getNameOfFileToImport" : "mFr 6/9/2021 17:50",
"handleKeystroke:" : "mFr 5/19/2021 11:00",
"importPNG" : "mFr 5/19/2021 11:00",
"importPNG:" : "mFr 5/19/2021 11:01",
"importImage" : "mFr 6/3/2021 21:17",
"importImage:" : "mFr 6/3/2021 21:17",
"initialize" : "K.P. 5/29/2021 14:20",
"initializeCanvasPanel" : "mk 7/27/2020 20:15",
"initializeColorPanel" : "mFr 5/19/2021 11:01",
Expand All @@ -45,17 +46,17 @@
"menuBrushCollection:" : "mFr 5/19/2021 12:17",
"menuGeometricCollection" : "CS 6/28/2021 21:36",
"menuGeometricCollection:" : "mFr 5/19/2021 12:17",
"menuMiscCollection" : "mFr 5/19/2021 12:22",
"menuMiscCollection" : "mFr 6/3/2021 21:16",
"menuMiscCollection:" : "mFr 5/19/2021 12:17",
"menuPanel" : "mFr 5/19/2021 10:57",
"menuPanel:" : "mFr 5/19/2021 10:57",
"minimumExtent" : "mFr 5/26/2021 12:05",
"paneColor" : " 6/28/2021 21:03:28",
"paneColor" : "6/28/2021 21:03:28",
"pasteClipboard" : "mFr 5/19/2021 10:57",
"setColor:" : "ms 6/16/2021 10:33",
"submenuDict" : "mFr 5/26/2021 11:54",
"submenuDict:" : "mFr 5/19/2021 12:23",
"topPanel" : "mFr 5/19/2021 10:58",
"topPanel:" : "mFr 5/19/2021 10:58",
"undo" : "mFr 5/19/2021 10:58",
"viewPort" : " 6/28/2021 21:03:28" } }
"viewPort" : "6/28/2021 21:03:28" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
importImage: aString
super importImage: aString.
self lastCalledMethod: #importImage:

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"exportAsMorph" : "NC 8/7/2020 21:51",
"exportAsPNG:" : "NC 8/7/2020 21:45",
"exportPNG" : "NC 8/7/2020 21:37",
"importPNG:" : "mp 8/7/2020 20:42",
"lastCalledMethod" : "K.P. 6/26/2021 14:36",
"lastCalledMethod:" : "K.P. 6/26/2021 14:36",
"importImage:" : "mFr 6/26/2021 21:05",
"lastCalledMethod" : "mp 8/7/2020 17:13",
"lastCalledMethod:" : "mp 8/7/2020 17:14",
"undo" : "mp 8/7/2020 17:43" } }

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
support
importTestJPEGPath
^ self fileDirectory pathName, FileDirectory slash, 'importTestJPEG.jpeg'
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ initializeLocalFiles
self fileDirectory
assureExistence;
deleteLocalFiles.
self class importTestPNG writePNGfileNamed: self importTestPNGPath.
self class importTestPNG writePNGfileNamed: self importTestPNGPath.
self class importTestJPEG writeJPEGfileNamed: self importTestJPEGPath

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
testCachedFormAfterJPEGImport
self backend importImage: self importTestJPEGPath.
self compare: self backend cachedForm with: #importTestJPEG
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
testCachedFormAfterPNGImport
self backend importImage: self importTestPNGPath.
self compare: self backend cachedForm with: #importTestPNG

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
testFormAfterJPEGImport
self backend importImage: self importTestJPEGPath.
self compareBackendFormWith: #importTestJPEG
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
testFormAfterPNGImport
self backend importImage: self importTestPNGPath.
self compareBackendFormWith: #importTestPNG
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
testing
testUndoAfterImport
self backend importPNG: self importTestPNGPath.
self backend importImage: self importTestPNGPath.
self drawFrom: 10 asPoint To: 20 asPoint.
self backend undo.
self compareBackendFormWith: #importTestPNG
Loading

0 comments on commit e134780

Please sign in to comment.