home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!corton!loria!loria.crin.fr!eker
- From: eker@loria.crin.fr (Steven Eker)
- Newsgroups: comp.sys.atari.st.tech
- Subject: Re: Need fast image conversion algorithm.
- Message-ID: <473@muller.loria.fr>
- Date: 9 Sep 92 18:16:40 GMT
- References: <79002@ut-emx.uucp>
- Sender: news@news.loria.fr
- Organization: CRIN (CNRS) Nancy - INRIA Lorraine
- Lines: 67
-
- In article <79002@ut-emx.uucp>, timg@ccwf.cc.utexas.edu (Tim Gallivan) writes:
- |> Hi,
- |>
- |> Does anyone have a fast algorithm (or some code) to transform
- |> a packed color image into the appropriate number of color planes?
- |> The packed format for a 4-bit image looks like this:
-
- [stuff deleted]
-
- |> Maybe some hot game hacker could code this up for me to show doubters
- |> that there is still a useful place in the world for his kind of
- |> programming (just wishful thinking :-); or maybe I should announce
- |> a programming contest, yeah, that's it. The winner gets a free copy
- |> of Ghostscript!
-
- Well the naive algorithm involves a lot of shifts which are slow
- on a vanilla 68k. So (off the top of my head) here is an addition based
- solution for the 4-bit case (for speed you always need to specialize, ie
- you need separate code for the 2, 8, 16,.. bit cases):
-
- *
- * Entry:
- * d7 #pixels/16
- * a4 address of source pixels
- * a0 destination for plane 0
- * a1 destination for plane 1
- * a2 destination for plane 2
- * a3 destination for plane 3
- *
- * Exit:
- * d0-d7/a0-a5 trashed
- *
-
- next_block:
- moveq #3,d6 ; 4 words for 16 pixels
- next_word:
- move.w (a4)+,d4 ; get 4 pixels
- moveq #3,d5 ; 4 pixels/word
- next_pixel:
- add.w d4,d4 ; Addition magick
- addx.w d0,d0
- add.w d4,d4
- addx.w d1,d1
- add.w d4,d4
- addx.w d2,d2
- add.w d4,d4
- addx.w d3,d3
- dbra d5,next_pixel
- dbra d6,next_word
- move.w d0,(a0)+ ; store 1 word of each bit plane
- move.w d1,(a1)+
- move.w d2,(a2)+
- move.w d3,(a3)+
- dbra d7,next_block
-
- To call it from C you will need some extra code at the top & bottom to
- save/restore regs & pull the arguments from the stack but this depends
- on the calling conventions of your compiler.
- Note that it assumes you have a multiple of 16 pixels per line so that
- you can have bit planes that have a whole number of words per line.
-
- If this you too slow you can unwind the innermost loop(s). If you intend
- to run it on a 68030 (TT/Falcon) unwind only the innermost loop otherwise
- you will have a lot of cache misses (main loop would then be > 128 bytes).
-
- Steven
-
-