Author Topic: Binary image app to test.  (Read 611 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7638
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Binary image app to test.
« on: May 07, 2020, 05:59:28 PM »
I have only posted the binary as I have not caught up with distributing the library yet, I will get that done when I have everything else done.

This app is close to a working application, it will open a number of different image file formats but will save a normal RGB bitmap, an RGBA bitmap and JPG files. With all types it will scale the image by percentage to smaller or larger sizes and with JPG files a quality setting that ranges from 100 down to 0.

With this combination you can get very good quality smaller images as the size reduction effectively sharpens the image and with the JPG quality setting, you can experiment to see how much lower you can go before JPG artifacts start to show up.

I have the documentation done, when I catch up with the libraries I will post the source.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2383
Re: Binary image app to test.
« Reply #1 on: May 07, 2020, 07:15:59 PM »
Hi Hutch,

Nice work :thumbsup: Tested on Windows 10 64-bit.

Siekmanski

  • Member
  • *****
  • Posts: 2377
Re: Binary image app to test.
« Reply #2 on: May 07, 2020, 10:02:59 PM »
Works on Win8.1, doesn't save with the filename extension.
Creative coders use backward thinking techniques as a strategy.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7638
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Binary image app to test.
« Reply #3 on: May 07, 2020, 10:04:41 PM »
 I use the standard file dialog where you must type in the file extension as well.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2383
Re: Binary image app to test.
« Reply #4 on: May 07, 2020, 10:10:53 PM »
Hi Hutch,

Like MS Paint, your application could automatically add the extensions.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7638
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Binary image app to test.
« Reply #5 on: May 08, 2020, 03:56:34 AM »
Here is a version that fixes invalid extensions or no extension at all. I don't personally like the technique and if this was release commercial software, I would loop back with an error message if there was an invalid or missing extension. The technique used is to test if there is a valid extension and simply add one if it has not. This is the safest way but you can end up with double extension file names.

flename.bmp.jpg

To back analyse alternatives is a very unreliable way to perform this task.
This is the algo used.

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

fixext proc pname:QWORD,extt:QWORD
  ; -----------------------------------
  ; note that the buffer address is
  ; reused each time the proc is called
  ; -----------------------------------
    LOCAL pbuf  :QWORD
    LOCAL pst1  :QWORD
    LOCAL str1[32]:BYTE

    .data?
      Buff@@$$@@ db 260 dup (?)             ; buffer with mangled name
    .code

    mov pst1, ptr$(str1)                    ; get both pointers
    mov pbuf, ptr$(Buff@@$$@@)

    rcall szCopy,pname,pbuf                 ; copy file name to Buff@@$$@@
    rcall szRight,pbuf,pst1,4               ; get the right 4 characters

    mov pst1, lcase$(pst1)                  ; convert both strings to lower case
    mov extt, lcase$(extt)
    rcall szCmp,pst1,extt                   ; test if they are the same

    .If rax eq 0
      rcall szCatStr,pbuf,extt              ; append the extension if invalid
      mov rax, pbuf                         ; return address of modified buffer
      ret
    .Else
      mov rax, pbuf                         ; just return the buffer address
      ret
    .EndIf

fixext endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2383
Re: Binary image app to test.
« Reply #6 on: May 08, 2020, 04:49:15 AM »
Hi Hutch,

Thanks for this version supporting automatic extensions. :thumbsup:

nidud

  • Member
  • *****
  • Posts: 2001
    • https://github.com/nidud/asmc
Re: Binary image app to test.
« Reply #7 on: May 08, 2020, 04:59:39 AM »
A simpler approach is to just add the extension:

    .if strrchr(file, '.')
        mov byte ptr [rax],0
    .endif
    strcat(file, ext)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7638
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Binary image app to test.
« Reply #8 on: May 08, 2020, 05:22:32 AM »
nidud,

Its a good design but you run into people who use periods within their file names "file.name.ext" and this would truncate the name of the file. You could scan it backwards from the end but its not without its problems. On any serious release software a loop back if there is an extension error is probably the safest way to do it.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

nidud

  • Member
  • *****
  • Posts: 2001
    • https://github.com/nidud/asmc
Re: Binary image app to test.
« Reply #9 on: May 08, 2020, 05:41:37 AM »
Its a good design but you run into people who use periods within their file names "file.name.ext" and this would truncate the name of the file. You could scan it backwards from the end but its not without its problems. On any serious release software a loop back if there is an extension error is probably the safest way to do it.

The strrchr() do a reverse scan from the end, strchr() from the start. However, you also have dotted directory names if it's a full path (C:\my.images\image) so the functions normally used also scans for the last slash:

    .if strrchr(rdi, '\')
        lea rdi,[rdi+1]
    .endif
    .if strrchr(rdi, '.')
        mov byte ptr [rax],0
    .endif
    strcat(rdi, ext)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7638
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Binary image app to test.
« Reply #10 on: May 08, 2020, 10:39:53 AM »
That looks like useful code but the task I have addressed is the file name that is typed into a file dialog box that does not have the drive and path attached to it. I do a bit more work than you have done to avoid a number of problems, I copy the original string to a 260 byte buffer then check if the extension matches, if it does it is passed back to the caller, if it does not match the extension is added to it then returned back to the caller.

I like simple solutions but the simplest solution is for the user to enter the correct file name with the correct extension and then the programmer does not have to make multiple assumptions on how to fix the manually typed entry.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: