PFF IMAGE FORMAT

General Computer Utilities
NTech
Posts: 7
Joined: Mon May 01, 2017 7:29 pm

PFF IMAGE FORMAT

Post by NTech » Thu Jul 27, 2017 7:25 pm

This converts bitmaps into 200x200 .pff files. You can then
load the .pff file and see it. Upgrade it!

***What It Needs***

-Smaller File Size
-Faster Writing Time
-Support For Variable Image Sizes

***Please Note***

-The .pff file is BIGGER then a .bmp file
of the same image
-The file writing time takes a while (at least
a minute)

***Thoughts***

-Could convert it into a 8-color image generator
(black,brown,red,green,blue,yellow,purple,orange)
which would save LOTS of kb's by assigning each
color a number (e.g. 1 = black 2 = brown etc.).
The only trouble with that is reading a bitmap into
those specific colors.

:idea:

Code: Select all

'PFF (Personalized File Format) picture
'converts .bmp's to .pff
'draws .pff files
'
'by N-Tech
'
'UPGRADES DUE:
'-smaller file size
'-faster save routine (currently 1-3 minutes)
'-support for different sizes of image
'
'
'PLEASE NOTE: THE IMAGE THAT IT SAVES AND LOADS IS 200x200 RESOLUTION
'             IT DOES NOT DESTINFUISH THE SIZE OF THE BITMAP.

global col$, x, y,red,green,blue,colr$

    nomainwin

    WindowWidth = 400
    WindowHeight = 400
    x = 1
    y = 1

    menu #main, "Menu", "Load .bmp", [load], "Save .pff", [save], "Load .pff", [loadPFF]
    open "Convert .bmp to .pff" for graphics as #main
    print #main, "font ms_sans_serif 0 16"
    #main, "fill black;flush image"

[main.inputLoop]   'wait here for input event
    wait



[load]   'Perform action for menu Menu, item Load .bmp
#main, "fill black;flush image"
filedialog "Load a .bmp", "C:\*.bmp",file$
if file$ = "" then wait
if right$(file$,4) <> ".bmp" then
notice "Invalid File Type: ";right$(file$,4)
wait
end if
loadbmp "d", file$
#main, "drawbmp d;flush image"
unloadbmp "d"
wait


[save]   'Perform action for menu Menu, item Save .pff
filedialog "Save a .pff", "C:\*.pff",filer$
if filer$ = "" then wait
if right$(filer$,4) <> ".pff" then filer$ = filer$ + ".pff"
open filer$ for output as #f
for i = 1 to 200
    for j = 1 to 200
    a = GetPixelBlueValue(i,j,"#main")
    '#f, red;" ";green;" ";blue
    next j
next i
notice "File Saved"
close #f

wait

[loadPFF]   'Perform action for menu Menu, item Load .pff
#main, "fill black;flush"
filedialog "Open a .pff", "C:\*.pff", filet$
if filet$ = "" then wait
if right$(filet$,4) <> ".pff" then
notice "Invalid File Type: ";right$(filet$,4)
wait
end if
    open filet$ for input as #f

for x = 1 to 200
    for y = 1 to 200
        input #f, colr$
        #main, "down"
        #main, "color ";colr$ : #main, "backcolor ";colr$
        #main, "size 1"
        #main, "up"
        #main, "goto ";x;" ";y
        #main, "down"
        #main, "set ";x;" ";y
        #main, "up"
    next y
next x

        close #f
        #main, "flush"

        notice "Loaded"

        wait

function GetPixelBlueValue(v, t, handle$) 'function by Uncle Ben (found in spriteMaker)
'Grab a 1*1 bitmap
    #handle$, "getbmp gpv "; v; " "; t; " "; 1; " "; 1
'Save in a bmp file
    bmpsave "gpv", "getpvaluetemp";times;".bmp"
'Open the file for string input and get it's full contents
    open "getpvaluetemp";times;".bmp" for input as #gpv
    s$ = input$(#gpv, lof(#gpv))
    close #gpv
'Check if user's display is 32-bit, and read the red-green-blue values
'otherwise function returns nothing (support for other display types could be added
    if asc(mid$(s$, 29, 1)) = 32 then
        red = asc(mid$(s$, 69, 1))
        green = asc(mid$(s$, 68, 1))
        blue = asc(mid$(s$, 67, 1))
    end if
'concatenate the return value, delete temporary file and free memory
    GetPixelBlueValue = blue
    'kill "getpvaluetemp.bmp"
    unloadbmp "gpv"
    'confirm "continue";an$
    'if an$ = "no" then end
    'notice red;" ";green;" ";blue
    #f, red;" ";green;" ";blue
end function

8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8) 8)