Example #1
0
        private static Filter GetDemosaic(DcRawState state, int quality)
        {
            Filter demosaic;

            if (state.filters != 0 && state.document_mode == 0)
            {
                if (quality == 0)
                {
                    demosaic = new Bilinear(state);
                }
                else if (quality == 1 || state.colors > 3)
                {
                    Demosaic.PreInterpolate(state);
                    throw new NotImplementedException();
                    //vng_interpolate();
                }
                else if (quality == 2)
                {
                    Demosaic.PreInterpolate(state);
                    throw new NotImplementedException();
                    //ppg_interpolate();
                }
                else
                {
                    demosaic = new AHD(state);
                }
            }
            else
            {
                demosaic = new BasicDemosiac(state);
            }

            return(demosaic);
        }
Example #2
0
        public static void DoStuff(string filename, DcRawState state, Settings settings)
        {
            try
            {
                DoStuff_internal(filename, state, settings);
            }
            finally
            {
                Profiler.DumpStats();
            }

            //ShowPicture(state);
        }
Example #3
0
        public static byte[] gamma_lut(DcRawState state)
        {
            int perc = (int)(state.width * state.height * 0.01);                /* 99th percentile white level */

            if (state.fuji_width != 0)
            {
                perc /= 2;
            }
            if (((state.highlight & ~2) != 0) || state.no_auto_bright != 0)
            {
                perc = -1;
            }
            float white = 0;

            for (int c = 0; c < state.colors; c++)
            {
                int total = 0;
                int val;
                for (val = 0x2000; --val > 32;)
                {
                    if ((total += state.histogram[c, val]) > perc)
                    {
                        break;
                    }
                }
                if (white < val)
                {
                    white = val;
                }
            }
            white *= 8 / state.bright;
            byte[] lut = new byte[0x10000];
            for (int i = 0; i < 0x10000; i++)
            {
                float r   = i / white;
                int   val = (int)(256 * (state.use_gamma == 0 ? r :
                                         //#ifdef SRGB_GAMMA
                                         //	        r <= 0.00304 ? r*12.92 : pow(r,2.5/6)*1.055-0.055 );
                                         //#else
                                         r <= 0.018 ? r * 4.5 : Math.Pow(r, 0.45f) * 1.099 - 0.099));
                //#endif
                if (val > 255)
                {
                    val = 255;
                }
                lut[i] = (byte)val;
            }
            return(lut);
        }
Example #4
0
 public hasselblad_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #5
