Archived

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

It might sound stupid but i dont know...

This topic is 5604 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
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
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
quote:
Original post by SysOp_1101
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.


Bzzzzzz - I messed up. What can I say? I looked at it from a totally different perspective (not a wrong one in general, I dare maintain, but slightly off-topic).I even missed the context because I didn''t pay attention to the argument names... However, I never hinted the other posters got it wrong. That, if for no other reason than the fact that I pressed "Reply" when there were no posts in yet, is not true.

Cheers,
Crispy

Share this post


Link to post
Share on other sites
quote:

Bzzzzzz - I messed up. What can I say?



Hehe, wasn''t trying to be harsh on ya'' man. You''re human just like the rest of us (been there done that sort of thing myself).

quote:

However, I never hinted the other posters got it wrong.



I apologize for the misunderstanding, I was in no way trying to insinuate that you did. The answer in your post just seemed to contradict the answers that were already posted (for reasons that you''ve cleared up in your reply).

It''s all good. :D

Share this post


Link to post
Share on other sites
quote:
Original post by SysOp_1101
You''re human just like the rest of us



Care to bet your head on that? Hehehe... Just kidding

quote:
Original post by SysOp_1101
I apologize for the misunderstanding, I was in no way trying to insinuate that you did.



Np, I should''ve paid more attention. Actually, I like it when people correct me when I get something wrong as I''m rather absent-minded

Crispy

Share this post


Link to post
Share on other sites