예제 #1
0
        static bool TIFFDefaultRefBlackWhite(TIFFDirectory td)
        {
            if(td.td_photometric==PHOTOMETRIC.YCBCR)
            {
                // YCbCr (Class Y) images must have the
                // ReferenceBlackWhite tag set. Fix the
                // broken images, which lacks that tag.
                try
                {
                    td.td_refblackwhite=new double[] { 0.0, 255.0, 128.0, 255.0, 128.0, 255.0 };
                }
                catch
                {
                    return false;
                }
            }
            else
            {
                try
                {
                    td.td_refblackwhite=new double[6];
                }
                catch
                {
                    return false;
                }

                // Assume RGB (Class R)
                for(int i=0; i<3; i++)
                {
                    td.td_refblackwhite[2*i+0]=0.0;
                    td.td_refblackwhite[2*i+1]=(double)((1<<td.td_bitspersample)-1);
                }
            }

            return true;
        }
예제 #2
0
        static bool TIFFDefaultTransferFunction(TIFFDirectory td)
        {
            ushort[][] tf=td.td_transferfunction;

            tf[0]=tf[1]=tf[2]=null;
            if(td.td_bitspersample>=4*8-2) return false; //4: sizeof(tsize_t)

            int n=1<<td.td_bitspersample;
            try
            {
                tf[0]=new ushort[n];

                tf[0][0]=0;
                for(int i=1; i<n; i++)
                {
                    double t=(double)i/((double)n-1.0);
                    tf[0][i]=(ushort)Math.Floor(65535*Math.Pow(t, 2.2)+0.5);
                }

                if(td.td_samplesperpixel-td.td_extrasamples>1)
                {
                    tf[1]=new ushort[n];
                    tf[2]=new ushort[n];
                    tf[0].CopyTo(tf[1], 0);
                    tf[0].CopyTo(tf[2], 0);
                }

                return true;
            }
            catch
            {
                tf[0]=tf[1]=tf[2]=null;
                return false;
            }
        }
예제 #3
0
        // Install extra samples information.
        static bool setExtraSamples(TIFFDirectory td, object[] ap, out uint v)
        {
            v=(uint)__GetAsUint(ap, 0);

            if((ushort)v>td.td_samplesperpixel) return false;

            Array a=ap[1] as Array;
            if(v>1&&a==null) return false;		// typically missing param

            if(a==null&&v==1)
            {
                if(!(ap[1] is ushort)) // typically wrong param type, maybe EXTRASAMPLE[]
                {
                    if(!(ap[1] is EXTRASAMPLE)) return false;

                    EXTRASAMPLE va=(EXTRASAMPLE)ap[1];
                    ushort[] tmp=new ushort[1];

                    if(va>EXTRASAMPLE.UNASSALPHA)
                    {
                        // XXX: Corel Draw is known to produce incorrect
                        // ExtraSamples tags which must be patched here if we
                        // want to be able to open some of the damaged TIFF
                        // files:
                        if((int)va==999) va=EXTRASAMPLE.UNASSALPHA;
                        else return false;
                    }
                    tmp[0]=(ushort)va;

                    td.td_extrasamples=(ushort)v;
                    TIFFsetShortArray(ref td.td_sampleinfo, tmp, td.td_extrasamples);
                }
                else
                {
                    ushort[] va=new ushort[1];

                    va[0]=(ushort)ap[1];

                    if(va[0]>(ushort)EXTRASAMPLE.UNASSALPHA)
                    {
                        // XXX: Corel Draw is known to produce incorrect
                        // ExtraSamples tags which must be patched here if we
                        // want to be able to open some of the damaged TIFF
                        // files:
                        if(va[0]==999) va[0]=(ushort)EXTRASAMPLE.UNASSALPHA;
                        else return false;
                    }

                    td.td_extrasamples=(ushort)v;
                    TIFFsetShortArray(ref td.td_sampleinfo, va, td.td_extrasamples);
                }
            }
            else
            {
                if(!(a is ushort[])) // typically wrong param type, maybe EXTRASAMPLE[]
                {
                    if(!(a is EXTRASAMPLE[])) return false;

                    EXTRASAMPLE[] va=(EXTRASAMPLE[])a;
                    ushort[] tmp=new ushort[v];

                    for(int i=0; i<v; i++)
                    {
                        if(va[i]>EXTRASAMPLE.UNASSALPHA)
                        {
                            // XXX: Corel Draw is known to produce incorrect
                            // ExtraSamples tags which must be patched here if we
                            // want to be able to open some of the damaged TIFF
                            // files:
                            if((int)va[i]==999) va[i]=EXTRASAMPLE.UNASSALPHA;
                            else return false;
                        }
                        tmp[i]=(ushort)va[i];
                    }

                    td.td_extrasamples=(ushort)v;
                    TIFFsetShortArray(ref td.td_sampleinfo, tmp, td.td_extrasamples);
                }
                else
                {
                    ushort[] va=(ushort[])a;

                    for(int i=0; i<v; i++)
                    {
                        if(va[i]>(ushort)EXTRASAMPLE.UNASSALPHA)
                        {
                            // XXX: Corel Draw is known to produce incorrect
                            // ExtraSamples tags which must be patched here if we
                            // want to be able to open some of the damaged TIFF
                            // files:
                            if(va[i]==999) va[i]=(ushort)EXTRASAMPLE.UNASSALPHA;
                            else return false;
                        }
                    }

                    td.td_extrasamples=(ushort)v;
                    TIFFsetShortArray(ref td.td_sampleinfo, va, td.td_extrasamples);
                }
            }

            return true;
        }