May 30, 2020, 04:52:26 PM

Author Topic: Trying to draw on image buffer  (Read 926 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 454
Trying to draw on image buffer
« on: February 23, 2018, 03:49:11 PM »
Hi.. i have a strange issue which maybe someone can help me solve..

In my app that combines png strips into a single png strip i am creating a long empty Image
and than I draw upon this image the png images one by one..
by changing the buffer into the image buffer..

but the problem is.. when the empty image im creation is bigger than the editor resolution, it doesn't draw it.
is their a way to draw on the image buffer without making a huge ridicules editor resolution?

here is my code..

Code: [Select]

'Should collect all the images and turn them from single to strip png
'Create an output consule

Strict

Import xorsteam.xors3d
Import albalynx.albalynx
Import albalynx.connect_xors3d

 Include "../MyLibs/AlbaSection.bmx"
 Include "../MyLibs/UserInputs.bmx"
 Include "../MyLibs/StringIssues/Main.bmx"
 Include "../MyLibs/FileIssues.bmx"
 
 Global UserInput:UserInputs_clas = New UserInputs_clas
 Global Strng:StringCommands_Class = New StringCommands_Class
 Global FileMngr:FileCommands_Class = New FileCommands_Class
 Global Alba:MyAlbaLib_Class = New MyAlbaLib_Class
 
xKey("M1Rk6-581XS-g6J5W-M4UFg-M77f8")
xSetEngineSetting("Splash::TilingTime", "0")
xSetEngineSetting("Splash::AfterTilingTime", "0")

Const ScreenWidth:Float = 1200, ScrnHeight:Float = 800
xGraphics3D (ScreenWidth, ScrnHeight)

Alba.SetMyAlba("Alba/bubble.xml")

xAppTitle("SavePngStrip V0.3 By Hardcoal")

'Buttons
 Global LoadPngs_bt = alCreateGButton(aldesktop, "SelectFolderWithPngs", 5, 5, 240, 30)
 Global SaveToFile_bt = alCreateGButton(aldesktop, "Save..", 5, 35, 240, 30)
 Global Exit_bt = alCreateGButton(aldesktop, "Exit", ScreenWidth - 65, ScrnHeight - 35, 60, 30)
 
 Global Sqaure_cb = alCreateGToggleButton(aldesktop, "SquareImage", 5, 210, 120, 25, 0, "CheckBox") ; alhide(Sqaure_cb) '; alsetvalueI(Sqaure_cb, True)
 
 Global TA = alCreateGTextArea(aldesktop, "", 10, 660, 450, 5, "Output") ; allock (TA)
 
 Global Inst = alCreateGTextArea(aldesktop, "A) Choose a Folder with PNG Animations Files. ~nB) Select Whether to Square it Or Leave same Aspect. ~nC) Save the file as a Single Strip PNG", 820, 600, 300, 9, "Instructions") ; allock (Inst) ; alSetColor(Inst, $8fa32a6a, "bg_color") ; alSetColor(Inst, $ffffffff, "Value")
 
Global ImagesList:TList = CreateList()
Global DirList:TList = CreateList()
Global NewImage

Global Delayer:Float = 3, DelayerCounter, ImageCount, ImageCounter

Global ImgWidth:Float, ImgHeight:Float

'Prepare
 alHide(SaveToFile_bt)
 
 Global Camera = xCreateCamera()
 xCameraClsColor(Camera, 100, 100, 100)

 Global Failur_Flg
 
 Global WantedDir:String
 
While Not xKeyDown(1)
    Local ReloadFlg

xCls()
xRenderWorld()
xUpdateWorld()

   'Square Stuff
If alTestClick(Sqaure_cb) Then ReloadFlg = True

   'Strip Making
If alTestClick(LoadPngs_bt) Or ReloadFlg Then
Local Strng:String, IMG:Image_Type, I

Failur_Flg = 0

If ReloadFlg = False Then WantedDir = RequestDir("Choose Dir With the Pngs", CurrentDir())

    If WantedDir = "" Then

AddMessage("Load Cancled")

Else

   'Clear
    ClearStuff()

If ReloadFlg = False Then
WantedDir = WantedDir + "\"
ChangeDir(WantedDir)
End If

   'Load Images
    DirList = FileMngr.ReadDirectory(WantedDir)
For Strng = EachIn DirList

If Trim(Lower(ExtractExt(Strng))) = "png" Or Trim(Lower(ExtractExt(Strng))) = "jpg" Or Trim(Lower(ExtractExt(Strng))) = "bmp" Then

IMG = New Image_Type

IMG.ImageHandle = xLoadImage(WantedDir + Strng)

       '--Add Here Image Size Match Check--'

ListAddLast(ImagesList, IMG)

End If
Next

   'Success
If Failur_Flg = False Then

ImgWidth = ScreenWidth / ImagesList.Count()

If alGetValueI(Sqaure_cb) = False Then

If Image_Type(ImagesList.First()).ImageHandle <> 0 Then
ImgHeight = xImageHeight(Image_Type(ImagesList.First()).ImageHandle) * (ImgWidth / xImageWidth(Image_Type(ImagesList.First()).ImageHandle))
If ImgHeight = 0 Then Failur_Flg = True
Else
Failur_Flg = True
End If

Else
ImgHeight = ImgWidth
EndIf

End If

   'Success
If Failur_Flg = False Then

   'Resize Images
For Local IT:Image_Type = EachIn ImagesList
xResizeImage(IT.ImageHandle, ImgWidth, ImgHeight)
Next

       'Create Big Image
NewImage = xCreateImage(ImgWidth * ImagesList.Count(), ImgHeight)

xSetBuffer(xImageBuffer(NewImage))

ImageCount = ImagesList.Count() - 1

   'Paint on the Big Image the Images
    I = 0
For IMG = EachIn ImagesList
xDrawImage(Image_Type(ImagesList.ValueAtIndex(I)).ImageHandle, ImgWidth * I, 0)
I = I + 1
Next

xSetBuffer(xBackBuffer())

   'Success
If NewImage > 0 Then
alShow(SaveToFile_bt)
alShow(Sqaure_cb)
End If

Else 'Failure

AddMessage ("Process has Failed")
ClearStuff()

End If

End If

End If

   'Displaying
If NewImage > 0 Then
Local AnimXPos:Float = 150

   'Draw Animation
xDrawImage(Image_Type(ImagesList.ValueAtIndex(ImageCounter)).ImageHandle, AnimXPos, 100)
xRect(AnimXPos, 100, ImgWidth, ImgHeight)

   'Delay
DelayerCounter = DelayerCounter + 1
If DelayerCounter >= Delayer Then
DelayerCounter = 0
ImageCounter = ImageCounter + 1
If ImageCounter = ImageCount Then ImageCounter = 0
End If

   'Draw Big Png
    Local BRectY = 350
xDrawImage(NewImage, 0, BRectY)

   'Draw Rects
    For Local I = 0 To ImageCount
xRect(I * ImgWidth, BRectY, ImgWidth, ImgHeight)
    Next

   'Details
xText (0, BRectY - 20, "Frames Amount: " + ImageCount + " XSize: " + ImgWidth + " YSize: " + ImgHeight)

End If

   'Save
If alTestClick (SaveToFile_bt) Then
    Local FN:String
FN = RequestFile("Save As..",, True)
If FN <> "" Then
FN = AddFileExtentionIfThereIsnt(FN, "png")
xSaveImage(NewImage, FN)
AddMessage("File Save to " + FN)
End If
End If

   'Exit
If alTestClick(Exit_bt) Or xWinMessage("WM_CLOSE") > 0 Then Exit

Alba.UpdateALEvents()
UserInput.UpdateUserInputs()
xFlip()
Delay(2)

Wend

'--------------------------------------------'

Function AddMessage(Msg:String)
alSetValueS(TA, alGetValueS(TA) + MSG + "~n")
End Function

Function AddFileExtentionIfThereIsnt:String(File:String, ExtentionWithoutPoint:String) 'For Example A png file without .png will be added a .png
For Local I = Len(File) To 1 Step - 1
If Mid(File, I, 1) = "." Then Return
Next
Return File + "." + ExtentionWithoutPoint
End Function

Function ClearStuff()

For Local IT:Image_Type = EachIn ImagesList
If it.ImageHandle <> 0 Then xFreeImage(IT.ImageHandle)
IT = Null
Next
ClearList(ImagesList)
If NewImage <> 0 Then xFreeImage(NewImage) ; NewImage = 0

End Function

Type Image_Type
Field ImageHandle
End Type

Function ScaleImageToSize(Image, XSize:Float, YSize:Float)
Local ScaleX:Float, ScaleY:Float
ScaleX = XSize / xImageWidth(Image)
ScaleY = YSize / xImageHeight(Image)
xScaleImage(Image, ScaleX, ScaleY)
End Function

Function GetImageHeightRelationToWidth:Float(Img)
Return GetHeightRelation(xImageWidth(Img), xImageHeight(Img))
End Function

Function GetHeightRelation:Float(Width:Float, Height:Float)
Return Height / Width
End Function


cheers.. please save me :)
Happy New Year

Offline Derron

  • Hero Member
  • *****
  • Posts: 2975
Re: Trying to draw on image buffer
« Reply #1 on: February 23, 2018, 04:24:58 PM »
Only draw a portion of the image:DrawSubImageRect() ?

Drawing Image to Image is done using Software Rendering (paste a pixmap content into another one) - or using eg. Col's Render2Texture code (textures are limited by the GPU).

So best bet is to use Software Rendering for these things.


For utility functions look here:
https://github.com/GWRon/Dig/blob/master/base.gfx.imagehelper.bmx

In your case something like

local image:TImage = CreateImage(myWidth, myHeight, myFlags)
LockImage(image).ClearPixels(0) 'remove the garbage on the image
DrawImageOnImage(pngStripImage, image, stripPosX, stripPosY)

bye
Ron



Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 454
Re: Trying to draw on image buffer
« Reply #2 on: February 23, 2018, 04:35:21 PM »
Im using Xors.. so I guess all this does no apply in my case..
Maybe I have to give up on Xors in this case..
Happy New Year

Offline Derron

  • Hero Member
  • *****
  • Posts: 2975
Re: Trying to draw on image buffer
« Reply #3 on: February 23, 2018, 06:32:31 PM »
Can Xors work with TPixmap? The basic idea is to have some kind of pixel array (the pixmap) and copy it byte by byte to another pixmap.

This can even be done without a graphical window - so as a command line tool.


bye
Ron



 

SimplePortal 2.3.6 © 2008-2014, SimplePortal