The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
red,green and blue dot?
insomniac


Joined: 20 Apr 2014
Posts: 15
I am finishing an old project I started with sdl 1.2 and then going to convert it to the newest sdl version! My problem is a red green and blue dot that appears on the bottom left corner of some bitmaps rendered like this:

SDL_Surface *Video::LoadImage( std::string filename )
{
SDL_Surface* loadedImage = NULL;

SDL_Surface* optimizedImage = NULL;

loadedImage = SDL_LoadBMP( filename.c_str() );

if( loadedImage != NULL )
{
optimizedImage = SDL_DisplayFormat( loadedImage );

SDL_FreeSurface( loadedImage );
}

return optimizedImage;
}

void Video::DrawBmp(int x, int y,SDL_Surface* source, SDL_Surface* destination,bool transparent)
{
SDL_Rect offset;

offset.x = x;
offset.y = y;

if(transparent)
SDL_SetColorKey(source, SDL_SRCCOLORKEY, SDL_MapRGB(source->format, 0, 0, 0));

SDL_BlitSurface( source, NULL, destination, &offset );
}

bool Video::Update()
{
if( SDL_Flip(this->screen) == -1 ) return false;

return true;
}


screen shot:
[img]http://bu-forums.2323770.n4.nabble.com/file/n1579/BUSS24.bmp[/img]

The red,green and blue dots appeared after I rendered the character's boots the size of the bmp is 34 x 27 and the transparency is 0,0,0!
insomniac


Joined: 20 Apr 2014
Posts: 15
Sorry the image didnt show up!You can see the dots by the bottom left hand side of her dress.
Naith


Joined: 03 Jul 2014
Posts: 158
Is the image you've posted the original image or a screenshot from when the program runs?

My guess is that it's something with the color key'ing you're doing in the render function.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
Is the image you've posted the original image or a screenshot from when the program runs?

My guess is that it's something with the color key'ing you're doing in the render function.


Thanks for the quick reply I will look into the color keying. That is a screen shot here is one of the bmps that is effected:
insomniac


Joined: 20 Apr 2014
Posts: 15
insomniac wrote:
Naith wrote:
Is the image you've posted the original image or a screenshot from when the program runs?

My guess is that it's something with the color key'ing you're doing in the render function.


Thanks for the quick reply I will look into the color keying. That is a screen shot here is one of the bmps that is effected:


After I adjusted my color key SDL_SRCCOLORKEY to SDL_TRUE it produces this which will show exactly where the dots are being placed on the bott bmps.

Naith


Joined: 03 Jul 2014
Posts: 158
May I look at your code (and not just the one you posted in your first post)? I have an idea on what might cause the problem. I will also need the affected image. I can't see the image you've posted.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
May I look at your code (and not just the one you posted in your first post)? I have an idea on what might cause the problem. I will also need the affected image. I can't see the image you've posted.

I cant really share the whole source code or I would I'm building this project for someone else and theres alot of vultures that would like to get a hold of it! I am remaking a client for an old mmorpg that were trying to keep alive. I noticed someone else is having similar problems rebuilding his version of the client using sdl 2.0. Can be seen here http://www.treos.org/viewtopic.php?f=17&t=135&start=60
Naith


Joined: 03 Jul 2014
Posts: 158
Oh, okay. I understand.

What I think you should do is:

1. Move the SDL_SetColorKey code from the render function into the function where you're creating the character and such, since the color keying only has to been done once for each surface, and not every frame.
Might eventually cause some problems if color keying is being made every frame during rendering. Shouldn't be any problems but it might case some weird effect.

Example:

Code:

void Init()
{
   SDL_Surface* pSurface = LoadImage("MyImage.bmp");

   // If the surface was successfully created, set the color key to black
   if(pSurface)
      SDL_SetColorKey(pSurface, SDL_SRCCOLORKEY, SDL_MapRGB(pSurface->format, 0, 0, 0));
}



2. Make sure that the background on the image you're loading only contains black so there isn't any pixels in another color (like the pixels that appears at the left when rendering). There will be problems with the color keying if that's the case.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
Oh, okay. I understand.

What I think you should do is:

1. Move the SDL_SetColorKey code from the render function into the function where you're creating the character and such, since the color keying only has to been done once for each surface, and not every frame.
Might eventually cause some problems if color keying is being made every frame during rendering. Shouldn't be any problems but it might case some weird effect.

Example:

Code:

void Init()
{
   SDL_Surface* pSurface = LoadImage("MyImage.bmp");

   // If the surface was successfully created, set the color key to black
   if(pSurface)
      SDL_SetColorKey(pSurface, SDL_SRCCOLORKEY, SDL_MapRGB(pSurface->format, 0, 0, 0));
}