0
        string artist; // 64 bytes;

        public TiffHeader(DcRawState state, bool full)
        {
            order       = (ushort)(Utils.htonl(0x4d4d4949) >> 16);
            offset_ntag = 2 + 2 + 4 + 2;
            int offset_nextifd = offset_ntag + 2 + 2 + (2 + 2 + 4 + 4) * 23;
            int offset_nexif   = offset_nextifd + 4;
            int offset_ngps    = offset_nexif + 2 + 2 + (2 + 2 + 4 + 4) * 4;
            int offset_bps     = offset_ngps + 2 + 2 + (2 + 2 + 4 + 4) * 10;

            offset_bps -= 2; // HACK - why do we need this?
            int offset_rat    = offset_bps + 4 * 2;
            int offset_gps    = offset_rat + 10 * 4;
            int offset_desc   = offset_gps + 26 * 4;
            int offset_make   = offset_desc + 512;
            int offset_model  = offset_make + 64;
            int offset_soft   = offset_model + 64;
            int offset_date   = offset_soft + 32;
            int offset_artist = offset_date + 20;
            int TH_SIZE       = offset_artist + 64;

            // Tags
            if (full)
            {
                tags.Add(new TiffTag(254, 4, 1, 0));
                tags.Add(new TiffTag(256, 4, 1, state.width));
                tags.Add(new TiffTag(257, 4, 1, state.height));
                tags.Add(new TiffTag(258, 3, state.colors,
                                     (state.colors > 2) ? offset_bps : state.output_bps));
                for (int c = 0; c < 4; c++)
                {
                    bps[c] = (short)state.output_bps;
                }
                tags.Add(new TiffTag(259, 3, 1, 1));
                tags.Add(new TiffTag(262, 3, 1, 1 + (state.colors > 1 ? 1 : 0)));
            }

            uint psize = 0;


            tags.Add(new TiffTag(270, 2, 512, offset_desc));
            tags.Add(new TiffTag(271, 2, 64, offset_make));
            tags.Add(new TiffTag(272, 2, 64, offset_model));
            if (full)
            {
                if (state.oprof != null)
                {
                    psize = Utils.htonl(state.oprof[0]);
                }
                tags.Add(new TiffTag(273, 4, 1, (int)(TH_SIZE + psize)));
                tags.Add(new TiffTag(277, 3, 1, state.colors));
                tags.Add(new TiffTag(278, 4, 1, state.height));
                tags.Add(new TiffTag(279, 4, 1, state.height * state.width * state.colors * state.output_bps / 8));
            }
            else
            {
                tags.Add(new TiffTag(274, 3, 1, "12435867"[state.flip] - '0'));
            }
            tags.Add(new TiffTag(282, 5, 1, offset_rat));
            tags.Add(new TiffTag(283, 5, 1, offset_rat + (4 * 2)));
            tags.Add(new TiffTag(284, 3, 1, 1));
            tags.Add(new TiffTag(296, 3, 1, 2));
            tags.Add(new TiffTag(305, 2, 32, offset_soft));
            tags.Add(new TiffTag(306, 2, 20, offset_date));
            tags.Add(new TiffTag(315, 2, 64, offset_artist));
            tags.Add(new TiffTag(34665, 4, 1, offset_nexif));
            if (psize > 0)
            {
                tags.Add(new TiffTag(34675, 7, (int)psize, (int)TH_SIZE));
            }

            exif.Add(new TiffTag(33434, 5, 1, offset_rat + 4 * 4));
            exif.Add(new TiffTag(33437, 5, 1, offset_rat + 6 * 4));
            exif.Add(new TiffTag(34855, 3, 1, (int)state.iso_speed));
            exif.Add(new TiffTag(37386, 5, 1, offset_rat + 8 * 4));

            /*if (state.gpsdata[1])
             * {
             *      tiff_set (&th->ntag, 34853, 4, 1, TOFF(th->ngps));
             *      tiff_set (&th->ngps,  0, 1,  4, 0x202);
             *      tiff_set (&th->ngps,  1, 2,  2, state.gpsdata[29]);
             *      tiff_set (&th->ngps,  2, 5,  3, TOFF(th->gps[0]));
             *      tiff_set (&th->ngps,  3, 2,  2, state.gpsdata[30]);
             *      tiff_set (&th->ngps,  4, 5,  3, TOFF(th->gps[6]));
             *      tiff_set (&th->ngps,  5, 1,  1, state.gpsdata[31]);
             *      tiff_set (&th->ngps,  6, 5,  1, TOFF(th->gps[18]));
             *      tiff_set (&th->ngps,  7, 5,  3, TOFF(th->gps[12]));
             *      tiff_set (&th->ngps, 18, 2, 12, TOFF(th->gps[20]));
             *      tiff_set (&th->ngps, 29, 2, 12, TOFF(th->gps[23]));
             *      //memcpy (th->gps, gpsdata, sizeof th->gps);
             *      for (int i=0; i<26; i++) {
             *              state.gpsdata[i] = th->gps[i];
             *      }
             * }*/

            rat[0] = rat[2] = 300;
            rat[1] = rat[3] = 1;
            for (int c = 0; c < 6; c++)
            {
                rat[4 + c] = 1000000;
            }
            rat[4] = (int)(rat[4] * state.shutter);
            rat[6] = (int)(rat[6] * state.aperture);
            rat[8] = (int)(rat[8] * state.focal_len);

            desc  = state.desc;
            make  = state.make;
            model = state.model;

            DateTime ts = state.timestamp.Value;

            date = string.Format("{0:d2}:{1:d2}:{2:d2} {3:d2}:{4:d2}:{5:d2}",
                                 ts.Year, ts.Month, ts.Day, ts.Hour, ts.Minute, ts.Second);
            soft = "dcraw";
        }
Example #6
0
 public ColourSpace(DcRawState state) : base(state)
 {
 }
Example #7
0
 public imacon_full_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #8
0
 public olympus_e410_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #9
0
 protected UnImplementedRawLoader(DcRawState state) : base(state)
 {
 }
Example #10
0
 public minolta_rd175_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #11
0
 public pentax_k10_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #12
