Image Remapping

Image Remapping

Post by Finn Higgin » Wed, 06 Aug 1997 04:00:00



Oh, and while I'm on this "asking questions" bit...

Anybody got a image remapping routine actually runs at a decent speed?  I
wrote a version that would remap an Intuition Image struct to a new screen
palette (Using ObtainBestPen to fill in the palette, then * little binary
operators to write the new pen numbers into the image one by one), but it is
slow as Windows.

It takes around 10 seconds on an '030 to remap a 32x32 image, which is really
pushing it considering I want to use it to remap images for a GUI :)

And speaking of images... Anybody got source for loading an IFF ILBM into an
intuition Image and loading the palette into an array of sorts?

Finn

 
 
 

Image Remapping

Post by Finn Higgin » Thu, 07 Aug 1997 04:00:00



>> Anybody got a image remapping routine actually runs at a decent speed?  I
>> wrote a version that would remap an Intuition Image struct to a new screen
>> palette (Using ObtainBestPen to fill in the palette, then * little
>> binary operators to write the new pen numbers into the image one by one),
>> but it is slow as Windows.
>I was able to get a reasonably fast routine using a combination of
>ReadPixelLine8(), WritePixelLine8(), and keeping a lookup table of the
>remapped pens, so I only needed to call ObtainBestPen once for each pen
>colour.

Yeah, I think that it is the ReadPixelLine8 compared to my own code that would
be making the difference.  I found the difference between a lookup table and
doing an ObtainBestPen for each pixel quite tiny, but I use a lookup table
anyway :)

Quote:>I'm sure there's a better way of doing it though.

There always is.  Lets hope somebody comes up with it.. Come to think about
it, we are basically doing Planer->Chunky->Planer, maybe some C2P code would
yield an idea or two :)

Quote:>Jon

Finn

 
 
 

Image Remapping

Post by Trond Werner Hanse » Thu, 07 Aug 1997 04:00:00



Quote:> There always is.  Lets hope somebody comes up with it.. Come to think about
> it, we are basically doing Planer->Chunky->Planer, maybe some C2P code would
> yield an idea or two :)

Can't you just use datatypes to handle it? Then you'll get a nice bitmap
(+mask) which is remapped and everything to the best possible
pixelformat/palette? In most cases, if you need a lot of images in your
app, the best way is just to use an artprogram to tile all the images into
one big picture, have it as a single file, which you load using datatypes.
It's fast, less work for you, works with everything, and even lets the
user change the gfx! :)

Greetings,

Trond Werner Hansen, slave at Norwegian University of Science and Technology.

Developing WorkbenchNG and Playboy3.0 | Amiga - There's a lady in every story -

 
 
 

Image Remapping

Post by Frank Pagel » Sun, 10 Aug 1997 04:00:00




>: Oh, and while I'm on this "asking questions" bit...
>: Anybody got a image remapping routine actually runs at a decent speed?
>Pass the image through the picture.datatype :)
>At least, I've never waited 10 seconds for a 256 colour 320x256 picture
>to remap to a WB with 120 pens free.

Best is to try the render.library on aminet. It is fast as hell :)

RenderLib.lha      dev/misc   153K   2+Image processing kernel

Frank

--
Frank (Copper) Pagels / Defect Softworks


IRC:    Copper, on #amigager
WWW:    HTTP://home.pages.de/~defect/

 
 
 

Image Remapping

Post by Marti » Wed, 13 Aug 1997 04:00:00






>>: Oh, and while I'm on this "asking questions" bit...

>>: Anybody got a image remapping routine actually runs at a decent speed?
>>Pass the image through the picture.datatype :)

>>At least, I've never waited 10 seconds for a 256 colour 320x256 picture
>>to remap to a WB with 120 pens free.

>Best is to try the render.library on aminet. It is fast as hell :)

>RenderLib.lha      dev/misc   153K   2+Image processing kernel

>Frank

Is there any examples preferably in C that use the render lib, I did not
find any with the archive?
I am *not* trying to remap images, im just trying to get the hang of
graphics programming and think the render library may help skip the
* parts for the moment.  

>--
>Frank (Copper) Pagels / Defect Softworks


>IRC:   Copper, on #amigager
>WWW:   http://www.veryComputer.com/~defect/

--
Martin Naylor AmigaA1200T/Blizzard-1230-III/16MB/Compaq151FS (SVGA==DBLPAL)
Soon to be 68060 (blizzard) :)
 
 
 

Image Remapping

Post by Mary Karmela Luc » Sat, 16 Aug 1997 04:00:00





>>>Oh, and while I'm on this "asking questions" bit...

>>>Anybody got a image remapping routine actually runs at a decent speed?

Sorry, i lost the original message & cant seem to find it :-\

Someone said something about using the blitter to remap a picture(???)

The blitter works really well for an 8 colour picture!
This is how i do it:

(The target pen array is just for illustration, use any pens
numbers you like)

S2 S1 S1            T2 T1 T1
0 0 0     ~A~B~C    1 1 0
0 0 1     ~A~BC     1 1 0
0 1 0     ~AB~C     1 0 1
0 1 1     ~ABC      0 0 0
1 0 0     A~B~C     0 1 0
1 0 1     A~BC      0 1 1
1 1 0     AB~C      1 1 1
1 1 1     ABC       0 0 1

Set the blitter C to source bitplane 0
Set the blitter B to source bitplane 1
Set the blitter A to source bitplane 2

Target bitplane 0 minterm = ABC+AB~C+A~BC+~AB~C = %11100100
Target bitplane 1 minterm = AB~C+A~BC+A~B~C+~A~BC+~A~B~C = %01110011
Target bitplane 2 minterm = AB~C+~AB~C+~A~BC+~A~B~C = %01000111

(Note that you read the "T" column from bottom to top to get the minterm)

This works a treat!

Any tortology gurus care to extend it to 8 bitplanes?

Remember to use OwnBlitter() or QBlit() to be nice and system friendly!

For more bitplanes i think its faster to use a planar2chunky, remap,
chunky2planar to do the mapping but im not sure.

Also, how does one emulate the minterm function of the blitter
using the CPU?

Cheers,
--  ___                     ___
   |  .| _____ __  __ _____/   \
.--'  :|/    .Y  || .Y -- _)-7_/
| --  ;| --  ;|  `' ;|   (_  _  Daves not here man.
`------^----^-^------^-----'`-'
"Beware of yellow snow"

 
 
 

Image Remapping

Post by Tatu Rissan » Sun, 17 Aug 1997 04:00:00






>>>>Oh, and while I'm on this "asking questions" bit...

>>>>Anybody got a image remapping routine actually runs at a decent speed?
>Any tortology gurus care to extend it to 8 bitplanes?

If you have more than 3 sources and you insist using blitter, you have
to divide the problem into smaller problems. The results from those
subproblems have to be stored somewhere, and then combined.

Eg. Function ~ABCD+~A~BCD+~A~B~C~D equals to:
D(~ABC+~A~BC)+~D(~A~B~C)
Do two blits into temporary storages:
tmp1 = ~ABC+~ABC
tmp2 = ~A~B~C
And then combine the results:
final = Dtmp1 + ~Dtmp2

Four sources require 3 blits and 2 temporary buffers. One of the buffers might
be the target, so only one extra buffer is needed. Eight sources would
require a lot more blits and temporary storage. Drawing a complete binary
tree on paper might shed some light on the problem. The depth of the tree
equals to image's depth - 3. Each node presents one blit and it's result
has to saved somewhere.

planes blits buffers
--------------------
3      1     0
4      3     1
5      7     2
6      15    3
7      31    4?
8      63    5?

As you can see pure blitter solution is unsuitable for 8 planes deep images.
Those 63 blits are required for each target plane.

