Author Topic: Looking for a JPEG library  (Read 356 times)

NoCforMe

  • Member
  • **
  • Posts: 77
Looking for a JPEG library
« on: November 09, 2018, 05:35:35 PM »
This may have been asked and answered already; my apologies if I missed it, but I can't seem to find what I'm looking for here.

I'd like to get a library for JPEG images, preferably free of course. Nothing fancy; I really only need to be able to read and save images.

I tried to download Intel's library, but can't use it (I'm still running XP and it seems to be made for a later OS version).

Any help appreciated!

Vortex

  • Member
  • *****
  • Posts: 1863
Re: Looking for a JPEG library
« Reply #1 on: November 10, 2018, 04:15:49 AM »

jj2007

  • Member
  • *****
  • Posts: 8826
  • Assembler is fun ;-)
    • MasmBasic
Re: Looking for a JPEG library
« Reply #2 on: November 10, 2018, 05:47:14 AM »
What exactly do you want to achieve? Here is a snippet that rotates all files dragged over the exe, using Gdi+ GdipImageRotateFlip:

include \masm32\MasmBasic\Res\MbGui.asm         ; download
  SetGlobals imgCt
  GetFiles CL                           ; translate commandline to an array of files
  mov imgCt, eax                        ; drag some files over the exe

Event Paint
  GuiImageCallback ImgSave
  dec imgCt
  .if Sign?
        MsgBox 0, Str$("%i files converted", Files$(?)), "Hi", MB_OK
        Exit
  .else
        GuiImage Files$(imgCt), fit     ; paint the image, fit to window
  .endif
EndOfEvents

ImgSave:                                       ; user-defined callback function
  gdi+ GdipImageRotateFlip, giImage, 1         ; giImage stands for GuiImageCallBackObject
  SaveImageToFile Cat$(Left$(Files$(imgCt), Rinstr(Files$(imgCt), ".jpg", 1)-1)+"_rotated.jpg")
  GuiCls                        ; trigger one Paint event for each file
  ret
GuiEnd

NoCforMe

  • Member
  • **
  • Posts: 77
Re: Looking for a JPEG library
« Reply #3 on: November 10, 2018, 04:14:22 PM »
Hello,

Image display functions
Screenshot with small size

Thanks, but those don't do me any good as I'm using a 32-bit OS (XP). Any other suggestions?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5897
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Looking for a JPEG library
« Reply #4 on: November 10, 2018, 07:32:46 PM »
I hate to have to tell you this but your forum name "NoCforMe" is probably the main obstruction to you getting what you are after. People who write many different computer languages all have to deal with an OS that is written primarily in C and while in this case, assemblers deal with C formats just fine, if you shut the door on C you have shut the door on much of what the OS has to offer.

You could look at GDIPLUS for at least some of what you are after but appreciate that there is no easy path to get what you are after.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Vortex

  • Member
  • *****
  • Posts: 1863
Re: Looking for a JPEG library
« Reply #5 on: November 10, 2018, 07:58:01 PM »
Hello NoCforMe,

Those examples are working under Windows XP 32-bit :

http://masm32.com/board/index.php?topic=4828.msg51959#msg51959 ( Screenshot with small size )
http://masm32.com/board/index.php?topic=4731.msg51075#msg51075 ( level lower the compression in images jpg )

Attached is the image library for Windows XP 32-bit.

NoCforMe

  • Member
  • **
  • Posts: 77
Re: Looking for a JPEG library
« Reply #6 on: November 11, 2018, 03:06:22 PM »
Attached is the image library for Windows XP 32-bit.

Thanks for that; I'll play with it. Couple things, though: any documentation? I guess I can figure out how to make it work from the sample code provided, but no details. And there doesn't seem to be a function to save to a JPEG. Anyhow, thanks again.

jj2007

  • Member
  • *****
  • Posts: 8826
  • Assembler is fun ;-)
    • MasmBasic
Re: Looking for a JPEG library
« Reply #7 on: November 11, 2018, 03:33:52 PM »
I realised that my example above doesn't work in my XP VM, and I wonder why... here is the SaveImageToFile macro showing the 4 Gdi+ functions used in bold, IMHO they should work in XP:

SaveImageToFile MACRO siFileW, quality:=<0>
  push ebx
  push ecx
  push eax                      ; hBmp slot
  mov ebx, wRec$(repargA(siFileW))
  mov ecx, esp
  gdi+ GdipCloneImage, giImage, ecx
  GetEncoderCLSID PROTO :DWORD
  invoke GetEncoderCLSID, ebx
  mov ecx, stack
  gdi+ GdipSaveImageToFile, ecx, ebx, eax, quality
  pop ecx
  gdi+ GdipDisposeImage, ecx
  pop ecx
  pop ebx
ENDM

Vortex

  • Member
  • *****
  • Posts: 1863
Re: Looking for a JPEG library
« Reply #8 on: November 11, 2018, 07:18:37 PM »
Hi NoCforMe,

Quote
And there doesn't seem to be a function to save to a JPEG.

Did you check the links I posted above? They save bitmaps as JPEGs and they are commented.

José Roca's forum explains a lot about the GDI+ functions :

http://www.jose.it-berater.org/smfforum/index.php?board=277.60

The GDI+ has it's own workflow to deal with images so you need to create your function to convert images to JPEG.

mabdelouahab

  • Member
  • ***
  • Posts: 397
Re: Looking for a JPEG library
« Reply #9 on: November 12, 2018, 08:18:30 AM »
an example
Code: [Select]
    ;------------------------------------------------------------
invoke _Open ,0,0,chr$("Image",0,"*.bmp;*.jpg;*.png",0,0) ; select image
.if eax
mov FileName,eax
printf("Load Image From:%s\n",FileName)
invoke UnicodeStr,FileName,ADDR _buffer ;str to wstr
invoke GdipLoadImageFromFile,ADDR _buffer,addr Img ;Load Image
.if eax == 0
mov pencoderClsid,rv( GetEncoderClsid,chr$("image/jpeg") )
invoke _SaveAs ,0,0,chr$("JPEG Image",0,"*.jpg",0,0) ; select file name
.if eax
mov FileName,eax
invoke UnicodeStr,FileName,ADDR _buffer ;str to wstr
printf("Save Image To:%s\n",FileName)
invoke GdipSaveImageToFile,Img,ADDR _buffer,pencoderClsid,0 ;SaveImageTo
.if eax == 0
printf("success\n",FileName)
.endif
.endif
invoke GdipDisposeImage,Img
.endif
.endif
    ;------------------------------------------------------------

jj2007

  • Member
  • *****
  • Posts: 8826
  • Assembler is fun ;-)
    • MasmBasic
Re: Looking for a JPEG library
« Reply #10 on: November 12, 2018, 10:51:01 AM »
an example

This is basically what I posted above, but it doesn't work on XP.

mabdelouahab

  • Member
  • ***
  • Posts: 397
Re: Looking for a JPEG library
« Reply #11 on: November 13, 2018, 01:23:58 AM »
..., but it doesn't work on XP.
Rebuild it on Xp

AW

  • Member
  • *****
  • Posts: 1562
  • Let's Make ASM Great Again!
Re: Looking for a JPEG library
« Reply #12 on: November 13, 2018, 01:30:56 AM »
It works in Windows 2000 as well.
I mean the mabdelouahab code, your masm basic looks buggy because you are popping ecx out of nowhere, but I will not delve deeper into such a complex artifact, sorry.

jj2007

  • Member
  • *****
  • Posts: 8826
  • Assembler is fun ;-)
    • MasmBasic
Re: Looking for a JPEG library
« Reply #13 on: November 13, 2018, 02:36:58 AM »
buggy because you are popping ecx out of nowhere

It works fine:
- on Win7-64
- on XP when debugged with Olly
- on XP when run through DebugHeap.exe
- but GdipSaveImageToFile fails silently on XP when not run with Olly or DebugHeap.

Mysteries of Windows 8)

mabdelouahab

  • Member
  • ***
  • Posts: 397
Re: Looking for a JPEG library
« Reply #14 on: November 13, 2018, 03:57:20 AM »
- but GdipSaveImageToFile fails silently on XP when not run with Olly or DebugHeap.
So
Try this.
Code: [Select]
invoke GdipSaveImageToFile,Img,ADDR _buffer,pencoderClsid,0 ;SaveImageTo
.if eax == 0
printf("success\n",FileName)
.else
printf("GdipSaveImageToFile ERR: %X\n",EAX)
.endif

Let's find out what's wrong with you.

Quote
GpStatusOk                          EQU 0
GpStatusGenericError                EQU 1
GpStatusInvalidParameter            EQU 2
GpStatusOutOfMemory                 EQU 3
GpStatusObjectBusy                  EQU 4
GpStatusInsufficientBuffer          EQU 5
GpStatusNotImplemented              EQU 6
GpStatusWin32Error                  EQU 7
GpStatusWrongState                  EQU 8
GpStatusAborted                     EQU 9
GpStatusFileNotFound                EQU 10
GpStatusValueOverflow               EQU 11
GpStatusAccessDenied                EQU 12
GpStatusUnknownImageFormat          EQU 13
GpStatusFontFamilyNotFound          EQU 14
GpStatusFontStyleNotFound           EQU 15
GpStatusNotTrueTypeFont             EQU 16
GpStatusUnsupportedGdiplusVersion   EQU 17
GpStatusGdiplusNotInitialized       EQU 18
GpStatusPropertyNotFound            EQU 19
GpStatusPropertyNotSupported        EQU 20