예제 #1
0
 public RawImage(DcRawState state)
 {
     image      = state.image;
     width      = state.width;
     height     = state.height;
     colours    = state.colors;
     topMargin  = state.top_margin;
     leftMargin = state.left_margin;
 }
예제 #2
0
        private static DateTime?GetRC2PhotoDate(string path)
        {
            DcRawState state = new DcRawState();

            state.inFilename = path;
            state.ifp        = new RawStream(path);

            Identifier id = new Identifier(state);

            id.identify(state.ifp);
            return(state.timestamp.HasValue ? state.timestamp.Value : LastWriteTime(path));
        }
예제 #3
0
        private static void Shrink(DcRawState state)
        {
            ushort[] img = new ushort[state.height * state.width * 4];
            for (int row = 0; row < state.height; row++)
            {
                for (int col = 0; col < state.width; col++)
                {
                    int c = fc(state, row, col);
                    img[(row * state.width + col) * 4 + c] = state.image[((row >> 1) * state.iwidth + (col >> 1)) * 4 + c];
                }
            }

            state.image  = img;
            state.shrink = 0;
        }
예제 #4
0
        public static void PreInterpolate(DcRawState state)
        {
            if (state.shrink != 0)
            {
                if (state.half_size)
                {
                    state.height = state.iheight;
                    state.width  = state.iwidth;
                }
                else
                {
                    Shrink(state);
                }
            }

            if (state.filters != 0 && state.colors == 3)
            {
                state.mix_green = state.four_color_rgb;
                if (state.mix_green)
                {
                    state.colors++;
                }
                else
                {
                    for (int row = state.FC(1, 0) >> 1; row < state.height; row += 2)
                    {
                        for (int col = state.FC(row, 1) & 1; col < state.width; col += 2)
                        {
                            state.image[(row * state.width + col) * 4 + 1] = state.image[(row * state.width + col) * 4 + 3];
                        }
                    }

                    state.filters &= ~((state.filters & 0x55555555) << 1);
                }
            }

            if (state.half_size)
            {
                state.filters = 0;
            }
        }
예제 #5
0
 public AHD(DcRawState state)
     : base(state)
 {
 }
예제 #6
0
 public Packed12Loader(DcRawState state) : base(state)
 {
 }
예제 #7
0
        };                                                                                                                             /* 14-bit lossless */

        public NikonCompressedLoader(DcRawState state) : base(state)
        {
        }
예제 #8
0
 protected Demosaic(DcRawState state) : base(state)
 {
 }
예제 #9
0
 public BasicDemosiac(DcRawState state) : base(state)
 {
 }
예제 #10
0
 public LosslessJpegLoader(DcRawState state)
     : base(state)
 {
 }
예제 #11
0
 public Bilinear(DcRawState state) : base(state)
 {
 }
예제 #12
0
 protected LJpegBase(DcRawState state) : base(state)
 {
 }
예제 #13
0
 public Median(DcRawState state) : base(state)
 {
 }
예제 #14
0
        public override void Parse(Stream s)
        {
            DcRawState state = new DcRawState();

            state.inFilename = "";
            state.ifp        = new RawStream(s);

            Identifier id = new Identifier(state);

            id.identify(state.ifp);

            // Works this far...

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

            case 180:
                state.flip = 3;
                break;

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

            /*
             * // TODO: need writer
             * Tiff t = new Tiff(state);
             * state.write_fun = t.write_ppm_tiff;*/

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


            if (state.is_raw == 0)
            {
                throw new FormatException("File not supported");
            }

            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 (state.use_camera_matrix && state.cmatrix[0, 0] > 0.25)
            {
                Array.Copy(state.cmatrix, state.rgb_cam, state.cmatrix.Length);
            }
            state.raw_color = true;

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

            if (state.shot_select >= state.is_raw)
            {
                throw new FormatException("File name incorrect");
            }

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

            state.load_raw.LoadRaw();
            height     = (uint)state.raw_height;
            width      = (uint)state.raw_width;
            colorDepth = (ushort)state.output_bps;
            cfa        = null;
            camMul     = new double[] { 1, 1, 1, 1 };
            black      = new double[4];
            curve      = null;
        }
