Jump to content
  • Advertisement
Sign in to follow this  
bennn

pixel level modifications on an SDL_Surface

This topic is 3123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys, i'm a newbie using sdl in C++. I did my codes to try to get rgb color components from an 8-bit grayscale image using what was taught here : <html>http://sdl.beuc.net/sdl.wiki/SDL_PixelFormat</html> However, I keep getting this error: incompatible types in assignment at this line: color = fmt->palette->colors[index]; My partial code as shown below: void colorInterpolation(SDL_Surface *s) { SDL_PixelFormat *fmt; Uint32 temp, pixel; Uint8 red, green, blue, alpha, index; SDL_Color *color; fmt=s->format; /* Check the bitdepth of the surface */ if(fmt->BitsPerPixel!=8){ fprintf(stderr, "Not an 8-bit surface.\n"); return; } SDL_LockSurface(s); .............. ............ /* Get the topleft pixel */ index = *(Uint8 *)s->pixels; color = fmt->palette->colors[index]; //ERROR : incompatible types in assignment WHY?????? ............. ........... ....... Your advice is highly appreciated!!! thanks! :D

Share this post


Link to post
Share on other sites
Advertisement
hi mattd,

could u pls help pin point to me how to change this code to correct this error?

I did exactly like the tutorial below extracted from http://sdl.beuc.net/sdl.wiki/SDL_PixelFormat

1 SDL_Surface *surface;
2 SDL_PixelFormat *fmt;
3 SDL_Color *color;
4 Uint8 index;
5
6 .
7 .
8
9 /* Create surface */
10 .
11 .
12 fmt=surface->format;
13
14 /* Check the bitdepth of the surface */
15 if(fmt->BitsPerPixel!=8){
16 fprintf(stderr, "Not an 8-bit surface.\n");
17 return(-1);
18 }
19
20 /* Lock the surface */
21 SDL_LockSurface(surface);
22
23 /* Get the topleft pixel */
24 index=*(Uint8 *)surface->pixels;
25 color=fmt->palette->colors[index];
26
27 /* Unlock the surface */
28 SDL_UnlockSurface(surface);
29 printf("Pixel Color-> Red: %d, Green: %d, Blue: %d. Index: %d\n",
30 color->r, color->g, color->b, index);

Share this post


Link to post
Share on other sites
Here's an example of what you, or rather what that sample code is doing:


int array[1];
array[0] = 0;

int* pNum = array[0]; //Error is here..similar to the sample code..




There's multiple ways to fix this, but if you are having trouble
understanding this concept, i suggest you read up on what pointers, references, etc. are in C/C++.
Read Chapter 6 here.

Nothing wrong with not understanding..it's all in the learning process.
And, also, don't always assume other people's sample code to be right,
and blindly copy and paste.

Share this post


Link to post
Share on other sites
Hi mattd, thanks for the help seriously!! I have never learnt C++, this is probably the first time do something like that and i'm trying to get things right by myself... Now I got this runtime error "Segmentation fault", what could be wrong??

Share this post


Link to post
Share on other sites
Quote:
Original post by bennn
what could be wrong??

The fact that you're learning a graphics library before you learn the language its interface uses? :) (OK, it's C, but hey)

Post your entire code. Use [source] ... [/source] tags to keep it tidy.

Share this post


Link to post
Share on other sites
I got your PM, but can't you post your code in this thread? That way anyone can help by checking it, or learn from any mistakes pointed out.

Share this post


Link to post
Share on other sites
thanks guys, any help is greatly appreciated, i'm really stucked right now, the functions in the codes aren't fully implemented as i'm still figuring out those errors on hand...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!