2. Make sure that the background on the image you're loading only contains black so there isn't any pixels in another color (like the pixels that appears at the left when rendering). There will be problems with the color keying if that's the case.


I tried moving the color function to each instance and I got the same result. I checked the bmps and their background/transparency and the bmps were fine.I removed the color key function completely to see what would happen and the dots still appear by the boots.
Naith


Joined: 03 Jul 2014
Posts: 158
Are the dots appearing only for some of the bmp's or all of them?

Have you considered switching to SDL_Image and loading the images as png files instead? By doing that, you don't have to have a black background on each of the images and you don't have do to any color keying, since SDL_Image takes care of the alpha layer and doesn't render it.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
Are the dots appearing only for some of the bmp's or all of them?

Have you considered switching to SDL_Image and loading the images as png files instead? By doing that, you don't have to have a black background on each of the images and you don't have do to any color keying, since SDL_Image takes care of the alpha layer and doesn't render it.


Its only on some bitmaps for instance most of the the boot bmps which are 34 x 27. I havnt tried SDL_Image because I would have to convert thousands of bmps to png files.If I can find a strait forward method to convert my bmps to png I will give your idea a shot.

I had a few ideas over night.
1: I'm going to try and slow down the program in between loading those bmps.
2: Instead of drawing the boots to the original screen I am going to draw them on the character.
Naith


Joined: 03 Jul 2014
Posts: 158
I still feel like it's something wrong with some of the bmp images since the error only occur on some of the images. I doubt that there's some bug in SDL_LoadBMP and / or SDL_BlitSurface that would occur only on some of the surfaces. The only time when I've had rendering problems using SDL_BlitSurface is when I've made something wrong with the background color and color keying and such.

Yeah, that might be a good idea. Also, if I were you, I would try to turn off all the other assets that's being rendered (backgrounds, menu buttons and so on) to see if it's maybe some background or something that causes the rendering error(s). Might be a long shot but it's worth to check.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
I still feel like it's something wrong with some of the bmp images since the error only occur on some of the images. I doubt that there's some bug in SDL_LoadBMP and / or SDL_BlitSurface that would occur only on some of the surfaces. The only time when I've had rendering problems using SDL_BlitSurface is when I've made something wrong with the background color and color keying and such.

Yeah, that might be a good idea. Also, if I were you, I would try to turn off all the other assets that's being rendered (backgrounds, menu buttons and so on) to see if it's maybe some background or something that causes the rendering error(s). Might be a long shot but it's worth to check.


Heres a zip files of the boot bmp's https://www.mediafire.com/?rm2ua7di11n76vu maybe try and render a few of um . I can't find anything wrong with them!
Naith


Joined: 03 Jul 2014
Posts: 158
A lot of images there. Can you check for one of the images that the error occurs on and I will try to render it on my computer?
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
A lot of images there. Can you check for one of the images that the error occurs on and I will try to render it on my computer?


It happens at random I have a program I made to convert individual bmps to sheets and full sheets to bmps.I converted all those bmps to sprite sheets multiple times and it happens at random.Each time I turned the bmps to sheets the dots appeared on different instances! Here is the last result produced from bmp_2_spritesheet https://www.mediafire.com/?4kiuf646mq5t68q
Naith


Joined: 03 Jul 2014
Posts: 158
I've now located the error.

Here's a screenshot from a program I wrote to render 962 images at the same time (didn't have room in the window to render more). As you can see in the image, some of the rendered surfaces has the small dots in them. We can therefore be sure that there's nothing wrong with your code. Link to image: http://tinypic.com/view.php?pic=2qnqpg2&s=8#.U-FNeGPDUe9

In my program I counted which surface was the first to have the dot's on it when rendered and opened up that image in Photoshop. I also located some more images to check. Here's an image showing the images zoomed in a lot: http://tinypic.com/view.php?pic=n4tcm0&s=8#.U-FOQ2PDUe9

There's the reason why you're having dot's on some surfaces during rendering. As you can see the issue seems to be very random since Bitmap_18.bmp and Bitmap_353 doesn't have the dots but Bitmap_354 has. The issue is on some images in a row but there's also images here and there that have the dots.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
I've now located the error.

Here's a screenshot from a program I wrote to render 962 images at the same time (didn't have room in the window to render more). As you can see in the image, some of the rendered surfaces has the small dots in them. We can therefore be sure that there's nothing wrong with your code. Link to image: http://tinypic.com/view.php?pic=2qnqpg2&s=8#.U-FNeGPDUe9

In my program I counted which surface was the first to have the dot's on it when rendered and opened up that image in Photoshop. I also located some more images to check. Here's an image showing the images zoomed in a lot: http://tinypic.com/view.php?pic=n4tcm0&s=8#.U-FOQ2PDUe9