0
        public static void DoStuff_internal(string filename, DcRawState state, Settings settings)
        {
            state.inFilename = filename;

            state.ifp = new RawStream(filename);

            Identifier id = new Identifier(state);

            id.identify(state.ifp);

            // Works this far...

            if (settings.user_flip >= 0)
            {
                state.flip = settings.user_flip;
            }

            switch ((state.flip + 3600) % 360)
            {
            case 270:
                state.flip = 5;
                break;

            case 180:
                state.flip = 3;
                break;

            case 90:
                state.flip = 6;
                break;
            }

            if (settings.timestamp_only)
            {
                if (state.timestamp == null)
                {
                    Console.WriteLine("{0} has no timestamp.", filename);
                }
                else if (settings.identify_only)
                {
                    //"%10ld%10d %s"
                    Console.WriteLine("{0}{1} {2}", state.timestamp, state.shot_order, filename);
                }
                else
                {
                    if (state.verbose)
                    {
                        Console.WriteLine("{0} time set to {1}.\n", filename, state.timestamp);
                    }

                    //ut.actime = ut.modtime = state.timestamp;
                    //utime ((char*)state.ifname, &ut);
                }
                return;
            }

            // TODO: need writer
            Tiff t = new Tiff(state);

            state.write_fun = t.write_ppm_tiff;

            if (settings.thumbnail_only)
            {
                if (state.thumb_offset == 0)
                {
                    Console.WriteLine("{0} has no thumbnail.\n", filename);
                    return;
                }

                if (state.thumb_load_raw != null)
                {
                    state.load_raw    = state.thumb_load_raw;
                    state.data_offset = state.thumb_offset;
                    state.height      = state.thumb_height;
                    state.width       = state.thumb_width;
                    state.filters     = 0;
                }
                else
                {
                    state.ifp.Seek(state.thumb_offset, SeekOrigin.Begin);
                    //fseek (state.ifp, state.thumb_offset, SEEK_SET);
                    state.write_fun = state.write_thumb;
                    goto thumbnail;
                }
            }

            if (state.load_raw is kodak_ycbcr_load_raw)
            {
                state.height += state.height & 1;
                state.width  += state.width & 1;
            }

            if (settings.identify_only && state.verbose && state.make != null)
            {
                Console.WriteLine("Filename: {0}", filename);
                //long localtimestamp = state.timestamp;
                //Console.WriteLine("Timestamp: %s", ctime(&localtimestamp));
                Console.WriteLine("Camera: {0} {1}", state.make, state.model);
                if (state.artist != null)
                {
                    Console.WriteLine("Owner: {0}", state.artist);
                }
                if (state.dng_version != 0)
                {
                    Console.Write("DNG Version: ");
                    for (int i = 24; i >= 0; i -= 8)
                    {
                        Console.WriteLine("{0}{1}", state.dng_version >> i & 255, i != 0 ? '.' : '\n');
                    }
                }
                Console.WriteLine("ISO speed: {0}", (int)state.iso_speed);
                Console.Write("Shutter: ");
                if (state.shutter > 0 && state.shutter < 1)
                {
                    Console.Write("1/");
                    state.shutter = 1 / state.shutter;
                }
                Console.WriteLine("{0} sec", state.shutter);
                Console.WriteLine("Aperture: f/{0}", state.aperture);
                Console.WriteLine("Focal length: {0} mm", state.focal_len);
                Console.WriteLine("Embedded ICC profile: {0}", state.profile_length != 0 ? "yes" : "no");
                Console.WriteLine("Number of raw images: {0}", state.is_raw);
                if (state.pixel_aspect != 1)
                {
                    Console.WriteLine("Pixel Aspect Ratio: {0}", state.pixel_aspect);
                }
                if (state.thumb_offset != 0)
                {
                    Console.WriteLine("Thumb size:  {0} x {1}", state.thumb_width, state.thumb_height);
                }
                Console.WriteLine("Full size:   {0} x {1}", state.raw_width, state.raw_height);
            }
            else if (state.is_raw == 0)
            {
                Console.WriteLine("Cannot decode file {0}", filename);
            }

            if (state.is_raw == 0)
            {
                return;
            }

            state.shrink = (state.filters != 0 &&
                            (state.half_size || state.threshold != 0 || state.aber[0] != 1 || state.aber[2] != 1))
                               ? (ushort)1
                               : (ushort)0;
            state.iheight = (state.height + state.shrink) >> state.shrink;
            state.iwidth  = (state.width + state.shrink) >> state.shrink;
            if (settings.identify_only)
            {
                if (state.verbose)
                {
                    if (settings.use_fuji_rotate)
                    {
                        if (state.fuji_width != 0)
                        {
                            state.fuji_width = (state.fuji_width - 1 + state.shrink) >> state.shrink;
                            state.iwidth     = (int)(state.fuji_width / Math.Sqrt(0.5));
                            state.iheight    = (int)((state.iheight - state.fuji_width) / Math.Sqrt(0.5));
                        }
                        else
                        {
                            if (state.pixel_aspect < 1)
                            {
                                state.iheight = (int)(state.iheight / state.pixel_aspect + 0.5f);
                            }
                            if (state.pixel_aspect > 1)
                            {
                                state.iwidth = (int)(state.iwidth * state.pixel_aspect + 0.5f);
                            }
                        }
                    }
                    if ((state.flip & 4) != 0)
                    {
                        int temp = state.iheight;
                        state.iheight = state.iwidth;
                        state.iwidth  = temp;
                    }
                    Console.WriteLine("Image size:  {0} x {1}", state.width, state.height);
                    Console.WriteLine("Output size: {0} x {1}", state.iwidth, state.iheight);
                    Console.WriteLine("Raw colors: {0}", state.colors);
                    if (state.filters != 0)
                    {
                        Console.WriteLine("\nFilter pattern: ");
                        //if (!state.cdesc[3]) state.cdesc[3] = 'G';
                        for (int i = 0; i < 16; i++)
                        {
                            //Console.Write(state.cdesc[state.fc(i >> 1, i & 1)]);
                        }
                    }
                    Console.Write("\nDaylight multipliers:");
                    for (int c = 0; c < state.colors; c++)
                    {
                        Console.Write(" {0}", state.pre_mul[c]);
                    }

                    if (state.cam_mul[0] > 0)
                    {
                        Console.Write("\nCamera multipliers:");
                        for (int c = 0; c < 4; c++)
                        {
                            Console.Write(" {0}", state.cam_mul[c]);
                        }
                    }
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("{0} is a {1} {2} image.\n", filename, state.make, state.model);
                }

                state.ifp.Close();
                return;
            }

            if (state.use_camera_matrix && state.cmatrix[0, 0] > 0.25)
            {
                Array.Copy(state.cmatrix, state.rgb_cam, state.cmatrix.Length);
            }

            //memcpy (rgb_cam, cmatrix, sizeof cmatrix);
            state.raw_color = false;

            state.image = new ushort[state.iheight * state.iwidth * 4];

            //SetImage((ushort (*)[4]) state.Alloc (state.iheight * state.iwidth * sizeof *IMAGE));

            // TODO: implement metadata support if we need foveon support

            /*
             *          if (state.meta_length != 0) {
             *              AllocMetadata(state);
             *                  //state.meta_data = (signed char *) state.Alloc (state.meta_length);
             *                  //merror (state.meta_data, "main()");
             *          }
             */
            if (state.verbose)
            {
                Console.WriteLine("Loading {0} {1} image from {2} ...", state.make, state.model, filename);
            }
            if (state.shot_select >= state.is_raw)
            {
                Console.WriteLine("{0}: \"-s {1}\" requests a nonexistent image!", filename, state.shot_select);
            }

            state.ifp.Seek(state.data_offset, SeekOrigin.Begin);

            using (Profiler.BlockProfile("Loader: " + state.load_raw.GetType()))
            {
                state.load_raw.LoadRaw();
            }

            //System::Console::WriteLine("load_raw()  -  {0}", load_raw.Method);

            //load_raw();


#if false
            // TODO
            if (state.zero_is_bad)
            {
                remove_zeroes();
            }
#endif

#if false
            // TODO
            bad_pixels(bpfile);
#endif

#if false
            // TODO
            if (dark_frame)
            {
                subtract(dark_frame);
            }
#endif

            int quality = 2 + (state.fuji_width == 0 ? 1 : 0);
            if (settings.user_qual >= 0)
            {
                quality = settings.user_qual;
            }

            if (settings.user_black >= 0)
            {
                state.black = (uint)settings.user_black;
            }

            if (settings.user_sat > 0)
            {
                state.maximum = (uint)settings.user_sat;
            }

//#ifdef COLORCHECK
            //colorcheck();
            //#endif


#if false
            // TODO
            if (state.is_foveon && !state.document_mode)
            {
                foveon_interpolate();
            }
#endif
            IList <Filter> filters = GetFilters(state, settings, quality);

            foreach (Filter f in filters)
            {
                using (Profiler.BlockProfile("Filter: " + f))
                {
                    f.Process();
                }
            }

thumbnail:

            string write_ext;

            /*if (write_fun == gcnew WriteDelegate(&CLASS jpeg_thumb)) {
             *                  write_ext = ".jpg";
             * } else if (state.output_tiff && write_fun == gcnew WriteDelegate(&CLASS write_ppm_tiff)) {*/
            write_ext = ".tiff";

            /*} else {
             *                  write_ext = (char*)".pgm\0.ppm\0.ppm\0.pam" + state.colors*5-5;
             * }*/

            string ofname = state.inFilename;
            ofname = Path.ChangeExtension(ofname, write_ext);

            /*if (state.multi_out)
             *                  sprintf (ofname+strlen(ofname), "_%0*d",
             *                  snprintf(0,0,"%d",state.is_raw-1), state.shot_select);
             *          if (thumbnail_only) ofname += ".thumb";*/

            Stream ofp = File.OpenWrite(ofname);
            if (state.verbose)
            {
                Console.WriteLine("Writing data to {0} ...\n", ofname);
            }
            using (Profiler.BlockProfile("Writer: " + state.write_fun.Method.ReflectedType + "." + state.write_fun.Method.Name))
            {
                state.write_fun(ofp);
            }

            state.ifp.Close();
            ofp.Close();
        }
