[Ffmpeg-devel] [PATCH/RFC] 1-7 and 9-15 bits per pixel PGM files

Michael Niedermayer michaelni
Sun Apr 8 13:08:25 CEST 2007


Hi

On Sun, Apr 08, 2007 at 11:44:12AM +0200, Ivo wrote:
> On Sunday 08 April 2007 00:39, Michael Niedermayer wrote:
> > On Sun, Apr 08, 2007 at 12:33:54AM +0200, Ivo wrote:
> > > On Saturday 07 April 2007 23:45, Michael Niedermayer wrote:
> > > > On Sat, Apr 07, 2007 at 11:17:43PM +0200, Ivo wrote:
> > > > >            ptr[j] = ptr[j]<<(8-s->bpp) | ptr[j]>>s->bpp;
> > > >
> > > > ptr[j]>>s->bpp == 0
> > >
> > > No, if the condition for which the code is run is true, s->bpp is
> > > always smaller than eight. Perhaps I should use a less confusing
> > > variable name,
> >
> > ptr[j] will contain s->bpp bits and you shift them away -> its 0
> > or iam stupid (which is possible too)
> 
> Ah, yes. My single line is not the same of course as your two line 
> suggestion earlier. I'll change it to ptr[j]<<=8-s->bpp; 
> ptr[j]+=ptr[j]>>s->bpp;
> 
> I thought about it a little more this time, and if I am not mistaken, this 
> won't be fully correct for bpp<4 either. 
> 
> if bpp==3: 0x07 will become 0xfc instead of 0xff
> if bpp==2: 0x03 will become 0xf0 instead of 0xff
> if bpp==1: 0x01 will become 0xc0 instead of 0xff
> 
> bpp==1 would be stupid, but it is a valid pgm file.
> 
> How about the next patch?

ugly, why are you trying so hard to avoid doing a multiplication?

with your incorrect conversation factor and rounding thats equivalent to:
7->8 (* 10000001 >> 6)
6->8 (* 01000001 >> 4)
5->8 (* 00100001 >> 2)
4->8 (* 00010001 >> 0)
3->8 (* 01001001 >> 1)
2->8 (* 01010101 >> 0)
1->8 (* 11111111 >> 0)

correcter would be something like
int w= (1<<bpp)-1;
int factor= (255*128 + w/2) / w;
new_pix= (old_pix * factor + 64)>>7;

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070408/0f6e86c9/attachment.pgp>



More information about the ffmpeg-devel mailing list