[C++] draw/copy problem with mixed BMP 8/24 bits

Short intro:
I am developing a template based library for easily creating GUI.
Currently, basics functionalities (window drawing and very simple event management) works correctly, but code is not optimized yet.

Templates should allow me to only have to implement 2 classes for switching from a library to another:
_ screen<T1,T2>
_ bitmap<T1,T2>

Here, no problem.

I have used SDL to implement those classes for tests.
Everything work perfectly if I use only 24bits images (loaded from files).

But, when I use a 8bit one (xpaint automatically choose the best format for images, not as mspaint, this is how I discovered this problem), nothing is drawn!
If I mix 8bits and 24bits images, the same…

I don’t understand from where this problem come. I have made a try to convert the 8bit image in the “bitmap::loadFile(std::string)” method with SDL_ConvertSurface, but it didn’t change anything (and so I have removed the try).

The code is really simple, as my library call SDL for everything that need to draw. I often only have to interface my API with SDL one, which is done by bitmap class (in fact, by it’s descendant)

In the sdl implementation, the first template argument is SDL_Surface, the second one is sdl_bitmap (the class which encapsulate SDL_Surface).
Class bitmap is here to give an abstract base model and a few methods to the class user will have to implement. (in my test code, I have named it sdl_bitmap.)
Here is the code:

template <typename className,typename object>
bool __bitmap<className,object>::draw(std::weak_ptr<className> &target,int16_t const sx, int16_t const sy,int16_t const w, int16_t const h, int16_t const dx, int16_t const dy)
	std::weak_ptr<className> weakSource (m_surface);
	return blitSurface(weakSource, target,dx,dy,!w?getW():w,!h?getH():h,sx,sy);

template <typename className,typename object>
bool __bitmap<className,object>::copy(std::weak_ptr<className> &source,int16_t sx, int16_t sy,int16_t w, int16_t h, int16_t dx, int16_t dy)
	std::weak_ptr<className> weakDest(m_surface);
	return blitSurface(source, weakDest,sx,sy,!w?getW():w,!h?getH():h,dx,dy);

For the sprite:
The first goal of the image class is to encapsulate the class bitmap, providing higher level methods.

Another thing is the “image::clone(image&)” method. It don’t really clone, it just make “this->m_texture” having same characteristics than the given object. There is no copy of image content.

template<typename className,typename object>
bool __sprite<className,object>::draw(std::weak_ptr<className> &target)
	//first verify if image is set
		return false;
	//clear the sprite BEFORE changing the screen
		return false;

		return false;


	//if the shadow does not exist or is not of the same size as the sprite, create one of the same size
	if(m_shadow.getH()!=m_sprite.getH() || m_shadow.getW()!=m_sprite.getW())
		return false;
	return (m_isDraw=m_sprite.draw(m_weakTarget,m_spriteX,m_spriteY));

If this portion of code is not enough, the full code is here: http://svn.gna.org/svn/cremone/trunk

I know that many names were stupidly chosen, and I have corrected most of it (with many other improvements) in my working directory. But since my repo on gna.org don’t work for a reason I don’t know, I can’t commit. Please forgive me for crap code…

Why not just convert your graphics to one thing and solve it that way? They would all be the same before you load them or do anything so that seems to be the simple answer. I don’t know the ins and outs of 8 bit bmp because even over 20 years back I never bothered with them. Since it’s xpaint we are talking about it could just be an issue with xpaint or some format stuff going on in it that you are unaware of. Have you tried images that are not from xpaint?

I don’t think it is an issue with xpaint, because the issue does not happen when I use files encoded with the same BPP.

I don’t remember if I tried to convert images or not (I think yes, but not sure), for the first question. I didn’t stop on a problem like this one, just mspaint instead of xpaint, I don’t need to create test images everyday so it is “ok” for now.

Did you say mspaint works fine but xpaint does not? When I have issues I try to document every n’th step. You could write the data to file when you load it, and again when you convert it to see if the headers correctly copied. You could take an xpaint image and the same image from another source (like a white square of same size) and see any differance. I like to cut issues up into tiny parts and expose everything and understand it. It drove my first wife crazy :slight_smile: