A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
8
Task/Bitmap-Flood-fill/HicEst/bitmap-flood-fill.hicest
Normal file
8
Task/Bitmap-Flood-fill/HicEst/bitmap-flood-fill.hicest
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
WINDOW(WINdowhandle=wh, BaCkcolor=0, TItle="Rosetta test image")
|
||||
|
||||
WRITE(WIN=wh, DeCoRation="EL=14, BC=14") ! color 14 == bright yellow
|
||||
|
||||
RGB(128, 100, 0, 25) ! define color nr 25 as 128/255 red, 100/255 green, 0 blue
|
||||
WRITE(WIN=wh, DeCoRation="L=1/4, R=1/2, T=1/4, B=1/2, EL=25, BC=25")
|
||||
|
||||
WINDOW(Kill=wh)
|
||||
10
Task/Bitmap-Flood-fill/J/bitmap-flood-fill-1.j
Normal file
10
Task/Bitmap-Flood-fill/J/bitmap-flood-fill-1.j
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
NB. finds and labels contiguous areas with the same numbers
|
||||
NB. ref: http://www.jsoftware.com/pipermail/general/2005-August/023886.html
|
||||
findcontig=: (|."1@|:@:>. (* * 1&(|.!.0)))^:4^:_@(* >:@i.@$)
|
||||
|
||||
NB.*getFloodpoints v Returns points to fill given starting point (x) and image (y)
|
||||
getFloodpoints=: [: 4&$.@$. [ (] = getPixels) [: findcontig ] -:"1 getPixels
|
||||
|
||||
NB.*floodFill v Floods area, defined by point and color (x), of image (y)
|
||||
NB. x is: 2-item list of (y x) ; (color)
|
||||
floodFill=: (1&({::)@[ ;~ 0&({::)@[ getFloodpoints ]) setPixels ]
|
||||
9
Task/Bitmap-Flood-fill/J/bitmap-flood-fill-2.j
Normal file
9
Task/Bitmap-Flood-fill/J/bitmap-flood-fill-2.j
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
'white blue yellow black orange red'=: 255 255 255,0 0 255,255 255 0,0 0 0,255 165 0,:255 0 0
|
||||
myimg=: white makeRGB 50 70
|
||||
lines=: (_2]\^:2) 0 0 25 0 , 25 0 25 35 , 25 35 0 35 , 0 35 0 0
|
||||
myimg=: (lines;blue) drawLines myimg
|
||||
myimg=: (3 3; yellow) floodFill myimg
|
||||
myimg=: ((35 25 24 ,: 35 25 10);black) drawCircles myimg
|
||||
myimg=: (5 34;orange) floodFill myimg
|
||||
myimg=: (5 36;red) floodFill myimg
|
||||
viewRGB myimg
|
||||
7
Task/Bitmap-Flood-fill/J/bitmap-flood-fill-3.j
Normal file
7
Task/Bitmap-Flood-fill/J/bitmap-flood-fill-3.j
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
NB. ref: http://www.jsoftware.com/pipermail/general/2005-August/024174.html
|
||||
eq=:[:}:"1 [:($$[:([:+/\1:,}:~:}.),) ,&_"1 NB. equal numbers for atoms of y connected in first direction
|
||||
eq_nd=: i.@#@$(<"0@[([:, |:^:_1"0 _)&> [:EQ&.> <@|:"0 _)] NB. n-dimensional eq, gives an #@$,*/@$ shaped matrix
|
||||
repl=: (i.~{.){ {:@] NB. replaces x by applying replace table y
|
||||
cnnct=: [: |:@({."1<.//.]) [: ; <@(,.<./)/.~
|
||||
|
||||
findcontig_nd=: 3 : '($y)${. ([:({.,~}:) ([ repl cnnct)/\.)^:([:+./@(~:/)2&{.)^:_ (,{.) eq_nd (i.~ ~.@,) y'
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
'This example requires the Windows API
|
||||
NoMainWin
|
||||
WindowWidth = 267.5
|
||||
WindowHeight = 292.5
|
||||
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
|
||||
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
|
||||
|
||||
Global hDC : hDC = GetDC(0)
|
||||
Struct point, x As long, y As long
|
||||
Struct RGB, Red As long, Green As long, Blue As long
|
||||
Struct rect, left As long, top As long, right As long, bottom As long
|
||||
|
||||
StyleBits #main.gbox, 0, _WS_BORDER, 0, 0
|
||||
GraphicBox #main.gbox, 2.5, 2.5, 253, 252
|
||||
|
||||
Open "Flood Fill - Click a Color" For Window As #main
|
||||
Print #main, "TrapClose quit"
|
||||
Print #main.gbox, "Down; Fill Black; Place 125 125; BackColor White; " _
|
||||
+ "CircleFilled 115; Place 105 105; BackColor Black; CircleFilled 50; Flush"
|
||||
Print #main.gbox, "When leftButtonUp gBoxClick"
|
||||
Print #main.gbox, "Size 1"
|
||||
Wait
|
||||
|
||||
Sub quit handle$
|
||||
Call ReleaseDC 0, hDC
|
||||
Close #main
|
||||
End
|
||||
End Sub
|
||||
|
||||
|
||||
Sub gBoxClick handle$, MouseX, MouseY
|
||||
result = GetCursorPos()
|
||||
targetRGB = GetPixel(hDC, point.x.struct, point.y.struct)
|
||||
ColorDialog "", replacementColor$
|
||||
If replacementColor$ = "" Then Exit Sub
|
||||
Print #main.gbox, "Color " + Word$(replacementColor$, 1) + " " + Word$(replacementColor$, 2) + " " + Word$(replacementColor$, 3)
|
||||
result = FloodFill(MouseX, MouseY, targetRGB)
|
||||
Print #main.gbox, "DelSegment FloodFill"
|
||||
Print #main.gbox, "GetBMP FloodFill 0 0 500 500; CLS; DrawBMP FloodFill 0 0; Flush FloodFill"
|
||||
Notice "Complete!"
|
||||
UnLoadBMP "FloodFill"
|
||||
End Sub
|
||||
|
||||
Sub ReleaseDC hWnd, hDC
|
||||
CallDLL #user32,"ReleaseDC", hWnd As uLong, hDC As uLong, ret As Long
|
||||
End Sub
|
||||
|
||||
Function GetDC(hWnd)
|
||||
CallDLL #user32, "GetDC", hWnd As uLong, GetDC As uLong
|
||||
End Function
|
||||
|
||||
Function GetCursorPos()
|
||||
CallDLL #user32, "GetCursorPos", point As struct, GetCursorPos As uLong
|
||||
End Function
|
||||
|
||||
Function GetPixel(hDC, x, y)
|
||||
CallDLL #gdi32, "GetPixel", hDC As uLong, x As long, y As long, GetPixel As long
|
||||
End Function
|
||||
|
||||
Function getLongRGB(RGB.Blue)
|
||||
getLongRGB = (RGB.Blue * (256 * 256))
|
||||
End Function
|
||||
|
||||
Function GetWindowRect(hWnd)
|
||||
'Get ClientRectangle
|
||||
CallDLL #user32, "GetWindowRect", hWnd As ulong, rect As struct, GetWindowRect As ulong
|
||||
End Function
|
||||
|
||||
Function FloodFill(mouseXX, mouseYY, targetColor)
|
||||
Scan
|
||||
result = GetWindowRect(Hwnd(#main.gbox))
|
||||
X = Int(mouseXX + rect.left.struct)
|
||||
Y = Int(mouseYY + rect.top.struct)
|
||||
If (GetPixel(hDC, X, Y) <> targetColor) Then
|
||||
Exit Function
|
||||
Else
|
||||
CLS
|
||||
Print str$(mouseXX) + " " + str$(mouseYY)
|
||||
Print #main.gbox, "Set " + str$(mouseXX) + " " + str$(mouseYY)
|
||||
End If
|
||||
If (mouseXX > 0) And (mouseXX < 253) Then
|
||||
result = FloodFill((mouseXX - 1), mouseYY, targetColor)
|
||||
result = FloodFill((mouseXX + 1), mouseYY, targetColor)
|
||||
End If
|
||||
If (mouseYY > 0) And (mouseYY < 252) Then
|
||||
result = FloodFill(mouseXX, (mouseYY + 1), targetColor)
|
||||
result = FloodFill(mouseXX, (mouseYY - 1), targetColor)
|
||||
End If
|
||||
End Function
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
createMask[img_, pos_, tol_] :=
|
||||
RegionBinarize[img, Image[SparseArray[pos -> 1, ImageDimensions[img]]], tol];
|
||||
floodFill[img_Image, pos_List, tol_Real, color_List] :=
|
||||
ImageCompose[
|
||||
SetAlphaChannel[ImageSubtract[img, createMask[img, pos, tol]], 1],
|
||||
SetAlphaChannel[Image[ConstantArray[color, ImageDimensions[img]]],
|
||||
Dilation[createMask[img, pos, tol],1]
|
||||
]
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue