Menu

#21 Flip images at load time (iterators?)

open
nobody
None
7
2003-02-26
2003-02-25
subatomic
No

Similar to the flipimage task, but this would involve
swapping the memory in-place, or (preferably) at load
time...

For generic memory mapping specifiable at load-time,
I'd suggest using an iterator type scheme. Something
that would optimize out to the same code you'd execute
anyway (we don't want loads to be slower)...

A generic image iterator would make it easier to
implement across all the specific loaders. Like a
reverse iterator that you set up before actually loading,
then when it just loads as usual, but the reverse iterator
takes care of the oposite ordering.

How about support for swizzled images? Just
kidding... :) An iterator scheme would support even
crazy stuff like that (which is common on some
video hardware like xbox)...

Might be cool to think about iterators at least.

Here's some code for a post-load in-place image flip that
could be implemented now:

corona::Image* im = corona::OpenImage( name,
corona::PF_R8G8B8A8 );

int pixelsize = (im->getFormat() ==
corona::PF_R8G8B8A8) ? 4 : 3;
int rowsize = pixelsize * im->getWidth();
std::vector<char> row;
row.resize( rowsize );
for (int y = 0; y < im->getHeight()/2; ++y)
{
char* top = &((char*)im->getPixels())[y * rowsize];
char* bottom = &((char*)im->getPixels())[((im-
>getHeight()-1) - y) * rowsize];
memcpy( &row[0], top, rowsize );
memcpy( top, bottom, rowsize );
memcpy( bottom, &row[0], rowsize );
}

Discussion

  • subatomic

    subatomic - 2003-02-25

    Logged In: YES
    user_id=49859

    note: the reason for this change is because some art tools
    like MAX have their 0,0 texcoord at the beginning of the
    _last_ row of the image in memory. Currently Corona
    defaults to the beginning of the _first_ row being the first
    segment of memory, which makes 0,0 match up with this
    portion - something that makes the image appear flipped
    vertically when mapped onto assets exported from Max.

     
  • Chad Austin

    Chad Austin - 2003-02-26

    Logged In: YES
    user_id=7212

    Since FlipImage operates in-place now, I'm making this bug
    "flip images at load-time"

     
  • Chad Austin

    Chad Austin - 2003-02-26
    • summary: Support upsidedown images (iterators?) --> Flip images at load time (iterators?)
     

Log in to post a comment.