Example #13
0
 public GreenMixer(DcRawState state) : base(state)
 {
 }
Example #14
0
        private static IList <Filter> GetFilters(DcRawState state, Settings settings, int quality)
        {
            IList <Filter> filters = new List <Filter>();

            if (!state.is_foveon && state.document_mode < 2)
            {
                //scale_colors();
                Filter colourScaler = new ColourScaler(state);
                filters.Add(colourScaler);
                //colourScaler.Process();
            }

            // Select demosaicing filter
            Filter demosaic = GetDemosaic(state, quality);

            filters.Add(demosaic);
            //demosaic.Process();

            if (state.mix_green)
            {
                Filter greenMixer = new GreenMixer(state);
                filters.Add(greenMixer);
                //greenMixer.Process();
            }

            if (!state.is_foveon && state.colors == 3)
            {
                //median_filter();
                Filter medianFilter = new Median(state);
                filters.Add(medianFilter);
                //medianFilter.Process();
            }

            if (!state.is_foveon && state.highlight == 2)
            {
                throw new NotImplementedException();
                //blend_highlights();
            }

            if (!state.is_foveon && state.highlight > 2)
            {
                throw new NotImplementedException();
                //recover_highlights();
            }

            if (settings.use_fuji_rotate && state.fuji_width != 0)
            {
                throw new NotImplementedException();
                //fuji_rotate();
            }

//#ifndef NO_LCMS
            //if (cam_profile) apply_profile (cam_profile, out_profile);
            //#endif

            Filter colourSpace = new ColourSpace(state);

            filters.Add(colourSpace);
            //colourSpace.Process();
            //convert_to_rgb();

            if (settings.use_fuji_rotate && state.pixel_aspect != 1)
            {
                throw new NotImplementedException();
                //stretch();
            }
            return(filters);
        }
Example #15
0
 public Tiff(DcRawState state)
 {
     this.state = state;
 }
Example #16
0
 public panasonic_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #17
0
 public eight_bit_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #18
0
 public sony_arw2_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #19
0
 public nokia_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #20
0
 public phase_one_load_raw_c(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #21
0
 public adobe_dng_load_raw_nc(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #22
0
 public casio_qv5700_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #23
0
 public sinar_4shot_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #24
0
 public quicktake_100_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #25
0
 public kodak_rgb_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #26
0
 public canon_compressed_load_raw(DcRawState state)
     : base(state)
 {
     throw new NotImplementedException();
 }
Example #27
0
 public ColourScaler(DcRawState state) : base(state)
 {
 }
Example #28
0
 protected RawLoader(DcRawState state)
 {
     this.state = state;
 }