Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

acessing a 1D array with row/col

Name: Anonymous 2009-04-21 8:27

imagePtr[i*cols + j]
where i and j are the row/col coordinates. this isn't right, i can't remember how else to do it. i know it's something LIKE this, just not exactly what, and google isn't cooperating. do i need to use the memory locations?

Name: Anonymous 2009-04-21 8:32

What makes you think this isn't right?

Name: Anonymous 2009-04-21 8:33

It's right. Although a variable called imagePtr is pretty dumb.

Name: Anonymous 2009-04-21 8:36

>>2
it doesn't work. memory access violation
>>3
mandated
it's actually a pointer, did i do something wrong there? do i need to dereference it or something?

Name: Anonymous 2009-04-21 8:37

entire sample

image_ptr negateImage(image_ptr imagePtr, int rows, int cols, int maxval)
{
    int i,j;
   
    for (i=0; i<rows; i++)
    {
        for (j=0; j<cols; j++)
        {
            printf(" %d", (i*cols + j));
            imagePtr[i*cols + j] = abs((imagePtr[i*cols + j]-maxval));
        }
    }
}

Name: Anonymous 2009-04-21 8:38

Please stop.
This really isn't a homework help forum.

Name: Anonymous 2009-04-21 8:39

abs((imagePtr[i*cols + j]-maxval));
what the shit

Name: SAGEFAULT 2009-04-21 8:40

SAGEFAULT

Name: Anonymous 2009-04-21 8:48

>>7
it's supposed to be the negative of the grey scale color pixel value stored in (i,j), where maxval is the maximum value of the scale.

Name: Anonymous 2009-04-21 8:55

Whatever's causing your memory access violation isn't visible in that code. Check the part where you're allocating imagePtr.

Name: Anonymous 2009-04-21 8:56

>>9
That was not my issue, sir

Name: Anonymous 2009-04-21 8:57

ITT we can't handle a new/malloc and try to rewrite Photoshop from scratch anyway

Name: Anonymous 2009-04-21 9:03

Name: Anonymous 2009-04-21 9:04

>>11
then what were you trying to say?

Name: Anonymous 2009-04-21 9:09

image_ptr negateImage(image_ptr imagePtr[], int rows, int cols, int maxval)

Name: Anonymous 2009-04-21 9:20

So, you're either overflowing your buffer, or your buffer is not of the right size. ( it should be of size cols*rows )
You didn't provide us enough code for us to be able to fix your problem, but fear not, as you can probably solve it yourself. Get a debugger! Run the application and see where it breaks, or set a breakpoint on the faulty line(which you already know), set a breakpoint on where you alloc the picture buffer as well, after this, such simple errors become apparent, but if that wasn't enough, you may post the full code and maybe some kind anon will help you, but you really shouldn't rely on that!

Name: Anonymous 2009-04-21 9:22

>>4
it's actually a pointer, did i do something wrong there?
Yes, you gave it a dumb name. Although image_ptr imagePtr is even worse.

Name: Anonymous 2009-04-21 10:26

ITT we don't know the difference between rows and columns.

And between pointers and arrays, though that's not the issue here.

Name: Anonymous 2009-04-21 10:32

>>18
It seems you're the only one here who doesn't know the difference between rows and columns.

Name: Anonymous 2009-04-21 10:49

, /prog/, >>10 and >>16 had it right, sorta. it turns out img_ptr actually isn't just a 1D array as i had thought, or something. anyway

image_ptr negateImage(image_ptr imagePtr, int rows, int cols, int maxval)
{
    int i,j;
    unsigned char image[rows][cols];
   
    for (i=0; i< rows; i++)
    {
        for (j=0; j< cols; j++)
        {
            image[i][j] = abs((imagePtr[i*cols + j]-maxval));;
        }
    }
   
    imagePtr=(image_ptr) image;
}

works now. or at least it doesn't crash and it obviously messes with the image, only question now is how to actually get the inversion working. i had thought what i had would work (it's for .pgm files), but it isn't. i can figure it out i'm sure, thanks again!

Name: Anonymous 2009-04-21 11:10

>>20
works now
No, it doesn't.

Name: Anonymous 2009-04-21 11:22

>>21
uh, what? the problem i was having is solved...

Name: Anonymous 2009-04-21 11:37

>>22
You don't understand what your problem was. You've done something that seems to work, and think you've solved it.

There is a name for this kind of asshattery.

Name: Anonymous 2009-04-21 11:41

>>23
Shhh.  As long as he believes it, at least our problem is solved.

Name: Anonymous 2009-04-21 11:41

>>23
You talk a whole lot of shit without giving any information about the problem. Your posts are general enough that they could apply to anything.

Name: Anonymous 2009-04-21 12:04

>>17
Couldn't agree more, it's people like >>4 who perverted hungarian notation.

Name: Anonymous 2009-04-21 12:15

>>25
"My posts"? What are you, an EXPERT EXTRAPOLATOR?

The information given doesn't make more specific help possible. I'm just telling you that you're making the grave error of mistaking "it seems to work" for "it works". This just shows you're very inexperienced in C. If you want to act all pissed off at someone offering genuine help, be my guest. You've already failed at life.

----------
Posted from my iPhone

Name: Anonymous 2009-04-21 12:39

>>27
my apologies if i have misinterpreted your intentions (which i honestly still don't think i have), i'm used to elitist faggotry and disinformation/aggravation from /prog/. it is working as i expected (more or less), and i know what i was doing wrong (trying to use the image_pointer structure as an simple array of unsigned int/char when in reality writing to it is not possible as so).

Name: Anonymous 2009-04-21 12:46

Holy dicks.

----------
Posted from my TI-89

Name: Anonymous 2009-04-21 13:10

imagePtr=(image_ptr) image;
Bwahahahahaha so clueless...

Name: Anonymous 2009-04-21 13:32

>>30
yeah i caught that. should be return, obviously.

Name: Anonymous 2009-04-21 17:22

>>31
This is getting silly, Mr.Troll.
I refuse to believe you are a genuine idiot you pretend to be.

Name: Anonymous 2009-04-21 21:03

>>32
what's wrong with it? the casting? it may be unnecessary, but is it not proper programming practice to do it anyway? go fuck yourself, this is the kind of stupid elitist circlejerking that i've come to expect from /prog/.

Name: Anonymous 2009-04-22 6:53

>>33
go fuck yourself, this is the kind of stupid elitist circlejerking that i've come to expect from /prog/.
I'll give you a hint.

Nobody wants to help you because you're doing stupid and boring shit a 5 year old would figure out. If you can't spend enough effort to read a book on basic C then that's your problem.

go fuck yourself, this is the kind of stupid elitist circlejerking that i've come to expect from /prog/.
Stop acting like a child.

Name: Anonymous 2009-04-22 11:24

OP here, I apologize for that outburst, I don't know what came over me. Now, if you'll just answer my question everything will be fine

Name: Anonymous 2009-04-22 11:32

Stop programming. Now and forevermore.

Name: Anonymous 2009-04-22 11:44

OP here, I apologize for that outburst, I don't know what came over me. Now, if you'll just leave me to suck a billion cocks everything will be fine

Name: Anonymous 2009-04-22 11:50

Do it twice. Call this function with two different pictures. Then you'll understand that whatever you're doing is wrong and you're not getting any ``disinformation from (unspoilered)/prog/''. This is such a basic problem that having people who don't even know about it post on our nice textboard is very embarrassing. Please go away. We don't want your kind here. There is that stack overflow forum and many other web 2.0 websights full of people who just learned about this and want world to know.

Name: Anonymous 2009-04-22 11:54

and want world to know.

Name: Anonymous 2009-04-22 11:59

>>20
imagePtr=(image_ptr) image;
Wow. What is that supposed to do?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List