There's the reason why you're having dot's on some surfaces during rendering. As you can see the issue seems to be very random since Bitmap_18.bmp and Bitmap_353 doesn't have the dots but Bitmap_354 has. The issue is on some images in a row but there's also images here and there that have the dots.


This seems to be a bug in SDL and should be addressed! Im not doing anything abnormal with my program, I am just rendering at times thousands of bmps at the same time.


My thoughts: what whould happen if I changed the bmp size to 34 x 28 instead of 34 x 27,its just theirs to many figures I have to test alone Smile
Naith


Joined: 03 Jul 2014
Posts: 158
Like I said, the dot's are on the images even before they are loaded. Check the second of my images. That image shows a screenshot from Photoshop where I've openede some of the images and the dot's are there. So the issue is in the images.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
Like I said, the dot's are on the images even before they are loaded. Check the second of my images. That image shows a screenshot from Photoshop where I've openede some of the images and the dot's are there. So the issue is in the images.

In your post you said bitmap 354 has the dots,but it doesnt here is the original copy of the the image . none of the boot bms have those dots Ive looked over them multiple times! How would the original game have been able to use the 0,0,0 transparency with those dots they would have and trust me I,ve been working with the server emulator for almost four years I know every in and out of the game and there was no weird rgb dots in the bottem of some bms.
insomniac


Joined: 20 Apr 2014
Posts: 15
insomniac wrote:
Naith wrote:
Like I said, the dot's are on the images even before they are loaded. Check the second of my images. That image shows a screenshot from Photoshop where I've openede some of the images and the dot's are there. So the issue is in the images.

In your post you said bitmap 354 has the dots,but it doesnt here is the original copy of the the image . none of the boot bms have those dots Ive looked over them multiple times! How would the original game have been able to use the 0,0,0 transparency with those dots they would have and trust me I,ve been working with the server emulator for almost four years I know every in and out of the game and there was no weird rgb dots in the bottem of some bms.



Holly craPP the dots that show up on that link I posted last are not on the original image!!!!???? I have it inlarged in photo shop 700% and the whole surface beside the boot gfx is 0,0,0 Crying or Very sad
insomniac


Joined: 20 Apr 2014
Posts: 15
insomniac wrote:
insomniac wrote:
Naith wrote:
Like I said, the dot's are on the images even before they are loaded. Check the second of my images. That image shows a screenshot from Photoshop where I've openede some of the images and the dot's are there. So the issue is in the images.

In your post you said bitmap 354 has the dots,but it doesnt here is the original copy of the the image . none of the boot bms have those dots Ive looked over them multiple times! How would the original game have been able to use the 0,0,0 transparency with those dots they would have and trust me I,ve been working with the server emulator for almost four years I know every in and out of the game and there was no weird rgb dots in the bottem of some bms.



Holly craPP the dots that show up on that link I posted last are not on the original image!!!!???? I have it inlarged in photo shop 700% and the whole surface beside the boot gfx is 0,0,0 Crying or Very sad


I am going to change the background to 255,255,255 and see if it still happens!
Naith


Joined: 03 Jul 2014
Posts: 158
Well, my Photoshop doesn't lie (as far as I know) and if you take a look at my Photoshop screenshot you can see that the file Bitmap_354.bmp is open (look at the file names of the images that are open) and you will see that Bitmap_354.bmp is open and does indeed has the dots.

I tryed to remove the dots in Bitmap_16.bmp and Bitmap_17.bmp, kept the black background in both of them, tried to render them and the error is gone.
Naith


Joined: 03 Jul 2014
Posts: 158
I had some time to kill so I fixed all the images that had the dot's in them. Images: http://speedy.sh/TXGJG/Textures.zip

Enjoy.
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
I had some time to kill so I fixed all the images that had the dot's in them. Images: http://speedy.sh/TXGJG/Textures.zip

Enjoy.


Thanks! I still don't see how this is happening but the people who made the original game did some weird stuff and it seems like Im spending more time finding and fixing thier garbage . Twisted Evil
Naith


Joined: 03 Jul 2014
Posts: 158
Are the images rendered correct after they've been fixed?
insomniac


Joined: 20 Apr 2014
Posts: 15
Naith wrote:
Are the images rendered correct after they've been fixed?


Yes like you said alls you have to do is edit the images that the dots some how show up on when rendered or uploaded and displayed! I'm just wondering how or what the original artist of thoses bmps did to make a pure black background render those dots,maybe just an old type of bmp file that modern computers have trouble rendering. Those files were made in the early 90's.

I checked new files that were made for server and created with modern programs and none of them have that defect,only the original gfx..still brain boggling to think something was wrong with my code and it was just the defective images.
Naith


Joined: 03 Jul 2014
Posts: 158
Yeah, it's weird. Confused

Glad it turned out good in the end! If you got the same problems with other images you know what to do with that / those image(s).