1. Masking

Is there a fster way to display a bitmap on the screen without the pixels 
which are the mask color, other than plotting each color individually in a 
loop?

this is the code im using at the moment:

for y = 1 to length(img) do
    for x = 1 to length(img[y]) do
        if img[y][x] != MASK_COLOR then
            pixel(img[y][x], {imgX + x, imgY + y})
        end if
    end if
end for

this is too slow for what i am doing.


thanks in advance

StewartML

new topic     » topic index » view message » categorize

2. Re: Masking

You could use the SSE/3dnow!ext instruction MASKMOVQ, it does the following

MASKMOVQ mm1, mm2
if (mm2[7])  m64[edi]   = mm1[7-0];
if (mm2[15]) m64[edi+1] = mm1[15-8];
if (mm2[23]) m64[edi+2] = mm1[23-16];
if (mm2[31]) m64[edi+3] = mm1[31-24];
if (mm2[39]) m64[edi+4] = mm1[39-32];
if (mm2[47]) m64[edi+5] = mm1[47-40];
if (mm2[55]) m64[edi+6] = mm1[55-48];
if (mm2[63]) m64[edi+7] = mm1[63-56];

That should go SUPER fast
Daniel Kluss
----- Original Message ----- 
From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
To: <EUforum at topica.com>
Sent: Saturday, November 08, 2003 11:30 AM
Subject: Masking


>
>
> Is there a fster way to display a bitmap on the screen without the pixels
> which are the mask color, other than plotting each color individually in a
> loop?
>
> this is the code im using at the moment:
>
> for y = 1 to length(img) do
>     for x = 1 to length(img[y]) do
>         if img[y][x] != MASK_COLOR then
>             pixel(img[y][x], {imgX + x, imgY + y})
>         end if
>     end if
> end for
>
> this is too slow for what i am doing.
>
>
> thanks in advance
>
> StewartML
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Masking

On Saturday 08 November 2003 02:30 pm, Stewart wrote:
>
>
> Is there a fster way to display a bitmap on the screen without the pixels
> which are the mask color, other than plotting each color individually in a
> loop?
>
> this is the code im using at the moment:
>
> for y = 1 to length(img) do
>     for x = 1 to length(img[y]) do
>         if img[y][x] != MASK_COLOR then
>             pixel(img[y][x], {imgX + x, imgY + y})
>         end if
>     end if
> end for
>
> this is too slow for what i am doing.

I realize this probably won't help you, but I was just writing a program which 
moves a sprite with transparent background around on a photographic background 
image. 

To do this in Linux/GTK takes exactly one line of code to load the image:
img = image("images/tux.xpm")
and one line to move it: 
set(background,"Put",{ img, x, y })

It works with .gif, .png, .xpm, and .tif files, perhaps others.

Regards,
Irv

-- 
Robert Tappen Morris, Jr., got six months in jail for crashing 10% of the
computers that Bill Gates made $100 million crashing last weekend.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Masking

Stewart,

if you are after a purely Euphorian solution, have a look at the following
routine that I wrote many years ago. It may not be good enough for whatever
you are doing, but give it a try. In comparison with yours, it has three
common, often quite significant optimizations:

    1. reduced indexing level
    2. a whole *run* of pixels is written instead of each one separately
    3. unnecessary addition of 'y' coordinates is eliminated.

jiri

global procedure merge_image(
    sequence xy,            -- top left corner
    sequence image,         -- 2-d image sequence
    integer c)              -- transparent cell color index

    --  display 2-d sequence image at point x,y
    --  image cells of color c are considered transparent

    sequence row
    integer f,k,w,x,y

    x = xy[1]-1
    y = xy[2]
    for i=1 to length(image) do
        row=image[i]
        w = length(row)
        f=0                 -- not in run
        for j=1 to w do
            if row[j]=c then
                if f then
                    pixel(row[k..j-1],{x+k,y})
                    f=0
                end if
            else
                if not f then
                    k=j
                    f=1
                end if
            end if
        end for
        if f then
            pixel(row[k..w],{x+k,y})
        end if
        y+=1
    end for
end procedure -- merge_image


----- Original Message ----- 
From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
To: <EUforum at topica.com>
Sent: 09 November 2003 8:30 AM
Subject: Masking


>
>
> Is there a fster way to display a bitmap on the screen without the pixels
> which are the mask color, other than plotting each color individually in a
> loop?
>
> this is the code im using at the moment:
>
> for y = 1 to length(img) do
>     for x = 1 to length(img[y]) do
>         if img[y][x] != MASK_COLOR then
>             pixel(img[y][x], {imgX + x, imgY + y})
>         end if
>     end if
> end for
>
> this is too slow for what i am doing.
>
>
> thanks in advance
>
> StewartML
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: Masking

Here is a way try this, take the image and compile it like this
this does only one line
sequence line,comp
atom clear
comp={}
line=your line
clear=0
for i = 1 to length(line) do
    if line[i]=CLEARCOLOR then clear+=1
    else comp&=clear&line[i] clear=0
    end if
end for

And to display a compiled line do this
atom x,y
x=your x
y=your y
for i = 1 to length(comp) by 2 do
    x+=comp[i]
    pixel({x,y},comp[i+1]
end for

THATS ALL FOLKS

Daniel Kluss
----- Original Message ----- 
From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
To: <EUforum at topica.com>
Sent: Saturday, November 08, 2003 11:30 AM
Subject: Masking


>
>
> Is there a fster way to display a bitmap on the screen without the pixels
> which are the mask color, other than plotting each color individually in a
> loop?
>
> this is the code im using at the moment:
>
> for y = 1 to length(img) do
>     for x = 1 to length(img[y]) do
>         if img[y][x] != MASK_COLOR then
>             pixel(img[y][x], {imgX + x, imgY + y})
>         end if
>     end if
> end for
>
> this is too slow for what i am doing.
>
>
> thanks in advance
>
> StewartML
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: Masking

I just thought of a better way

 sequence line,comp,run
 atom clear
 comp={}
 line=your line
 clear=0
 run={}
 for i = 1 to length(line) do
     if line[i]=CLEARCOLOR then clear+=1
     elsif clear=0 then run&=line[i]
     else comp&=clear&{run} clear=0 run={}
     end if
 end for

 And to display a compiled line do this
 atom x,y
 x=your x
 y=your y
 for i = 1 to length(comp) by 2 do
     x+=comp[i]
     pixel({x,y},comp[i+1])
 end for

Daniel, that should be faster

----- Original Message ----- 
From: "Daniel Kluss" <codepilot at netzero.net>
To: <EUforum at topica.com>
Sent: Saturday, November 08, 2003 2:41 PM
Subject: Re: Masking


>
>
> Here is a way try this, take the image and compile it like this
> this does only one line
> sequence line,comp
> atom clear
> comp={}
> line=your line
> clear=0
> for i = 1 to length(line) do
>     if line[i]=CLEARCOLOR then clear+=1
>     else comp&=clear&line[i] clear=0
>     end if
> end for
>
> And to display a compiled line do this
> atom x,y
> x=your x
> y=your y
> for i = 1 to length(comp) by 2 do
>     x+=comp[i]
>     pixel({x,y},comp[i+1]
> end for
>
> THATS ALL FOLKS
>
> Daniel Kluss
> ----- Original Message ----- 
> From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
> To: <EUforum at topica.com>
> Sent: Saturday, November 08, 2003 11:30 AM
> Subject: Masking
>
>
> > Is there a fster way to display a bitmap on the screen without the
pixels
> > which are the mask color, other than plotting each color individually in
a
> > loop?
> >
> > this is the code im using at the moment:
> >
> > for y = 1 to length(img) do
> >     for x = 1 to length(img[y]) do
> >         if img[y][x] != MASK_COLOR then
> >             pixel(img[y][x], {imgX + x, imgY + y})
> >         end if
> >     end if
> > end for
> >
> > this is too slow for what i am doing.
> >
> >
> > thanks in advance
> >
> > StewartML
> >
> >
> > TOPICA - Start your own email discussion group. FREE!
> >
> >
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

7. Re: Masking

I've done this in a graphics lib I wrote...

It involved pre-loading the image, uh.... Have a look through the attached 
file. Basically, euphoria can draw a sequence of pixels much faster than 
doing it pixel by pixel.

What my graphics lib does is process the image, breaking each line up into 
lines of pixels that should be drawn, and ignoring the rest.

ie: if 0 is the transparent colour, and the first line of the image looks 
initially like this:
(random chars represent colours)
0000000000000af6732$@waer789awf000000000J8474@#a78a74900000000000000

Then it splits the line up into af6732$@waer789awf and J8474@#a78a749, and 
displays them
at the right positions.
It's very very fast, because there are no if statements, and it accomplishes 
things in as few steps as possible.

Have a look at my snake program, it shows how normal images are used, to do 
transparent images just use the other type of func calls.
=====================================================
.______<-------------------\__
/ _____<--------------------__|===
||_    <-------------------/
\__| Mr Trick


>From: Stewart MacKenzie-Leigh <stewartml89 at msn.com>
>Reply-To: EUforum at topica.com
>To: EUforum at topica.com
>Subject: Masking
>Date: Sat, 08 Nov 2003 19:30:28 +0000
>
>
>Is there a fster way to display a bitmap on the screen without the pixels 
>which are the mask color, other than plotting each color individually in a 
>loop?
>
>this is the code im using at the moment:
>
>for y = 1 to length(img) do
>    for x = 1 to length(img[y]) do
>        if img[y][x] != MASK_COLOR then
>            pixel(img[y][x], {imgX + x, imgY + y})
>        end if
>    end if
>end for
>
>this is too slow for what i am doing.
>
>
>thanks in advance
>
>StewartML
>
>
>
>TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

8. Re: Masking

This is a multi-part message in MIME format.

------=_NextPart_000_1779_390f_3eff




------=_NextPart_000_1779_390f_3eff

new topic     » goto parent     » topic index » view message » categorize

9. Re: Masking

img_mask = -(img = 0)

and_bits(background, img_mask)
or_bits(background, img)

        Lucius L. Hilley III - Unkmar

----- Original Message ----- 
From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
To: <EUforum at topica.com>
Sent: Sunday, November 09, 2003 07:26 AM
Subject: RE: Masking


>
>
> maybe i could get it to run even faster if i did both tasks at once...
>
> i need to make a copy of the pixels from the location on the screen where
> the new ones are going, before puting my image onto the screen.  this is
so
> that i can put them back when im done displaying the picture.  i only want
> to copy the pixels where the non-transparent pixels of the image are
going,
> the rest i'll fill out with the transparent color.
>
> i should tell you that i am not writing directly to the screen, instead
i'm
> putting all the bitmap information into a sequence the same size as the
> screen, then displaying that on the screen  -  it reduces flicker.
>
> at the moment, it works.  it just runs like shit through a seive.  please
> help :)
>
> thanks in advance.
> _________________
>
> StewartML
>

new topic     » goto parent     » topic index » view message » categorize

10. Re: Masking

The and or method I gave you is better.
but I give you this as an alternative.
--
I also give you the ofind version.  Ask me for ofind if you
don't know where to find it.

--
include ofind.e

integer s, e
sequence img_mask

img_mask = (img = MASK_COLOR)
for y = 1 to length(img) do
    s = ofind(0, img_mask[y], 1) -- Find pixel that starts visable area
    while (s) do
      e = ofind(0, img_mask[y], s+1)
      if (e = 0) then
            e = length(img_mask)
      end if
      pixel(img[y][s..e], {imgX + s, imgY + y})

      s = ofind(0, img_mask[y], e+1)
    end while
end for


-- Plain
integer s, e
img_mask = (img = MASK_COLOR)
for y = 1 to length(img) do
    s = find(0, img_mask[y]) -- Find pixel that starts visable area
    while (s) do
       -- the follwing crap is why I created ofind.
      e = find(0, img_mask[y][s+1..length(img_mask[y]])
      if (e) then
            e += s
      else
            e = length(img_mask)
      end if
      pixel(img[y][s..e], {imgX + s, imgY + y})

      s = find(0, img_mask[y][e+1..length(img_mask[y]])
      if (s) then
            s += e
      end if
    end while
end for


        Lucius L. Hilley III

----- Original Message ----- 
From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
To: <EUforum at topica.com>
Sent: Saturday, November 08, 2003 02:30 PM
Subject: Masking


>
>
> Is there a fster way to display a bitmap on the screen without the pixels
> which are the mask color, other than plotting each color individually in a
> loop?
>
> this is the code im using at the moment:
>
> for y = 1 to length(img) do
>     for x = 1 to length(img[y]) do
>         if img[y][x] != MASK_COLOR then
>             pixel(img[y][x], {imgX + x, imgY + y})
>         end if
>     end if
> end for
>
> this is too slow for what i am doing.
>
>
> thanks in advance
>
> StewartML
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

11. Re: Masking

This has been tested

--
include ofind.e
procedure display_image2(sequence xy, sequence img)
  integer x, y, s, e, li
  sequence img_mask

  x = xy[1]
  y = xy[2]
  img_mask = (img = 0)
  position(2, 1)
  for Y = 1 to length(img) do
    li = length(img_mask[Y])
    e = 0
    s = find(0, img_mask[Y])
    while (s) and (li > e) do
      e = ofind(1, img_mask[Y] , s+1)
      if (e) then
        e -= 1
      else
        e = li
      end if
      pixel(img[Y][s..e], {x+s, Y+y})

      s = ofind(0, img_mask[Y], e+1)
    end while
  end for
end procedure

        Lucius L. Hilley III - Unkmar

----- Original Message ----- 
From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
To: <EUforum at topica.com>
Sent: Saturday, November 08, 2003 02:30 PM
Subject: Masking


>
>
> Is there a fster way to display a bitmap on the screen without the pixels
> which are the mask color, other than plotting each color individually in a
> loop?
>
> this is the code im using at the moment:
>
> for y = 1 to length(img) do
>     for x = 1 to length(img[y]) do
>         if img[y][x] != MASK_COLOR then
>             pixel(img[y][x], {imgX + x, imgY + y})
>         end if
>     end if
> end for
>
> this is too slow for what i am doing.
>
>
> thanks in advance
>
> StewartML
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu