Hi all,
hoping someone can help, I am new to AGK2 but have done some projects a while back in DarkBasic Pro so not fully new to programming.
I am having some trouble with the code below regarding arrays.
This is the start of a flood fill routine which takes the image, PIC4.png a 640 x 430 image with white as the background colour and black as a line drawing for areas to colour in and then uses a 2D array of the same dimensions to store a set of numbers from 1 to ? depending on the complexity of the drawing.
The array stores a value at the pixel co-ord for x and y and is reference to a fill area. So what it does is give a fill area a specific number a bit like paint by numbers but each fill area on the screen has it's own number area.
I haven't got to the part where I actually paint yet but just doing the storing of the numbers so far.
If I run the program with the Print commands un-commented in the function storeFillPixels then the correct values are shown in the array pixelStore[x,y], however if I re-comment the Print commands back out to then see the pixelStore[x,y] values printed in the main program it shows some odd values store eg 37 and 256 instead of starting at 1.
Any ideas or if this makes sense?
I am storing the values this way instead of doing a tradition fill to obtain the different values for each fill area on my pic as the program I am creating is going to be a colouring book style program but with not the normal flood fill for colouring the areas.
Thanks in advance.
// Project: flood_fill
// Created: 2015-01-13
// Variables and Array setup
global pixelStore as integer[ 640, 430 ]
global pixelStoreStack as integer[ 20000 ]
imgWidth = 640
imgHeight = 430
// set screen properties and images
// picture is 640 x 430
drawImage = LoadImage ( "\media\PIC4.png" )
drawImageScrNum = 1
memBlock = CreateMemblockFromImage ( drawImage )
colour_backGrnd = GetPixel ( memBlock, 0, 0, imgWidth ) // Grab first pixel and set the colour as background colour
// set display properties
// SetVirtualResolution( 1024, 768 )
SetVirtualResolution( imgWidth, imgHeight )
SetOrientationAllowed( 1, 1, 1, 1 ) // 0, 0, 1, 1 horizontal value only but upside turn allowed
SetSyncRate ( 60, 0 )
// display screen
//CreateSprite ( drawImageScrNum, drawImage )
//SetSpritePosition ( drawImageScrNum, 0, 0 )
//colourFillStore.length = -1
//colourStoreStack.length = -1
StoreFillPixels ( memBlock, imgWidth, imgHeight, colour_backGrnd )
// ***** Main Game Loop *****
do
for rows = 1 to imgHeight
for columns = 1 to imgWidth
Print ( columns )
Print ( rows )
pixelcheck = pixelStore [ columns, rows ]
Print ( pixelcheck )
Sync ()
next columns
next rows
loop
// ******************** Functions **********************
// grab Memory Block pixels into an array from screen to store each fill area as a seperate value
function StoreFillPixels ( memBlockInput, img_width, img_height, colour_back )
for y = 0 to img_height
for x = 0 to img_width
pixelStore [ img_width, img_height ] = 0
next x
next y
for i = 0 to 20000
pixelStoreStack [ i ] = 0
next i
newFillAreaRow = 0
for rows = 1 to img_height
for columns = 1 to img_width
colour_test = GetPixel ( memBlockInput, columns-1, rows-1, img_width )
if colour_test = colour_back
colourAbove = 0
colourLeft = 0
if rows > 1 then colourAbove = pixelStore [ columns, rows - 1 ]
if columns > 1 then colourLeft = pixelStore [ columns - 1 , rows ]
if colourAbove = 0 and colourLeft = 0
newFillAreaRow = newFillAreaRow + 1
fillAreaNum = newFillAreaRow
pixelStoreStack [ newFillAreaRow ] = rows
else
if colourLeft <> 0 and colourAbove <> 0
if colourLeft = colourAbove
fillAreaNum = colourLeft
else
newColour = colourAbove
oldColour = colourLeft
// Checks rows/columns for new number that should be same as current fill and changes to this
for rowsAgain = pixelStoreStack [ oldColour ] to rows
for columnsAgain = 1 to img_width
if pixelStore [ columnsAgain, rowsAgain ] = oldColour
pixelStore [ columnsAgain, rowsAgain ] = newColour
if rowsAgain < pixelStoreStack [ newColour ] then pixelStoreStack [ newColour ] = rowsAgain
endif
next columnsAgain
next rowsAgain
fillAreaNum = newColour
endif
else
fillAreaNum = colourLeft + colourAbove
endif
endif
pixelStore [ columns, rows ] = fillAreaNum
endif
/*
print ("colour_test")
print (colour_test)
print ("colour_back")
print (colour_back)
print ("columns")
print (columns)
print ("rows")
print (rows)
print ("newFillAreaRow")
Print (newFillAreaRow)
print ("fillAreaNum")
print (fillAreaNum)
print ("colourLeft")
print (colourLeft)
print ("colourAbove")
print (colourAbove)
print ("pixelStore")
pixelcheck = pixelStore [ columns, rows ]
Print ( pixelcheck )
sync()
*/
next columns
next rows
endfunction
// function to obtain colour value (RGB) and Alpha value if needed of each pixel in the memory block
function GetPixel ( memBlockIn, x, y, width )
offsetPixel = 12 + (( x + ( y * width )) * 4 )
Red = GetMemBlockByte ( memBlockIn, offsetPixel )
Green = GetMemBlockByte ( memBlockIn, offsetPixel + 1 )
Blue = GetMemBlockByte ( memBlockIn, offsetPixel + 2 )
Alpha = GetMemBlockByte ( memBlockIn, offsetPixel + 3 )
PixelColourRGB = Red + Green + Blue
endfunction PixelColourRGB
Background:
AMOS on the AMIGA!