The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on July 20, 2008, 12:52:08 PM

Title: Converting bmp to jpg?
Post by: Farabi on July 20, 2008, 12:52:08 PM
Is windows have library to convert bmp to jpg?
Title: Re: Converting bmp to jpg?
Post by: dsouza123 on July 20, 2008, 05:27:13 PM
The closest thing I could find for bmp and jpeg handling/conversion is using gdiplus (gdi+)
the gdiplus.dll comes with XP and is available for earlier Windows versions.

GDI+: bmp/gif/png/jpg to bmp/gif/png/jpg
http://www.masm32.com/board/index.php?topic=5210.msg38936

Using GDI+ (GDIplus)
http://www.masm32.com/board/index.php?topic=5673.msg52290

Loading JPEG as splash
http://www.masm32.com/board/index.php?topic=5348.msg40077
Title: Re: Converting bmp to jpg?
Post by: MichaelW on July 20, 2008, 08:16:33 PM
The attachment is another example that uses GDI+.


[attachment deleted by admin]
Title: Re: Converting bmp to jpg?
Post by: Farabi on July 21, 2008, 09:10:04 AM
Quote from: MichaelW on July 20, 2008, 08:16:33 PM
The attachment is another example that uses GDI+.


Thanks, this is just what I need.
Title: Re: Converting bmp to jpg?
Post by: Farabi on July 21, 2008, 09:38:04 AM
Quote from: MichaelW on July 20, 2008, 08:16:33 PM
The attachment is another example that uses GDI+.

Where is the include file and the lib?
Title: Re: Converting bmp to jpg?
Post by: dsouza123 on July 21, 2008, 11:38:08 AM
Two versions of the lib are available from this post for download, then use l2inc to generate the inc.

Put gdiplus.lib in your lib directory.
Go into your include directory and run l2inc pathtolib\gdiplus.lib
The gdiplus.inc will then reside in the include directory.

http://www.masm32.com/board/index.php?topic=6569.msg48859
Title: Re: Converting bmp to jpg?
Post by: Farabi on July 21, 2008, 12:00:13 PM
Hi,
I got a new problem, but I think I know where is the problem is but dont know how to solve it.\

Quote
   gdipsi              GdiplusStartupInput <1>  ; version must be 1
   token               dd 0
   image               dd 0
   numEncoders         dd 0
    sizeImageCodecInfo  dd 0
    pImageCodecInfo     dd 0
   
.code

fPicSaveToFileAsJpg proc uses esi edi lpFileName:dword
   LOCAL str_len,tmp_esi:dword
   LOCAL buff[256],buff2[256],buff3[256]:dword
   
   invoke exist,lpFileName
   .if eax==0
      invoke MessageBox,0,0,0,0
      ret
   .endif
   
   invoke GdiplusStartup, ADDR token, ADDR gdipsi, NULL
      invoke GdipLoadImageFromFile, lpFileName, ADDR image
      invoke GdipGetImageEncodersSize, ADDR numEncoders,ADDR sizeImageCodecInfo
      invoke mAlloc,sizeImageCodecInfo
      .if eax==0
         invoke MessageBox,0,CADD("Not Enough memory/Memori tidak cukup"),0,0
         jmp error
      .endif
      mov pImageCodecInfo,eax
      invoke GdipGetImageEncoders, numEncoders, sizeImageCodecInfo,pImageCodecInfo
            invoke lstrlen,lpFileName
            mov str_len,eax
            sub str_len,2
            invoke lstrcpyn,addr buff,lpFileName,str_len
            invoke lstrcat,addr buff,CADD("jpg")
            
            assume esi:ptr ImageCodecInfo
               mov ecx,numEncoders
               mov esi,pImageCodecInfo
               @@:
               push ecx
               push esi
               mov tmp_esi,esi
               invoke WideCharToMultiByte,0,0,[esi].MimeType,-1,addr buff2,1024,0,0
               invoke lstrcmp,addr buff2,CADD("image/jpeg")
               .if eax==0
                  invoke MultiByteToWideChar,0,0,addr buff,-1,addr buff3,1024
                  invoke GdipSaveImageToFile, image, addr buff3,tmp_esi, NULL
                  
                  jmp error
               .endif
               pop esi
               add esi, SIZEOF ImageCodecInfo
               pop ecx
               dec ecx
               jnz @b
            assume esi:nothing
      
      error:      
   invoke GdipDisposeImage, image
   invoke GdiplusShutdown, token
   invoke GlobalFree,pImageCodecInfo
   
   ret
fPicSaveToFileAsJpg endp


The red color is what I think the problem is. Everything I think work fine except for those 2 function. I did not generate any file. Anyone can help?
Title: Re: Converting bmp to jpg?
Post by: MichaelW on July 21, 2008, 02:57:02 PM
Farabi,

I should have added a note that the import library and include file are in the MASM32 version 10 beta, but not in the earlier versions.

If I pass your procedure the correct filename as an ANSI string then GdipLoadImageFromFile fails because it expects a Unicode string. If I pass your procedure the correct filename as a Unicode string, then after I comment out the invoke exist,lpFileName code, and replace the call to mAlloc with the alloc macro, the code works OK except the output file is named "sjpg".
Title: Re: Converting bmp to jpg?
Post by: Farabi on July 22, 2008, 05:11:54 AM
Okay, I solve the problem, thanks MichaelW.
Quote
fPicSaveToFileAsJpg proc uses esi edi lpFileName:dword
   LOCAL str_len,tmp_esi:dword
   LOCAL buff[256],buff2[256],buff3[256]:dword
   
   invoke exist,lpFileName
   .if eax==0
      invoke MessageBox,0,0,0,0
      ret
   .endif
   
   invoke GdiplusStartup, ADDR token, ADDR gdipsi, NULL
      invoke MultiByteToWideChar,0,0,lpFileName,-1,addr buff3,1024
      invoke GdipLoadImageFromFile, addr buff3, ADDR image
      invoke GdipGetImageEncodersSize, ADDR numEncoders,ADDR sizeImageCodecInfo
      invoke mAlloc,sizeImageCodecInfo
      .if eax==0
         invoke MessageBox,0,CADD("Not Enough memory/Memori tidak cukup"),0,0
         jmp error
      .endif
      mov pImageCodecInfo,eax
      invoke GdipGetImageEncoders, numEncoders, sizeImageCodecInfo,pImageCodecInfo
            invoke lstrlen,lpFileName
            mov str_len,eax
            sub str_len,2
            invoke lstrcpyn,addr buff,lpFileName,str_len
            invoke lstrcat,addr buff,CADD("jpg")
            
            assume esi:ptr ImageCodecInfo
               mov ecx,numEncoders
               mov esi,pImageCodecInfo
               @@:
               push ecx
               push esi
               mov tmp_esi,esi
               invoke WideCharToMultiByte,0,0,[esi].MimeType,-1,addr buff2,1024,0,0
               invoke lstrcmp,addr buff2,CADD("image/jpeg")
               .if eax==0
                  invoke MultiByteToWideChar,0,0,addr buff,-1,addr buff3,1024
                  invoke GdipSaveImageToFile, image, addr buff3,tmp_esi, NULL
                  pop esi
                                                pop ecx
                  jmp error
               .endif
               pop esi
               add esi, SIZEOF ImageCodecInfo
               pop ecx
               dec ecx
               jnz @b
            assume esi:nothing
      
      error:      
   invoke GdipDisposeImage, image
   invoke GdiplusShutdown, token
   invoke GlobalFree,pImageCodecInfo
   
   ret
fPicSaveToFileAsJpg endp