News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

My Code does not work anymore

Started by Farabi, June 10, 2010, 09:18:29 PM

Previous topic - Next topic

Farabi


include gdiplus.inc
includelib gdiplus.lib

   GdiplusStartupInput STRUCT
      GdiplusVersion           DWORD ?
      DebugEventCallback       DWORD ?
      SuppressBackgroundThread DWORD ?
      SuppressExternalCodecs   DWORD ?
    GdiplusStartupInput ENDS

    ImageCodecInfo STRUCT
      ClassID           CLSID <>
      FormatID          GUID <>
      CodecName         DWORD ?
      DllName           DWORD ?
      FormatDescription DWORD ?
      FilenameExtension DWORD ?
      MimeType          DWORD ?
      Flags             DWORD ?
      Version           DWORD ?
      SigCount          DWORD ?
      SigSize           DWORD ?
      SigPattern        DWORD ?
      SigMask           DWORD ?
    ImageCodecInfo ENDS
.data
ALIGN 16
Sprite_Simd_Mask_RVB_unpck_1 DWORD 000010001h,000000001h
Sprite_Simd_Mask_RVB_unpck_255 DWORD 000FF00FFh,0000000FFh
   
.data?
      token               dd 0
      image               dd 0
      numEncoders         dd 0
      sizeImageCodecInfo  dd 0
      pImageCodecInfo     dd 0
      gdipsi              GdiplusStartupInput <1>  ; version must be 1

.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 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


It worked before, but now when it hit  invoke GdipLoadImageFromFile, addr buff3, ADDR image it crashed. Why?

How I used to use

invoke fPicSaveToFileAsJpg,CADD("Test.bmp")


It will generate a file named test.jpg
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

baltoro

MultiByteToWideChar just preceeding GdipLoadImageFromFile.
A simple mistake, you must have copied and pasted the code, because you do the same thing later.   
Just out of curiosity, what's the advantage of doing this in Assembly? You'd have better type checking, and the code for checking return values would be easier in C++.
Baltoro

Farabi

Quote from: baltoro on June 11, 2010, 12:03:51 AM
Just out of curiosity, what's the advantage of doing this in Assembly? You'd have better type checking, and the code for checking return values would be easier in C++.

Because that is the only thing I can do.

So MultiByteToWideChar is the main problem?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

baltoro

If you read the documentation: MultiByteToWideChar, that last parameter, if it is not the size of your buffer, the function fails. Hell, I've done it myself numerous times. That's why checking return values before you make the graphics call will keep you from crashing.   
Lately, I have been using DirectX, and so, am unfamiliar with the GDI+ APIs.
Baltoro

Farabi

So the problem is not on GdipLoadImageFromFile?
That is weird, it worked before.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

aker

伟大的恐怖主义革命家拉登,因遭袭医治无效,于2011年5月1日在巴基斯坦逝世,享年54岁

MichaelW

Onan,

Your code works for me under Windows 2000. I did change mAlloc to crt_malloc and GlobalFree to crt_free, because I didn't have time to determine what mAlloc is. When GdipLoadImageFromFile "crashes" what is the return status? See the Status enumeration here.

eschew obfuscation

donkey

Hi,

I'm not completely sure why you are searching the codecs for JPEG, it is always found on Windows and has a fixed GUID:

From GdiPlusImaging.h in the GoAsm header project:
#define GUID_ImageEncoderBMP <0x557cf400, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>
#define GUID_ImageEncoderJPEG <0x557cf401, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>
#define GUID_ImageEncoderGIF <0x557cf402, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>
#define GUID_ImageEncoderEMF <0x557cf403, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>
#define GUID_ImageEncoderWMF <0x557cf404, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>
#define GUID_ImageEncoderTIFF <0x557cf405, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>
#define GUID_ImageEncoderPNG <0x557cf406, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>
#define GUID_ImageEncoderICON <0x557cf407, 0x1a04, 0x11d3, <0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e>>


You'll find that your proggy is working hard just to yield a predefined GUID.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Farabi

Quote from: MichaelW on June 11, 2010, 07:21:42 AM
Onan,

Your code works for me under Windows 2000. I did change mAlloc to crt_malloc and GlobalFree to crt_free, because I didn't have time to determine what mAlloc is. When GdipLoadImageFromFile "crashes" what is the return status? See the Status enumeration here.



There is no return status, because it doesnot execute  GdipLoadImageFromFile completely. On the debugger the ebx point to 0 memory address and it tried to access the value from it. Since the debugger stopped on 0x07000000 address or something I guess the dll tried to access a wrong address. Dont know what is my mistake. Can you upload your .lib file for the Win2000?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Okay I got the return code from the GDIStart function
Quote
UnsupportedGdiplusVersion   = 17,


What should I do?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Okay I got where is my mistake is, craps.  :red

Quote
fPicSaveToFileAsJpg proc uses esi edi lpFileName:dword
   LOCAL str_len,tmp_esi:dword
   LOCAL buff[256],buff2[256]
   LOCAL  buff3[256]:dword
   
   invoke exist,lpFileName
   .if eax==0
      invoke MessageBox,0,0,0,0
      ret
   .endif
   
   invoke MultiByteToWideChar,0,0,lpFileName,-1,addr buff3,512
  mov      eax,OFFSET gdipsi
   mov      GdiplusStartupInput.GdiplusVersion[eax],1
   invoke GdiplusStartup, ADDR token, eax, NULL

  ; mov ecx,eax
  ; invoke dw2a,ecx,addr buff
;  invoke MessageBox,0,addr buff,0,0
;   ret
      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
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

baltoro

...Oops,...   
...I need brain surgery,...
...Sorry, Onan.
Thank god Edgar solved the problem.
Baltoro

clive

Now you just have to handle the error paths a little better.<G> My code would be a lot more clean/compact if I could really ignore them.
It could be a random act of randomness. Those happen a lot as well.

dedndave

Onan, does that routine give you the opportunity to set the "quality" and "smoothing" values for JFIF compression ?