예제 #15
0
        public JHead(DcRawState state, RawStream s, bool info_only, uint dng_version)
        {
            byte[] data = new byte[0x10000];

            restart = int.MaxValue;

            s.Read(data, 0, 2);

            if (data[1] != 0xd8)
            {
                // Error state (I think)
                throw new Exception("unexpected value in jpeg header");
                //return 0;
            }

            int tag;
            int len;

            do
            {
                s.Read(data, 0, 2 * 2);
                tag = data[0] << 8 | data[1];
                len = (data[2] << 8 | data[3]) - 2;
                if (tag <= 0xff00)
                {
                    // Non error
                    return;
                }

                s.Read(data, 0, len);
                switch (tag)
                {
                case 0xffc0:        // SOF0 - Start of Frame 0 - Baseline DCT
                case 0xffc3:        // SOF3 - Start of Frame 3 - Lossless (sequential)
                    if (tag == 0xffc3)
                    {
                        sraw = ((((data[7] >> 4) * (data[7] & 15) - 1) & 3) == 0) ? false : true;
                    }
                    bits = data[0];
                    high = data[1] << 8 | data[2];
                    wide = data[3] << 8 | data[4];
                    clrs = data[5] - (sraw ? 1 : 0);
                    if (len == 9 && dng_version == 0)
                    {
                        s.ReadByte();
                    }
                    break;

                case 0xffc4:        // DHT - Define Huffman Table
                    if (info_only)
                    {
                        break;
                    }

                    for (int dpi = 0; dpi < len && data[dpi] < 4;)
                    {
                        int idx = data[dpi];
                        dpi++;
                        huff[idx] = new HuffmanTree(data, ref dpi);
                    }
                    break;

                case 0xffda:        // SOS - Start of Scan
                    psv   = data[1 + data[0] * 2];
                    bits -= data[3 + data[0] * 2] & 15;
                    break;

                case 0xffdd:        // DRI - Define Restart Interval
                    restart = data[0] << 8 | data[1];
                    break;

                // <-- end of dcraw.c ported code (for this switch statement) -->

                // thumbnail image
                // for more unhandled tags, see: http://www.impulseadventure.com/photo/jpeg-decoder.html
                case 0xffd8:        // SOI - Start of Image
                case 0xffd9:        // EOI - End of Image
                case 0xffdb:        // DQT - Define Quantization Table
                    break;

                default:
                    Console.WriteLine("Unhandled jpeg tag: {0}", tag);
                    break;
                }
            } while (tag != 0xffda);

            if (info_only)
            {
                // No error
                //return 1;
                return;
            }

            if (sraw)
            {
                huff[3] = huff[2] = huff[1];
                huff[1] = huff[0];
            }

            row = new ushort[wide * clrs * 2];

            /*
             * for (int iii = 0; iii < huff.Length; iii++)
             * {
             *  Console.WriteLine("huff[{0}]", iii);
             *  Decode.DumpTable(huff[iii], 0);
             * }
             */

            //row = (ushort*) calloc(wide * clrs, 4);
            //merror(jh->row, "ljpeg_start()");
            // TODO: why do we need error handling here?
            s.ZeroAfterFF = true;
        }
예제 #16
0
 protected Filter(DcRawState state)
 {
     this.state = state;
 }
예제 #17
0
 private static int fc(DcRawState state, int row, int col)
 {
     return(state.filters != 1 ? state.FC(row, col) : filter[(row + state.top_margin) & 15, (col + state.left_margin) & 15]);
 }
예제 #18
0
 public AdobeDngLoader(DcRawState state) : base(state)
 {
 }