Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Bitmap image programming with FASM macros

Name: Anonymous 2014-11-14 6:02

Sample output: http://imgur.com/a/qaluB

format binary as 'bmp'

; some basic definitions
width equ 400
height equ 400
bytesperpixel=4
foreground=dword 0x00FF00FF
background=dword 0xFF00FF00
rule=byte 241

;;;;;;;;;;;;;;;;;;;;;;;;;;;; Start image data ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
db "BM"
dd filesize, 0, pixeladdr

dibheader: dd pixeladdr - dibheader, width, height
dw 1, 32
dd 6 dup 0

pixeladdr: rept width{rept height\{dd background\}}
filesize: ; official end of pixel data in the file
scratchrow: rept width{dd background}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; End image data ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Macros ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro getoffset x,y,base,index{index = base+(y*width*bytesperpixel)+(x*bytesperpixel)}
macro paint x,y,value{store dword value at pixeladdr+(y*width*bytesperpixel)+(x*bytesperpixel)}
macro paintscratch x,v{store dword v at scratchrow+(x*bytesperpixel)}
macro pixelcolor x,y,value{load value dword from pixeladdr+(y*width*bytesperpixel)+(x*bytesperpixel)}

macro copyscratchtorow y
{
local sroff, pixoff, i
i=0
while i < width
load c dword from scratchrow+(i*bytesperpixel)
store dword c at pixeladdr+(y*width*bytesperpixel)+(i*bytesperpixel)
i=i+1
end while
}

macro getnewpixelcolor x,y,val
{
local xp,xm,xn,xpaddr,xnaddr,match,color
xp=0
xm=0
xn=0
match=0
xpaddr=x-1
xnaddr=x+1
if x=0
xpaddr=width
else if x=width
xnaddr=0
end if
pixelcolor xpaddr,y,xp
if xp=foreground
match=match+4
end if
pixelcolor x,y,xm
if xm=foreground
match=match+2
end if
pixelcolor xnaddr,y,xn
if xn=foreground
match=match+1
end if
color=background
if 1=(rule and (1 shl match)) shr match
color=foreground
end if
val=color
}

macro wolframcel
{
macro scanrow y
\{
local i,match,newpix
i=0
match=dword 0
newpix=0
repeat width-1
getnewpixelcolor %,y,match
paintscratch %,match
i=i+1
end repeat
\}
local j
j=0
while j<height
scanrow j
j=j+1
copyscratchtorow j
end while
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; End Macros ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Et Cetera ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
paint width/2, 0, foreground ; paint a single seed pixel foreground

wolframcel


Please be gentle, this is the first program that I have ever written in my entire life. I just found out that computers were for more than sending text messages to mom on yesterday, honest. On a side note, it is a complete pain in the ass to track down an off-by-one error in a bitmap image.

Also, I figured I would put this up on the shithub that I made just to follow Sympta: https://github.com/github-is-shit/fasmmacros/tree/master .

Name: Anonymous 2014-11-15 3:22

Uhh, I see uglyness. I probably should have waited until today to post this. getoffset is never used, and there are still counters from when there were while

>>2
Well, from the examples given in the documentation, store and load seem to be intended to encrypt the executable at assembly time. I suppose you could write a PNG compressing post-processor, but I don't know of a way to delete data that's already been allocated, so the filesize couldn't be reduced.

>>3
I love you too[/i]

>>4
Neat-o! Not really my thing though. I started this a while back, when http://bbs.progrider.org/prog/read/1394345263/30 mentioned it, but I was trying to do it with 24 bits. It was too stupid, so BMP had to take one for the team. I was also trying to do it more Lispy, but recursively processing it smashes the stack for all but the tiniest of images. I enjoyed the Turing machine-esque way of processing data as if it were a tape (while avoiding the constrictions in place in Brainfuck), but generating real images like those would be far too hard. For a assembly macro language, it sure does fuck you in the ass with strict typing.

>>5,6
Fuck you assface, I said PLEASE BE GENTLE. That means NO CRITICISM. Ban him, Admin-kike.

>>9
Presumably, Stephen Wolfram has enough memory can simulate an infinite grid in which to generate those. BMP files have a fixed width and can't go over, and adding a bigger scratch space would end up tacking more useless data onto the end of the file. So the edge cells matches just loop to the other side. There won't be a difference until it grows large enough to fill the entire screen, so just... lower the height.

>>20
I prefer to think of it as academic circlejerking.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List