basic bitmap storage
Useful for comparing two JPEG images saved with a different compression ratios.

You can use these pictures for testing (use the full-size version of each):



50% quality JPEG

100% quality JPEG







link to full size 50% image

link to full size 100% image

The expected difference for these two images is 1.62125%

 
now =time$( "seconds")
nomainwin
 
WindowWidth  = 1620
WindowHeight =  660
 
open "jpeg.dll" for dll as #j   '   "JPEG.DLL copyright Alyce Watson, 2003. "
 
open "RC Image Comparison- difference shown as 20 times abs( pixel_difference." for graphics_nf_nsb as #1
    #1 "trapclose [quit]"
    #1 "down ; fill black"
 
    hW =hwnd( #1)
    calldll #user32,"GetDC", hW as ulong, hdc as ulong
 
    jname1$   ="Lenna50.jpg"
    hPic1     =LoadImageFile( hW, jname1$)
    if hPic1 =0 then notice "Function failed.": wait
    loadbmp "demo1", hPic1
    hDemo1 =hbmp( "demo1")
    #1 "drawbmp demo1 10 10 ; flush"
 
    jname2$ ="Lenna100.jpg"
    hPic2     =LoadImageFile( hW, jname2$)
    if hPic2 =0 then notice "Function failed.": wait
    loadbmp "demo2", hPic2
    hDemo1    =hbmp( "demo2")
    #1 "drawbmp demo2 550 10 ; flush"
 
    c1 =16777216
    c2 =   65536
    c3 =     256
    x1 =10
    y1 =10
    x2 =550
    y2 =10
 
    for y =0 to 511
        for x =0 to 511
            pixel1  =( GetPixel( hdc,  x1 +x, y1 +y) + c1) mod c1
            b1      = int(  pixel1  /c2)
            g1      = int(( pixel1 -b1 *c2) /c3)
            r1      = int(  pixel1 -b1 *c2 -g1 *c3)
 
            pixel2  =( GetPixel( hdc, x2 +x, y2 +y) + c1) mod c1
            b2      = int(  pixel2  /c2)
            g2      = int(( pixel2 -b2 *c2) /c3)
            r2      = int(  pixel2 -b2 *c2 -g2 *c3)
 
            totalDiff =totalDiff +abs( r1 -r2) +abs( g1 -g2)+ abs( b1 -b2)
 
            #1 "color "; 20 *abs( r2 -r1); " "; 20 *abs( g2 -g1); " "; 20 *abs( b2 -b1)
            #1 "set "; 1090 +x; " "; 10 +y
            scan
        next x
    next y
 
   #1 "place 90 575 ; color white ; backcolor black"
   #1 "font courier 9 bold"
   #1 "\"; " Difference between images          =";  using( "#.#####", 100.0 *totalDiff / 512 /512 /3 /255); "%."
   #1 "\"; " Rosetta Code for these two images  =1.62125%."; "   Time taken ="; time$( "seconds") -now; " seconds."
   #1 "flush"
 
wait
 
function LoadImageFile( hWnd, file$)
    calldll #j,     "LoadImageFile",   hWnd as ulong, file$ as ptr, LoadImageFile as ulong
end function
 
function GetPixel( hDC, x, y)
    calldll #gdi32, "GetPixel",        hDC As uLong,  x As long,    y As long,     GetPixel As long
end function
 
[quit]
    if hPic1  <>0 then calldll #gdi32, "DeleteObject", hPic1 as long, re as long
    if hPic2  <>0 then calldll #gdi32, "DeleteObject", hPic2 as long, re as long
    if hDemo1 <>0 then unloadbmp "demo1"
    if hDemo2 <>0 then unloadbmp "demo2"
    close #1
    close #j
    end
 