News:

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

Main Menu

Looking for a JPEG library

Started by NoCforMe, November 09, 2018, 05:35:35 PM

Previous topic - Next topic

NoCforMe

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!
Assembly language programming should be fun. That's why I do it.


jj2007

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

Assembly language programming should be fun. That's why I do it.

hutch--

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.

Vortex

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

Quote from: Vortex on November 10, 2018, 07:58:01 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.
Assembly language programming should be fun. That's why I do it.

jj2007

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

Hi NoCforMe,

QuoteAnd 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

an example
    ;------------------------------------------------------------
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

Quote from: mabdelouahab on November 12, 2018, 08:18:30 AM
an example

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

mabdelouahab


aw27

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

Quote from: AW on November 13, 2018, 01:30:56 AMbuggy 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

Quote from: jj2007 on November 13, 2018, 02:36:58 AM
- but GdipSaveImageToFile fails silently on XP when not run with Olly or DebugHeap.
So
Try this.

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