![]() |
Forum Index : Microcontroller and PC projects : CMM2 graphics library - help needed
Author | Message | ||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi, because of need in Napoleon Commander, I wrote small graphics library and finally thought it could be useful also in other projects, so I moved it to separate repository. Right now it can just few things: ![]() FUNCTION GRF.info(pg AS INTEGER) AS STRING return MODE, BPP, y-lines, pg address, write address it's mainly combination of MM.INFO SUB GRF.saveBMP(filePath AS STRING, xx AS INTEGER, yy AS INTEGER, ww AS INTEGER, hh AS INTEGER, pp AS INTEGER) save BMP file from screen memory on xx,yy with size of ww,hh from page pp it takes bpp from current MODE (so either 8 or 16) = makes BMP smaller than MMBASICs 24bpp saves image also from other page as 0 FUNCTION GRF.getImgInfo(filePath AS STRING) AS STRING return info about graphic file, WIDTH, HEIGHT, BPP, VERSION works now just for BMP, PNG, GIF FUNCTION GRF.loadImg(filePath AS STRING, xx AS INTEGER, yy AS INTEGER, pg AS INTEGER) AS INTEGER load image to x, y, page returns 0 when NOK FUNCTION GRF.getC64info(filePath AS STRING) AS STRING get info for some C64 formats (Koala, HiEddie, Doodle, HIRES) FUNCTION GRF.loadC64(filePath AS STRING, x AS INTEGER, y AS INTEGER, pg AS INTEGER) AS INTEGER load some C64 formats to x, y, page returns 0 when NOK FUNCTION GRF.getCMMcolor(n AS INTEGER) AS INTEGER get color from standard CMM (for sprites) I would like to extend it, but I have few issues, so I need somebody for help: * loaders for RLE Doodle and Koala (.jj and .gg files) - I don't know way, but I'm no able to do it properly. They are just simple RLE with $FE as RLE sign, but... * loaders for some other 8-bit formats (from ZX Spectrum, MSX, Sord, Amstrad...). I can write something from Atari ST (Degas...), but other computers I didn't owned, so I need at least to know, if is it interest and what format is most important * GIF87a loader * get width and height info for JPG. I'm using for BMP, PNG and GIF MMBasics loader, but I'm loading it to other page than 0 and later resize it to window, so I need to know size * maybe something else ? Right now the library is built so, that basic formats (BMP, PNG, GIF, JPG) and C64 formats are separated, it's because to have for every format own FUNCTION/SUB (info and load) will bring too many SUBs into main program and this can be problem. So I expect just info and load for every category (for example GRF.getZXinfo and GRF.loadZX)... If has somebody interest in cooperation, I'll be very glas ![]() Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
These are the SUBs I use in my FileManager to get image info: 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 You are welcome to use them as is or parts of them. Jim VK7JH MMedit |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi Jim, thanks a lot! I have just to incorporate JPG info into GRF.INC and it works perfect. I have just replaced ASC(INPUT$(1,#2))*256 + ASC(INPUT$(1,#2)) with STR2BIN(UINT16, INPUT$(2, #10), BIG) Btw. you have in signature ZX81, so I expect maybe you had also ZX Spectrum (?). If yes, do you think the graphic formats .SCR (screen dump of bitmap + atributes) + .BSC (border screeen image) will cover main area of ZX? Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
No. After the ZX81 I went to Microbee, an Australian built Z80 system. Jim VK7JH MMedit |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi all, maybe is time again to refresh the graphic library (GitHub) and extend it. right now it supports this: Info and loaders for following formats: General : JPG, GIF, PNG, BMP Atari ST : PI1, PI2, PI3, PC1, PC2, PC3 C64 : DD,HED, KOA, HBM ZX Spectrum: SCR, BSC Also can save BMP in 8- and 16-bit colors. It could be interesting to add some other formats (BBC, SHARP, SORD, MSX...), but I need help from you... If somebody knows (owned) some (mainly 8-bit) computer and knows his graphics formats and (in best case) can help with loader, it will be very nice. I'm still missing some important C64 format, but also maybe Amiga IFF can be nice to have. Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |