Help: 2D Array Reversing

K

Kevin

Hello,

I need to some help in reversing an 2-dimensional array. I am working
with gif images and I am trying to make the mirror image. I was
hoping that someone could help give me a headstart in how I can
accomplish this. Also, I don't know the the size of the array before
hand as the image can be any size. I already have the my read and
write gif functions working, but I just need to know how to reverse
the contents.

Thanks for your help in advance.
 
W

WW

Kevin said:
Hello,

I need to some help in reversing an 2-dimensional array. I am working
with gif images and I am trying to make the mirror image. I was
hoping that someone could help give me a headstart in how I can
accomplish this. Also, I don't know the the size of the array before
hand as the image can be any size. I already have the my read and
write gif functions working, but I just need to know how to reverse
the contents.

Post some code. At least enough to know the type and layout of your array.
 
J

Jakob Bieling

Kevin said:
Hello,

I need to some help in reversing an 2-dimensional array. I am working
with gif images and I am trying to make the mirror image. I was
hoping that someone could help give me a headstart in how I can
accomplish this. Also, I don't know the the size of the array before
hand as the image can be any size. I already have the my read and
write gif functions working, but I just need to know how to reverse
the contents.

Thanks for your help in advance.

Well, suppose you have a realtiny bitmap .. 4x4 pixels, and

0 1 2 3
4 5 6 7
8 9 a b
c d e f

are the fields (each field represents one pixel). The mirror image would
have to look like this:

3 2 1 0
7 6 5 4
b a 9 8
f e d c

Now if you did not know the dimension, the image could be 8x2 pixel as
well:

0 1 2 3 4 5 6 7
8 9 a b c d e f

and the mirrored image for that is:

7 6 5 4 3 2 1 0
f e d c b a 9 8

If now you put all rows into one single row (one row after the other,
the way they are stored in memory) you will find that the mirrored image for
the 4x4 image and the 8x2 image are not the same. So first, you better find
out the size of that image. For the reversing task, you could use
std::reverse for each row. Also note that each field above represents one
pixel of the image (this includes all possible bytes needed to represent
that pixel). You have to keep that in mind when using std::reverse,
otherwise your colors will get messed up.

hth
 
D

David Rubin

Kevin said:
Hello,

I need to some help in reversing an 2-dimensional array. I am working
with gif images and I am trying to make the mirror image. I was
hoping that someone could help give me a headstart in how I can
accomplish this. Also, I don't know the the size of the array before
hand as the image can be any size. I already have the my read and
write gif functions working, but I just need to know how to reverse
the contents.

std::reverse(r.begin(), r.end()) for each row in the array? Or is there
something particular about GIF (as opposed to PPM) that won't let you do
this?

/david
 
T

Thomas Matthews

Kevin said:
Hello,

I need to some help in reversing an 2-dimensional array. I am working
with gif images and I am trying to make the mirror image. I was
hoping that someone could help give me a headstart in how I can
accomplish this. Also, I don't know the the size of the array before
hand as the image can be any size. I already have the my read and
write gif functions working, but I just need to know how to reverse
the contents.

Thanks for your help in advance.

I've always found that assembly languages are best at bit manipulation.
Your processor may have some instructions that will be more efficient
than C++ code.

I suggest you ask about image transformations in a graphics newsgroup.
They will probably have better algorithms there.

You could treat the graphic as a matrix and apply a transformation
to it.

You could copy the bits, row by row, in a reverse order to another
image or matrix.

You could write a multi-bit swap routine and apply it to each row.

.....

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top