News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

JPG UI test piece to save as JPG files.

Started by hutch--, April 26, 2020, 07:29:21 PM

Previous topic - Next topic

hutch--

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.

Vortex

Hi Hutch,

Rebuilding your application, it works fine on XP 64-bit :thumbsup:

hutch--

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.

Siekmanski

Creative coders use backward thinking techniques as a strategy.

Siekmanski

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
Creative coders use backward thinking techniques as a strategy.

hutch--

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

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