By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

Help: 2D Array Reversing

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
WW
Kevin wrote:
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.

--
WW aka Attila
Jul 19 '05 #2

P: n/a
"Kevin" <ke*********@msn.com> wrote in message
news:e9**************************@posting.google.c om...
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
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #3

P: n/a
Kevin wrote:

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

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Jul 19 '05 #4

P: n/a
Kevin wrote:
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

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.