[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Dvipng] accessing alpha channel
From: |
Bob McElrath |
Subject: |
Re: [Dvipng] accessing alpha channel |
Date: |
Wed, 18 May 2005 11:25:53 -0700 |
User-agent: |
Mutt/1.5.6+20040523i |
I use the following sequence of commands using python's Imaging library:
im = Image.open(os.path.join(workingDir, imname))
im2 = Image.new('RGBA', (im.size[0], im.size[1]), (255,255,255))
im2.paste(im, (0, 0))
To explicitly create an alpha channel I use:
alpha = ImageChops.invert(im.convert('L'))
im = im.putalpha(alpha)
This creates a PNG with a proper alpha channel. I would VERY much like
it if dvipng did this for me. I would love it if you could hack it in
to dvipng.
The code is in latexwiki http://mcelrath.org/Notes/LatexWiki in case I
have omitted some important step in the above code.
John Hunter address@hidden wrote:
>
> I would like to overlay dvipng rasters over an arbitrary background,
> not just a solid color. My first thought was that one could extract
> an alpha mask from the dvipng output by having dvipng blend black and
> white and working out what the alpha at each pixel must have been
> using the formula (I'm using the red channel but values are the same
> for blue and green). First I run dvipng with
>
> dvipng -bg Transparent -fg 'rgb 0.0 0.0 0.0' -D 100 -T tight -o outfile.png
> somefile.dvi
>
>
> red = alpha*red_foreground + (1-alpha)*red_background
>
>
> Since the foreground is black (0) and the background is white (1) this
> reduces to red = 1-alpha or
>
> alpha = 1-red
>
>
> This gives be an MxN arrays of an alpha mask, and I then blend the
> dvipng raster over an arbitrary background.
>
> The problem is that the small rasters blended this way don't come out
> as nicely as the ones rendered by dvipng assuming a constant
> background. So I must be making some error in my logic. At first I
> thought I might not be handling gamma properly, but I'm using gamma=1
> so I don't have any special correction for that AFAIK. I also
> wondered if I'm using the wrong blending formula -- eg is dvipng using
> premultiplied alpha or some other formula to blend.
>
> So my questions are
>
> * would it be possible to modify dvipng to have an option to simply
> return an alpha mask so we could blend dvi rasters over arbitrary
> backgrounds?
>
> * is there a way to calculate this mask from the output of dvipng as
> it stands?
>
> Thanks!
>
> JDH
>
>
> _______________________________________________
> Dvipng mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/dvipng
--
Cheers,
Bob McElrath [Univ. of California at Davis, Department of Physics]
Censorship is never over for those who have experienced it. It is a brand
on the imagination that affects the individual who has suffered it,
forever. -- Noam Chomsky
signature.asc
Description: Digital signature