mirror of
https://github.com/Dadido3/noita-mapcap.git
synced 2024-11-18 17:17:31 +00:00
Format Capture.pb
This commit is contained in:
parent
15e2b88ed5
commit
d9d8c9cd78
@ -1,4 +1,4 @@
|
|||||||
; Copyright (c) 2019-2023 David Vogel
|
; Copyright (c) 2019-2024 David Vogel
|
||||||
;
|
;
|
||||||
; This software is released under the MIT License.
|
; This software is released under the MIT License.
|
||||||
; https://opensource.org/licenses/MIT
|
; https://opensource.org/licenses/MIT
|
||||||
@ -16,14 +16,14 @@ Structure QueueElement
|
|||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure GLViewportDims
|
Structure GLViewportDims
|
||||||
x.i
|
x.i
|
||||||
y.i
|
y.i
|
||||||
width.i
|
width.i
|
||||||
height.i
|
height.i
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure WorkerInfo
|
Structure WorkerInfo
|
||||||
workerNumber.i
|
workerNumber.i
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
; Returns the size of the main OpenGL rendering output.
|
; Returns the size of the main OpenGL rendering output.
|
||||||
@ -42,10 +42,10 @@ ProcedureDLL GetRect(*rect.RECT)
|
|||||||
If Not *rect
|
If Not *rect
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
Protected dims.GLViewportDims
|
Protected dims.GLViewportDims
|
||||||
glGetIntegerv_(#GL_VIEWPORT, dims)
|
glGetIntegerv_(#GL_VIEWPORT, dims)
|
||||||
|
|
||||||
*rect\left = dims\x
|
*rect\left = dims\x
|
||||||
*rect\top = dims\y
|
*rect\top = dims\y
|
||||||
*rect\right = dims\x + dims\width
|
*rect\right = dims\x + dims\width
|
||||||
@ -61,10 +61,10 @@ ProcedureDLL AttachProcess(Instance)
|
|||||||
|
|
||||||
CreateDirectory("mods/noita-mapcap/output/")
|
CreateDirectory("mods/noita-mapcap/output/")
|
||||||
|
|
||||||
Static Workers = 8
|
Static Workers = 8
|
||||||
Dim WorkerInfos.WorkerInfo(Workers-1)
|
Dim WorkerInfos.WorkerInfo(Workers-1)
|
||||||
For i = 0 To Workers-1
|
For i = 0 To Workers-1
|
||||||
WorkerInfos(i)\workerNumber = i
|
WorkerInfos(i)\workerNumber = i
|
||||||
CreateThread(@Worker(), @WorkerInfos(i))
|
CreateThread(@Worker(), @WorkerInfos(i))
|
||||||
Next
|
Next
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@ -89,11 +89,11 @@ Procedure Worker(*workerInfo.WorkerInfo)
|
|||||||
ResizeImage(img, sx, sy)
|
ResizeImage(img, sx, sy)
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; Save image temporary, and only move it once it's fully exported.
|
; Save image temporary, and only move it once it's fully exported.
|
||||||
; This prevents images getting corrupted when the main process crashes.
|
; This prevents images getting corrupted when the main process crashes.
|
||||||
If SaveImage(img, "mods/noita-mapcap/output/worker_" + *workerInfo\workerNumber + ".tmp", #PB_ImagePlugin_PNG)
|
If SaveImage(img, "mods/noita-mapcap/output/worker_" + *workerInfo\workerNumber + ".tmp", #PB_ImagePlugin_PNG)
|
||||||
RenameFile("mods/noita-mapcap/output/worker_" + *workerInfo\workerNumber + ".tmp", "mods/noita-mapcap/output/" + x + "," + y + ".png")
|
RenameFile("mods/noita-mapcap/output/worker_" + *workerInfo\workerNumber + ".tmp", "mods/noita-mapcap/output/" + x + "," + y + ".png")
|
||||||
; We can't really do anything when either SaveImage or RenameFile fails, so just silently fail.
|
; We can't really do anything when either SaveImage or RenameFile fails, so just silently fail.
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
FreeImage(img)
|
FreeImage(img)
|
||||||
@ -117,15 +117,15 @@ ProcedureDLL Capture(*capRect.RECT, x.l, y.l, sx.l, sy.l)
|
|||||||
If *capRect\bottom < *capRect\top : *capRect\bottom = *capRect\top : EndIf
|
If *capRect\bottom < *capRect\top : *capRect\bottom = *capRect\top : EndIf
|
||||||
If *capRect\right > viewportRect\right : *capRect\right = viewportRect\right : EndIf
|
If *capRect\right > viewportRect\right : *capRect\right = viewportRect\right : EndIf
|
||||||
If *capRect\bottom > viewportRect\bottom : *capRect\bottom = viewportRect\bottom : EndIf
|
If *capRect\bottom > viewportRect\bottom : *capRect\bottom = viewportRect\bottom : EndIf
|
||||||
|
|
||||||
Protected capWidth = *capRect\right - *capRect\left
|
Protected capWidth = *capRect\right - *capRect\left
|
||||||
Protected capHeight = *capRect\bottom - *capRect\top
|
Protected capHeight = *capRect\bottom - *capRect\top
|
||||||
|
|
||||||
imageID = CreateImage(#PB_Any, capWidth, capHeight)
|
imageID = CreateImage(#PB_Any, capWidth, capHeight)
|
||||||
If Not imageID
|
If Not imageID
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
;Protected *pixelBuf = AllocateMemory(3 * width * height)
|
;Protected *pixelBuf = AllocateMemory(3 * width * height)
|
||||||
|
|
||||||
hDC = StartDrawing(ImageOutput(imageID))
|
hDC = StartDrawing(ImageOutput(imageID))
|
||||||
@ -133,22 +133,22 @@ ProcedureDLL Capture(*capRect.RECT, x.l, y.l, sx.l, sy.l)
|
|||||||
FreeImage(imageID)
|
FreeImage(imageID)
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
*pixelBuffer = DrawingBuffer()
|
|
||||||
glReadPixels_(*capRect\left, *capRect\top, capWidth, capHeight, #GL_BGR_EXT, #GL_UNSIGNED_BYTE, *pixelBuffer)
|
|
||||||
|
|
||||||
;For y = 0 To *capRect\height - 1
|
*pixelBuffer = DrawingBuffer()
|
||||||
; *Line.Pixel = Buffer + Pitch * y
|
glReadPixels_(*capRect\left, *capRect\top, capWidth, capHeight, #GL_BGR_EXT, #GL_UNSIGNED_BYTE, *pixelBuffer)
|
||||||
;
|
|
||||||
; For x = 0 To *capRect\width - 1
|
; For y = 0 To *capRect\height - 1
|
||||||
|
; *Line.Pixel = Buffer + Pitch * y
|
||||||
;
|
;
|
||||||
; *Line\Pixel = ColorTable(pos2) ; Write the pixel directly to the memory !
|
; For x = 0 To *capRect\width - 1
|
||||||
; *Line+Offset
|
;
|
||||||
;
|
; *Line\Pixel = ColorTable(pos2) ; Write the pixel directly to the memory !
|
||||||
; ; You can try with regular plot to see the speed difference
|
; *Line+Offset
|
||||||
; ; Plot(x, y, ColorTable(pos2))
|
;
|
||||||
; Next
|
; ; You can try with regular plot to see the speed difference
|
||||||
; Next
|
; ; Plot(x, y, ColorTable(pos2))
|
||||||
|
; Next
|
||||||
|
; Next
|
||||||
|
|
||||||
StopDrawing()
|
StopDrawing()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user