The MASM Forum

General => The Laboratory => Topic started by: hutch-- on April 26, 2020, 07:29:21 PM

Title: JPG UI test piece to save as JPG files.
Post by: hutch-- on April 26, 2020, 07:29:21 PM
With the design work that Marinus has done, I have modified the original code to work as a module so I can later add it into the library. This test piece will load images (I have been testing on BMP files) and will save them back to disk as JPG files with different quality levels which are set in a dialog after the file save dialog has closed.

The BMP files I have been testing with are mainly hi res scenery which are very fussy about JPG artifacts but 75% looks good, 50% still looks OK, 25% is starting to degrade and 10% looks terrible. If you are using simple images you can probably get better results with the lower quality settings but generally the results at various quality settings are at least as good as the software I have been using for years.
Title: Re: JPG UI test piece to save as JPG files.
Post by: Vortex on April 26, 2020, 09:55:56 PM
Hi Hutch,

Rebuilding your application, it works fine on XP 64-bit :thumbsup:
Title: Re: JPG UI test piece to save as JPG files.
Post by: hutch-- on April 26, 2020, 10:05:47 PM
Thanks Erol, I only have win7 and win10 64 bit. When I can find a bit more brain space, I will try and digest the data you prepared on GDI+ to understand how the CLSID's are derived.
Title: Re: JPG UI test piece to save as JPG files.
Post by: Siekmanski on April 26, 2020, 10:33:04 PM
Works OK on win8.1
Title: Re: JPG UI test piece to save as JPG files.
Post by: Siekmanski on April 26, 2020, 10:52:34 PM
Hi Hutch,

If you mean, to enumerate all the Image Type CLSIDs?
That's not necessary, you can use 1 GUID for all Image Types.

Image_BMP       equ 0
Image_JPG       equ 1
Image_GIF       equ 2
Image_TIF       equ 5
Image_PNG       equ 6

.data
CLSID_ImageTypes        GUID <0557CF400h,01A04h,011D3h,<09Ah,073h,000h,000h,0F8h,01Eh,0F3h,02Eh>> ; for all image types

.code
    mov     byte ptr [CLSID_ImageTypes],Image_PNG ; select any of the Image types
    invoke  GdipSaveImageToFile,pImage,"ImageName.png",addr CLSID_ImageTypes,NULL
Title: Re: JPG UI test piece to save as JPG files.
Post by: hutch-- on April 27, 2020, 01:10:31 AM
I have tidied up the save JPG algo and it is now ready for a library. Removed any unnecessary names in the data sections, mangled the necessary ones and it is all testing up OK.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

SaveImgAsJpg proc BmpHndl:QWORD,filename:QWORD,quality:QWORD

    LOCAL pImage :QWORD

  ; -------------------------------------------------
  ; names are mangled to avoid accidental duplication
  ; -------------------------------------------------
  .data?
    QualityLevel_@@@ dd ?

  .data
    align 16
    JPG_CLSID_@@@@@@ GUID <0557CF401h,01A04h,011D3h,<09Ah,073h, \
                           000h,000h,0F8h,01Eh,0F3h,02Eh>>          ; JPG image type
    Parameters_@@@@@ dd 1                                           ; parameters in this structure
                     dd 0                                           ; alignment !
                     GUID <01d5be4b5h,0fa4ah,0452dh,<09ch,0ddh, \   ; CLSID_EncoderQuality
                           05dh,0b3h,051h,005h,0e7h,0ebh>>
                     dd 1                                           ; Number of the parameter values
                     dd 4                                           ; ValueTypeLong
                     dq offset QualityLevel_@@@                     ; JpgQualityParameterPTR
  .code
  ; -------------------------------------------------

    cmp quality, 100
    jbe next

    mov quality, 75                                                 ; default for quality error

  next:
    rcall GdipCreateBitmapFromHBITMAP,BmpHndl,0,ptr$(pImage)        ; convert BMP handle
    mov rax, quality                                                ; set the quality level
    mov QualityLevel_@@@, eax                                       ; 100 = highest, 0 = lowest
    invoke GdipSaveImageToFile,pImage,L(filename), \
           ADDR JPG_CLSID_@@@@@@,ADDR Parameters_@@@@@              ; write JPG image to file
    rcall GdipDisposeImage,pImage                                   ; delete GDIP handle

    ret

SaveImgAsJpg endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