![]() |
Forum Index : Microcontroller and PC projects : Size of sprite / framebuffer
Author | Message | ||||
elk1984![]() Senior Member ![]() Joined: 11/07/2020 Location: United KingdomPosts: 228 |
At risk of someone pointing me straight to the manual (I have looked and checked in Peter's excellent Graphics Programming on the Colour Maximite 2) - is there a way to get the size of a sprite, loaded image or framebuffer. The use case is I'd like to load a bitmap bounded by a box. Of course I do know the size of the bitmap I'm loading, but if there was a way to get it from the file I'd prefer not to put hardcoded values in my program. Thanks elk1984 |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
You are asking three different things. For sprite use the SPRITE function for framebuffer use MM.INFO. For a BMP file you are going to need to read the file header and decode it.- |
||||
elk1984![]() Senior Member ![]() Joined: 11/07/2020 Location: United KingdomPosts: 228 |
Thanks - the mixing up probably reflects my head ![]() |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
These SUbs are from my FileManager program. They give the vital stats for image files. sub jpgInfo f$, onDisk AS INTEGER, iWdth AS INTEGER, iHt AS INTEGER, info$ LOCAL INTEGER block LOCAL x$ onDisk = MM.INFO(filesize f$) info$ = "" OPEN f$ FOR INPUT AS #2 DO block = ASC(INPUT$(1,#2)) ' flag for start of block IF block = 255 THEN block = ASC(INPUT$(1,#2)) ' block type IF block = &hC0 THEN x$ = INPUT$(3,#2) iHt = ASC(INPUT$(1,#2))*256 + ASC(INPUT$(1,#2)) iWdth = ASC(INPUT$(1,#2))*256 + ASC(INPUT$(1,#2)) EXIT DO elseif block = &hC2 THEN info$ = "Progressive" x$ = INPUT$(3,#2) iHt = ASC(INPUT$(1,#2))*256 + ASC(INPUT$(1,#2)) iWdth = ASC(INPUT$(1,#2))*256 + ASC(INPUT$(1,#2)) exit do ENDIF ENDIF LOOP CLOSE #2 END SUB sub bmpInfo f$, onDisk AS INTEGER, iWdth AS INTEGER, iHt AS INTEGER, info$ LOCAL x$ onDisk = MM.INFO(filesize f$) OPEN f$ FOR INPUT AS #2 x$ = INPUT$(18,#2) ' skip this iWdth = ASC(INPUT$(1,#2))+ASC(INPUT$(1,#2))*256 iWdth = iWdth +ASC(INPUT$(1,#2))*2^16+ASC(INPUT$(1,#2))*2^24 iHt = ASC(INPUT$(1,#2))+ASC(INPUT$(1,#2))*256 iHt = iHt +ASC(INPUT$(1,#2))*2^16+ASC(INPUT$(1,#2))*2^24 x$ = INPUT$(2,#2) ' colour planes - not used info$ = str$(ASC(INPUT$(1,#2))+ASC(INPUT$(1,#2))*256)+" bit" CLOSE #2 END SUB sub gifInfo f$, onDisk AS INTEGER, iWdth AS INTEGER, iHt AS INTEGER, info$ LOCAL x$, iBits as integer onDisk = MM.INFO(filesize f$) OPEN f$ FOR INPUT AS #2 x$ = INPUT$(6,#2) ' skip this GIF89a iWdth = ASC(INPUT$(1,#2))+ASC(INPUT$(1,#2))*256 iHt = ASC(INPUT$(1,#2))+ASC(INPUT$(1,#2))*256 x$ = INPUT$(1,#2) ' colour table start and bits iBits = (asc(x$) and &b00000111) + 1 'if (asc(x$) and &b10000000) then iBits = 0 - iBits ' indicate animated image CLOSE #2 info$ = str$(iBits)+" bit" END SUB sub pngInfo f$, onDisk AS INTEGER, iWdth AS INTEGER, iHt AS INTEGER, info$ ' data from https://en.wikipedia.org/wiki/Portable_Network_Graphics LOCAL x$, iBits as integer onDisk = MM.INFO(filesize f$) OPEN f$ FOR INPUT AS #2 x$ = INPUT$(12,#2) x$ = INPUT$(4,#2) ' should be IHDR iWdth = ASC(INPUT$(1,#2))*2^24 + ASC(INPUT$(1,#2))*2^16 iWdth = iWdth +ASC(INPUT$(1,#2))*256 + ASC(INPUT$(1,#2)) iHt = ASC(INPUT$(1,#2))*2^24 + ASC(INPUT$(1,#2))*2^16 iHt = iHt +ASC(INPUT$(1,#2))*256 + ASC(INPUT$(1,#2)) iBits = ASC(INPUT$(1,#2)) ' colour bits/pixel select case ASC(INPUT$(1,#2)) ' colour type case 0 info$ = str$(iBits)+" bit Grayscale" case 2 info$ = str$(iBits*3)+" bit Truecolour" case 3 info$ = str$(iBits)+" bit Palettised" case 4 info$ = str$(iBits*2)+" bit Grayscale+Alpha" case 6 info$ = str$(iBits*4)+" bit RGBA" case else info$ = str$(iBits)+" bit/pixel" end select CLOSE #2 END SUB Given the file name, they return sizes plus other info. Jim VK7JH MMedit |
||||
elk1984![]() Senior Member ![]() Joined: 11/07/2020 Location: United KingdomPosts: 228 |
That's fantastic - thanks TassyJim |
||||
elk1984![]() Senior Member ![]() Joined: 11/07/2020 Location: United KingdomPosts: 228 |
Thanks for the inspiration Jim. Using your code as a basis, I've reworked as an exercise in improving my knowledge of file handling, arrays etc. The program needs 4 images (test.bmp, test.gif, test.jpg and test.png) in the same directory as the basic file. image-info.zip Any review comments welcome, especially that would help make this standalone and reusable for others. Edited 2020-09-29 04:15 by elk1984 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |