Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Metal Typhoon

It might sound stupid but i dont know...

This topic is 5817 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

BYTE *GetLine (int line ,BYTE surface,int stride) {return (surface + stride * line);} this little function is bugging me alot... the erro i get is this ''return'' : cannot convert from ''int'' to ''unsigned char *'' But fromt the normal tutorial it work fine.. man.. can someoen give me a tip.. sorry for the dummy question
Metal Typhoon

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The function should probably read:

BYTE* Getline(int line, BYTE* surface, int stride)
{ return (surface + stride*line); }

If you can''t see this then you probably need
to read up on C. (and C++ if you want).

Share this post


Link to post
Share on other sites
Hmmm, looks just like a piece of code I've been working on for my image class.

First off, your data types should be unsigned BYTE* (or unsigned char*). Also changing your function to this:

      
unsigned BYTE *GetLine (int line, unsigned BYTE* surface, int stride) {
return (surface + (stride * line));
}

should make it work.

HTH


SysOp_1101

[edited by - SysOp_1101 on August 16, 2002 4:10:39 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Metal Typhoon
BYTE *GetLine (int line ,BYTE surface,int stride)
{return (surface + stride * line);}
Metal Typhoon



Thats right - you will get that error because surface, I presume, should be a pointer:

BYTE *GetLine ( int Line, BYTE *pSurface, int Stride )
{
return ( pSurface + ( Stride * Line ) );
}

Share this post


Link to post
Share on other sites
Its all to do with "type casting" in C/C++, you can cast anything as anything but only if you tell it. What you need to is explicitly cast the result you are returning as a BYTE*, like this:


BYTE *GetLine (int line ,BYTE surface,int stride)
{return (BYTE*)(surface + stride * line);}



Then all should be happy

NightWraith

Share this post


Link to post
Share on other sites
quote:
Original post by SysOp_1101
Hmmm, looks just like a piece of code I''ve been working on for my image class.

First off, your data types should be unsigned BYTE* (or unsigned char*). Also changing your function to this:


      
unsigned BYTE *GetLine (int line, BYTE* surface, int stride) {
return (surface + (stride * line));
}

should make it work.

HTH


SysOp_1101

[edited by - SysOp_1101 on August 16, 2002 3:58:55 AM]

lol what a conincidence... this fucntion if to read a line pts toa bitmap.. well this i feed the function with the right parameters.. first of if i just compile without using the function the error shows..

Metal Typhoon

Share this post


Link to post
Share on other sites
Consider this:

What you''re doing is this:


  
BYTE *a;

//assigning to a pointer address!

a = surface + stride * line;


Furthermore, you don''t have BYTE *a, but BYTE* is a return type which is a pointer, not the same as (surface + stride * line), which is an integer. The compiler''s smart enough to check what you''re returning against what you''ve meant to return in a function. Remember, usually BYTE == char, so BYTE* == char*!

Simply change that return type to what you''re returning, or vice versa:


  
int GetLine (int line ,BYTE surface,int stride)
{
return (surface + stride * line);
}


Hope this helps,
Crispy

Share this post


Link to post
Share on other sites
OMGGGGGGGGGG thx for all the replies... how i did not see that ? LOLSSSSSSS i''ve been programming for 10 hours straight O_o i think i need to sleep

Metal Typhoon

Share this post


Link to post
Share on other sites
Crispy,

What he is returning is a pointer to an unsigned char[] in memory, not an offset to plug between the brackets. The way that numerous posters suggested is not incorrect. The surface + stride * line simply tells the application to move the current byte pointer (stride * line) bytes ahead of the current pointer (thus setting it at the next line). You then use the returned pointer as the offset in memory to begin reading from or writing to.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!