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%

      hbm1% = FNloadimage("C:lenna50.jpg")
      hbm2% = FNloadimage("C:lenna100.jpg")
 
      SYS "CreateCompatibleDC", @memhdc% TO hdc1%
      SYS "CreateCompatibleDC", @memhdc% TO hdc2%
 
      SYS "SelectObject", hdc1%, hbm1%
      SYS "SelectObject", hdc2%, hbm2%
 
      diff% = 0
      FOR y% = 0 TO 511
        FOR x% = 0 TO 511
          SYS "GetPixel", hdc1%, x%, y% TO rgb1%
          SYS "GetPixel", hdc2%, x%, y% TO rgb2%
          diff% += ABS((rgb1% AND &FF) - (rgb2% AND &FF))
          diff% += ABS((rgb1% >> 8 AND &FF) - (rgb2% >> 8 AND &FF))
          diff% += ABS((rgb1% >> 16) - (rgb2% >> 16))
        NEXT
      NEXT y%
      PRINT "Image difference = "; 100 * diff% / 512^2 / 3 / 255 " %"
 
      SYS "DeleteDC", hdc1%
      SYS "DeleteDC", hdc2%
      SYS "DeleteObject", hbm1%
      SYS "DeleteObject", hbm2%
      END
 
      DEF FNloadimage(file$)
      LOCAL iid{}, hbm%, pic%, ole%, olpp%, text%
      DIM iid{a%,b%,c%,d%}, text% LOCAL 513
 
      iid.a% = &7BF80980 : REM. 128-bit iid
      iid.b% = &101ABF32
      iid.c% = &AA00BB8B
      iid.d% = &AB0C3000
 
      SYS "MultiByteToWideChar", 0, 0, file$, -1, text%, 256
 
      SYS "LoadLibrary", "OLEAUT32.DLL" TO ole%
      SYS "GetProcAddress", ole%, "OleLoadPicturePath" TO olpp%
      IF olpp%=0 THEN = 0
 
      SYS olpp%, text%, 0, 0, 0, iid{}, ^pic% : REM. OleLoadPicturePath
      IF pic%=0 THEN = 0
 
      SYS !(!pic%+12), pic%, ^hbm% : REM. IPicture::get_Handle
      SYS "FreeLibrary", ole%
      = hbm%