PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Windows mobile 5, imgdecmp.dll fix

Hi -

I've made a fix for DecompressImage() so that it works on windows mobile 5. This uses the IImagingFactory interface that was introduced in the Windows Mobile 2003 sdk, and no longer needs the imgdecmp.dll.

Is anyone interested in the changes? The IImagingFactory interface dates back to 1999, and should work on all devices.
Sure :D

You can see it from this thread:

Problem with image loading in the future?

You can include my Bugfix if you want to ;)

Or I can include your code in bugfix as PF improvement, if you don't mind.

You said 2003 SDK, does this mean it wouldn't work on 2000 and 2002 devices?
Or you check WM version to use this method only on WM 5 devices?
I believe that it will work on older devices, but I'm not sure. MS posted that it used to be internal-only, but that it has been around since 1999. It's now officially supported, but it definitely works on 2003 and WM 5. I don't have a previous device to test it on though. Since it seemed likely that it would work going way back, and since imgdecomp.dll is not shipped on all devices (and blows up in WM5), I just went ahead and removed it.

Here are the changes:

game.cpp - Need to init COM. The constructor and destructor are modified.
Code:

Game::Game()
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
... rest of constructor goes here.
}

Game::~Game()
{
CoUninitialize();
}

--------------------------------------------

image.cpp - remove imgdecmp, replace with IImagingFactory:

// replace define line 24
#ifdef _WIN32_WCE
#include "foreign/imgdecmp/imgrendr.h"
#include <INITGUID.h>
#include <imaging.h>
#pragma comment( lib, "ole32.lib" )
#else

---------------------------------------------
image.cpp - add after DecompressImage(hBitmap)

// Create a surface from a IImage
static Surface* CreateSurface( IImage *img )
{
// Retrieve bitmap info
ImageInfo iInfo;

HRESULT hr = img->GetImageInfo(&iInfo);
if (FAILED(hr))
{
// FileLog("Failed getting image info...",hr);
return NULL;
}

// Create the surface
Surface* surface = new Surface( iInfo.Width, iInfo.Height );

// Blit the bitmap on the surface
HDC hDestDC = surface->GetDC( true );

RECT rc;
rc.left = 0;
rc.top = 0;
rc.right = iInfo.Width;
rc.bottom = iInfo.Height;

img->Draw(hDestDC,&rc,NULL);

surface->ReleaseDC( hDestDC );
//FileLog("Returning surface...",0);
return surface;
}

------------------------------------------------
Replace DecompressImage

static Surface* DecompressImage( const uint8_t* pBegin, const uint8_t* pEnd )
{
//FileLog("Decompressing Image",0);
// This will be filled with a handle to the image
HBITMAP hBitmap = 0;

// CComPtr should auto release.
CComPtr<IImagingFactory>pFactory;
HRESULT hr = pFactory.CoCreateInstance(CLSID_ImagingFactory);
if ( SUCCEEDED(hr) )
{
CComPtr<IImage>pImg;
hr = pFactory->CreateImageFromBuffer((const void *)pBegin, pEnd-pBegin, BufferDisposalFlagNone, &pImg);
if (FAILED(hr))
{
// FileLog("CreateImageFromBuffer failed",hr);
return 0;
}
return CreateSurface(pImg);
}
else
{
//FileLog("IImageFactory failed",hr);
}
return 0;
}
Sorry - it seems to have deleted all of the spacing...
Use the code tags for code...
Code:
like this


If you wanted to see if it works with older devices, post an exe and have us test it.
I can test it on my MIPS Cassiopea E-125 and ARM(XScale) A620BT ;)

If you use only eVC 4.0, I can help you to compile and test it with eVC 3.0 (PPC 2000 MIPS and ARM SDK's)

if you wanted to see if it works with older devices, post an exe and have us test it.


I can post a WM2003 version for ARM. Would that work on earlier devices?
Attachments:
supersample.zip (34 KB)
If you use only eVC 4.0, I can help you to compile and test it with eVC 3.0 (PPC 2000 MIPS and ARM SDK's)


Sure - want me to post my modified PF project? Or do you want to apply the "code patch" I posted above?
Can you, please, PM me or post your project+modified PF files in one zip ;)

Supersample works on Asus A620BT (PocketPC 2003)
Jaimi, I'd rather see that you post your modified PF-project+files here in the forum so that everyone can have a look at it.

Regards
I'll zip up the project and post it here when I get home this evening.
Coincidentally I just finished up my changes to PocketFrog to use SHLoadImageFile and SHLoadImageResource.

These changes work without requiring any extra stuff, including the IImagingFactory interface. Since both of the SHLoadImage functions return HBITMAPs, and there's already a CreateSurface() function that takes an HBITMAP, it's much cleaner this way.

A couple of notes:
1) Download the right version ( PF 0.7 or 0.8 )
2) SHLoadImageResource only seems to look for images in a "GIF" resource folder... pretty flippin' ignorant of Microsoft... so I changed the default from "image" to "GIF" in image.h.
3) Only PPC 2002 and above support SHLoadImage, so you'll have to drop support for PPC 2000. (But I don't think anyone will have a problem with that.)

http://www.pocketadventures.com/downloa ... ge_src.zip
http://www.pocketadventures.com/downloa ... ge_src.zip

-John

[EDIT: The files at PM vanished, and the upload utility isn't working, so I'm hosting them at PocketAdventures.com.]
Just to set it straight, the IImagingFactory code doesn't require any new stuff either -- it's been built into the operating system since 1999.

Not saying that people shouldn't use yours (or that mine is better), but for me, the reason that I choose IImagingFactory over SHLoadImageFile (besides the GIF issue), is because IImagingFactory supported loading images straight from a buffer, and was a drop-in replacement for DecompressImage. Since I wanted to support loading textures from "pak" files, I needed this functionality.

This link is my entire PocketFrog directory. It includes the latest updates to pocketfrog 0.8.1 (from BigBen) and the latest PocketHal.

http://www.aztica.com/pocketfrog.zip
Jaimi wrote:Just to set it straight, the IImagingFactory code doesn't require any new stuff either -- it's been built into the operating system since 1999.

Not saying that people shouldn't use yours (or that mine is better), but for me, the reason that I choose IImagingFactory over SHLoadImageFile (besides the GIF issue), is because IImagingFactory supported loading images straight from a buffer, and was a drop-in replacement for DecompressImage. Since I wanted to support loading textures from "pak" files, I needed this functionality.
Good point, Jaimi. The SHLoadImage functions don't work with objects in a buffer. Also, not to confuse anyone, the resource images don't have to be GIF files, they just need to be in a resource folder called GIF. (Though maybe JPG, PNG, etc work too. I haven't tried those.)
If you look at the MSDN documentation, some pages state:
MSDN wrote:Converts a .gif file in the resource file to a .bmp file. A resource .gif file should be coded in the resource file as follows: IDG_MYIMAGE_GIF GIF DISCARDABLE "MyImage.gif".

Syntax
HBITMAP SHLoadImageResource (
HINSTANCE hinst,
UINT uIdGif
);
But other pages state that it does .png, .gif, .jpg, etc...

Also, I must admit that it's nice to see the community working to make PF better. I still believe that it's the easiest library to work with, by far.
Jaimi, I tried to compile Blit and PF.libs but failed with some IImage related errors(VC6), and with one error in eVC. I have no imaging.h file, should I install some WM5 SDK's first?

Presto, I've tried your approach - changed resource type to "GIF" in supersample- works well in my VC6.

Obviously doesn't compile in eVC3.0 (PPC2000 SDK), yes I'm a dinosaur :?
Imaging.h is in the wm2003 sdk. I didn't bother installing the wm5 sdk, it seemed geared toward c# (etc). Since your using evc3, you may want to do a clean on the projects, delete the .aps files [etc]. to make sure that the evc4 stuff isn't causing problems.
BIGBEN wrote:Presto, I've tried your approach - changed resource type to "GIF" in supersample- works well in my VC6.

Obviously doesn't compile in eVC3.0 (PPC2000 SDK), yes I'm a dinosaur :?
It compiles fine in eVC3.0, but you need to install the PPC2002 SDK.

-John
Thank you both for making Frog move, I know that it's not working just with my old SDK's, so I'll try it later compiling for WM5

Have you tried it with WM5 device? Is the image loading the only issue that you found?
I've tried it on my JasJar (it's the same as the HTC universal). Besides imgdecmp.dll failing, There is only one issue that is a problem on a WM5 device - the screen is offset by 1 pixel on the top and the left side (so you still see 1 pixel of the window behind). I've seen this with Arvale 1 (which also leaks memory like a sieve), but not with Arvale 2 (which is much faster, doesn't leak, and doesn't show the 1 pixel line).

The other issues I've seen seem to come from MS dropping some defines in EVC4 and the WM2003 sdk.

I'd like to contribute all the fixes for this - I wish we had a community repository so we could all share our fixes, and keep a common codebase.
BIGBEN wrote:Have you tried it with WM5 device? Is the image loading the only issue that you found?
I've updated two of my games, and both of them now work on the X51v. (According to two different sources.) The versions were compiled in eVC3.0 w/ the PocketPC 2002 SDK. It seems the image loading was the only issue. All of my games run in portrait mode, so I don't know of any landscape problems.

-John
I'm an amateur and a lurker and I've been working on a PF-based game off and on lately, so I read your post with some interest, especially since I'm considering upgrading to a WM2005 device but supporting 2002, 2003 and 2005. I work with eVC 3.0 and PF 0.7 so the IImage interface didn't appeal to me. The SHLoadImage alternative has obvious limitations so I didn't favor it either.

:idea: I had been planning to use PNG format, but I hit upon the idea that it would be really simple to dump all implementations of DecompressImage and just roll my own Windows BMP loader (or better yet, copy part of one verbatim out of any number of game programming books). Not much code involved, and now I'm free of Microsoft's whims about changing interfaces and libraries just to load a stupid image. I wrote it to load from a file, create a DIB section and return an HBITMAP which I use with the CreateSurface method found in image.cpp. Of course, now I'm limited to BMP format, but I plan to reclaim most of the benefits of PNG by storing all of my bitmaps as zlib-compressed data chunks in custom resource files (GIF/Jpeg don't concern me -- I don't use them). Its trivial to add another version of my bitmap loader to read the data from a memory buffer (ala zlib) instead of a file. Already working great for me on desktop and PPC.
MontyG wrote:I wrote it to load from a file, create a DIB section and return an HBITMAP which I use with the CreateSurface method found in image.cpp. Of course, now I'm limited to BMP format
With SHLoadImageFile and SHLoadImageResource you can load PNGs from files and resources. Both functions return an HBITMAP that CreateSurface can convert to a Surface. The SHLoadImage functions also work with BMP, GIF and JPG. So I'm curious to know which limitations you were talking about that makes it inadequate for what you're trying to do.

-John
Presto wrote:With SHLoadImageFile and SHLoadImageResource you can load PNGs from files and resources. Both functions return an HBITMAP that CreateSurface can convert to a Surface. The SHLoadImage functions also work with BMP, GIF and JPG. So I'm curious to know which limitations you were talking about that makes it inadequate for what you're trying to do.

-John


It can only load from files and internal resources. I want to concatenate and store my images in my own packed resource files, so I would want to load from a memory buffer. I am only interested in BMP and PNG, and for my purposes a zlib-compressed BMP is the same as PNG, so I will extract the zlib-compressed bitmap data from a packed resource file into a memory buffer and use my code to create the HBITMAP. Can't do that (AFAIK) with SHLoadImageFile, etc. Now I've eliminated any reliance on external image libraries I have no control over. It was such a small amount of code to add its just easier than worrying about imgdecmp.dll, IImage, SHLoadImage, etc. Still some reliance on some very old GDI structures, but if they change the OS drastically enough to eliminate GDI then I expect I'll have bigger problems than just loading a bitmap.
It sounds like the IImagingFactory stuff is exactly what you need. What about it don't you like? It should work all the way back to Windows Mobile 2002. Matter of fact, it's the method MS recommends to use...
I have the IImagingFactory code working in eVC and building samples fine to my X51v. I had to hunt out the location of imaging.h and add to my tools / options / directories include files C:\PROGRAM FILES\WINDOWS CE TOOLS\WCE420\POCKET PC 2003\INCLUDE\ARMV4

My question is:- Should this build in Visual Studio 6 on PC as I get the 13 errors I originally had when imaging.h was not included. As I do most all of my dev work on PC with VC6 this is really important. I will post back if I get it working. AFter that I will need to change Space Treker III over to PocketHAL and get it running.

UPDATE: imaging.h is only included via an #ifdef when building for CE. When I add to the PC side for VC6 I lose all but 2 errors:-
'CoInitializeEx' : undeclared identifier
'COINIT_MULTITHREADED' : undeclared identifier
Any thoughts?


ps: Remember the HI_RES_AWARE resource is needed if you want to run in VGA.

Many thanks for this work which has upgraded PF to work 'as is' with Windows mobile.
It's possible that on earlier SDK versions, you may need to change that to:

CoInitialize(NULL);
Presto wrote:But other pages state that it does .png, .gif, .jpg, etc...



I'm trying to use Presto's image modifications to load a jpg and it fails. I've tried moving it to a resource type of "GIF" and it still fails unless I actually re-save the file as a gif.

Has anyone else gotten it to work with jpg's and bmp's?

I was on the virge of releasing a game when I decided to try and get it compatible with wm2005.
One thing I found with respect to Presto's changes... The depricated LoadImage(Display *, resource, ... ) is changed to point to "GIF" resource, but the LoadImage(resource, ...) is still coded for "image".

Still doesn't change my problems, but I thought I'd point it out to anyone trying to use it.



edit.....

It seems as if something was going on with my resource file. It appears to be working now with the "jpg as gif" resource method. The bmp's were loading fine, I just didn't realize it (they are resource type 'bitmap' - I'm not sure if that has anything to do with it.).

Maybe someone can clarify something though... When I import a jpg as resource type "gif", it creates a new file with an extension .bin. I assume that when I modify my image, I'll have to re-import the image. I also notice that a .png file loaded into the gif resource doesn't get renamed... It's pretty confusing - but it seems to work.

If anyone with access to wm2005 wants to check it out for me, PM me.
fast_rx wrote:When I import a jpg as resource type "gif", it creates a new file with an extension .bin.
That's really weird. I've never known it to create a new file before. Is this using eVC3 or eVC4? PF08 or PF07?

-John
It's with eVC3 and PF08.

It will do the same with a gif if you load it into resource type other than "GIF" (renames it to .bin). There's probably something to do to allow .jpg, but I'm not going to worry about it since it seems to work.
I use:

Surface* LoadImage( const uint8_t* pBegin, const uint8_t* pEnd );

Is it true that the Jaimi approach is the only one and I can't get SHLoadImage to work with my buffer load?
I'm asking because today I've downloaded PPC2002 SDK and wanted to use the Presto's approach, but it seems that there is no chance to load from a buffer with SH(?)
Yes, for buffered data, you'll need to use the IImaging stuff. The SHLoadImage functions only work for files and resources.

-John
I misunderstood. I though that the term buffer was referring to resources. So I could use this approach if my graphics are loading from a resource? (I currently use jpg and bmp) The imaging factory method works fine so is there a performance or other major advantage of the other approach?
Honestly, I'm not sure. It'd be interesting to see some benchmarks. The SHLoadImage functions return HBITMAPs that CreateSurface can convert. I don't know if they outperform or underperform the decoding done by the IImagingFactory code. The bonus to using IImagingFactory is that you can give it a range of memory and it'll create the image from it. (Like in PF0.7.0's splashscreen.) I always load from files or resources, so I haven't had a need to try Jaimi's version yet. If SHLoadImage gives a performance gain (which I doubt since MS wrote it, but it's possible), it'd probably be smart to merge the two versions and use the decoding for buffered data.

-John
And I probably (FINALLY!) use libpng. It only gives me the possbibility to load PNGs, but I would be amused with it. Besides I can load to +alpha channel Surface! and use PPC2000 SDK.

Downladed the WinCE version, currently struggling throught the manual :?

P.S. Just curious, does I need WMobile2003 SDK installed to use IImagingFactory, or I can be satisfied with only one file: imaging.h?
I've recently implemented Jaimi changes. Works fine, nothing seemed to change.
Anyone with a WM5 device to test my game? 3 megs in zip, a huge memory requirements for now :).
Yes, Axim X51v. Happy to test (I have beta tested many PocketPC games)
send me too :)
ipaq 1950
andrewshilov[[[@]]]gmail[[[.]]]com
Looks like it works just fine, thanks a bundle, Jaimi :). I only needed to copy .h and .lib files from WM2003SDK, and compiled using EVC3 and PPC2002.
There seem to be a problem with Jaimi's approach(IImage Factory stuff).
It's noticed that it doesn't work on some older PPC2002 devices. So far there are ipaq H38xx and ipaq H39xx - iimage just fails loading..

Anyone have any ideas of how this can be fixed?