Quote:>Also, how does one emulate the minterm function of the blitter
>using the CPU?

I know it's not common to send sources here, but since I got something
recently written at hand, here goes.

Tatu Rissanen

-- clip - clip - clip --
#include <stdio.h>

void remap(unsigned int **, int, unsigned char *);
void printImage(unsigned int **, int);
void buildTerms(int *, unsigned char *);

unsigned int data[3][4] = {
    { 0x38220455,
      0x60360400,
      0x302A0400,
      0xE0220700 },
    { 0x03220033,
      0x04B60000,
      0x07AA0000,
      0x04A20000 },
    { 0x0000E40F,
      0x00009400,
      0x0000E400,
      0x00008700 }

Quote:};

int mapping[8] = { 3, 4, 6, 1, 7, 1, 0, 5 };

int main()
{
    unsigned int *image[3];
    unsigned char f[3];
    int count = sizeof(data[0]) / sizeof(unsigned int);

    image[0] = data[0];
    image[1] = data[1];
    image[2] = data[2];
    buildTerms(mapping, f);
    printf("before:\n");
    printImage(image, count);
    remap(image, count, f);
    printf("after:\n");
    printImage(image, count);
    return 0;

Quote:}

void printImage(image, count)
unsigned int *image[3];
int count;
{
    unsigned int mask = 0x80000000;
    char color;
    unsigned int *a[3];
    a[0] = image[0];
    a[1] = image[1];
    a[2] = image[2];

    while (count-- > 0) {
        for (mask = 0x80000000; mask; mask >>= 1) {
            color = 0;
            if (*a[0] & mask)
                color += 1;
            if (*a[1] & mask)
                color += 2;
            if (*a[2] & mask)
                color += 4;
            printf("%2x", color);
        }
        a[0]++;
        a[1]++;
        a[2]++;
        printf("\n");
    }

Quote:}

void buildTerms(mapping, f)
int mapping[8];
unsigned char f[3];
{
    unsigned char readMask, writeMask;
    int i, j;

    for (readMask = 0x01, i = 0; i < 3; i++, readMask <<= 1) {
        f[i] = 0x00;
        for (writeMask = 0x80, j = 0; j < 8; j++, writeMask >>= 1) {
            if (mapping[j] & readMask)
                f[i] |= writeMask;
        }
    }

Quote:}

/*
 * Remaps source planes to new set of colors.
 *
 * Now images must be only 3 planes deep, but this can be expanded to
 * handle 4 planes, but it doubles the work. Expanding to handle 5 planes
 * again doubles the work, ans so on. Remapping 8 planes deep image would
 * require 256 tests and logical operations for each long word, and
 * a little imagination to expand each element of f to contain 256 bits.
 * The algorithm might prove to be unsuitable for images that deep.
 *
 * This routine should be written in assembler for speed and to make sure
 * that the register allocation is done right.
 *
 * The outcome of the remapping will be written over the source.
 *
 * image - array of pointers to source planes
 * count - number of long words to process
 * f     - functions to perform on source data (minterms)
 *
 * Eg. mapping { 4, 0, 2, 2, 1, 5, 6, 1 }
 *
 * source bits      target bits
 * s2 s1 s0         t2 t1 t0
 * 0  0  0     -->  1  0  0
 * 0  0  1     -->  0  0  0
 * 0  1  0     -->  0  1  0
 * 0  1  1     -->  0  1  0
 * 1  0  0     -->  0  0  1
 * 1  0  1     -->  1  0  1
 * 1  1  0     -->  1  1  0
 * 1  1  1     -->  0  0  1
 *
 * would yield
 * unsigned char f[3] = { 0x0D, 0x32, 0x86 };
 */
void remap(image, count, f)
unsigned int *image[3];
int count;
unsigned char f[3];
{
    unsigned int d0, d1, d2, result;
    int i;
    unsigned int *a[3];

    a[0] = image[0];
    a[1] = image[1];
    a[2] = image[2];
    while (count-- > 0) {
        d0 = *a[0];
        d1 = *a[1];
        d2 = *a[2];
        for (i = 0; i < 3; i++) {
/*
 * It is would be nice to poke the function as a set of instructions
 * into memory, and then just jump to that code rather than
 * checking for each bit in f for every written long word.
 * But that would be illegal, wouldn't it?
 */
            result = 0;
            if (f[i] & 0x80)
                result |= ~d2 & ~d1 & ~d0;
            if (f[i] & 0x40)
                result |= ~d2 & ~d1 & d0;
            if (f[i] & 0x20)
                result |= ~d2 & d1 & ~d0;
            if (f[i] & 0x10)
                result |= ~d2 & d1 & d0;
            if (f[i] & 0x08)
                result |= d2 & ~d1 & ~d0;
            if (f[i] & 0x04)
                result |= d2 & ~d1 & d0;
            if (f[i] & 0x02)
                result |= d2 & d1 & ~d0;
            if (f[i] & 0x01)
                result |= d2 & d1 & d0;
            *a[i]++ = result;
        }
    }

Quote:}

 
 
 

Image Remapping

Post by Kyze » Mon, 18 Aug 1997 04:00:00



: Also, how does one emulate the minterm function of the blitter
: using the CPU?

I posted a C source do to that a few months ago, look it up on DejaNews :)
It's also in the UAE source.

--

My opinions are not those of Aberdeen University, and I do not speak for or
on behalf of AUCC.
                   ..100% Amiga, forever!..  http://www.abdn.ac.uk/~u13sac/

--
Random sig of the day:
HC(S) S? H! L++ Xamigas P V2++ N-- DM--- DL-- DC++ HR+++ HK! HNM! CCC* CCJ+++
CCH+ R++ SPAM SPOD+

 
 
 

1. Image Remapping Help Wanted

Let's put it this way: the SS_LoadImage() (and it's major sub-functions
SS_LoadIBM() and SS_AllocateColors()) make up an considerable ampount
of code inside my ScreenSupport.library. Short: it's a little too much
to post here. I can send you the current source, if you like (although
it might be better to wait a couple of days, since I'm currently cutting
the ILBM stuff from an application to put it into the library, and the
Library-version hasn't been fully debugged yet). Mail me.

The basic ideas are:
- you need a color allocation function. This should sort the
  colors --- it should allocate "different" colors before allocating
  colors that are "close" to colors already allocated (like: allocate
  "red, green, blue, dark red, light green" instead of "red, dark red,
  green, light green, blue" etc). This improves results on machines
  with only a few free pens
- read the image into a one line bitmap, remap it using ReadPixelLine()
  and WritePixelLine() (this is faster than ReadPixel()/WritePixel,
  and faster than using the blitter)
- make sure you handle masks correctly (a couple of special casees,
  such as BMF_STANDARD targets should be considered). If you don't care
  about masks, you still need to ignore a mask plane if the file has
  one, and handle the transparent color correctly. I don't support
  maskLasso, though.
- you can ignore all chunks except for CMAP, BMHD and BODY. Other chunks
  don't provide anything useful (although I'm still thinking about
  supporting EHB images, but there is really no need for it).

Christian

2. CSocket performance

3. Datatypes/image remapping

4. SAS GRAPH output as pdf file

5. Image dithering & remapping

6. Attention trolls! The clock is ticking....

7. Remapping an image to a colour map

8. FOLLOW-UP: Brand New And Just Released - SASLearningEdition CD- Rom

9. Boopsi Image Question: can't get image fields to display

10. When is a ROM image not a ROM image?

11. Remapping demo finished. Uploaded to wuarchive

12. Problem to remap the rom on a blizzard 1230 III

13. Apollo 1240/40 Remapping Kickstart?