Esempio n. 1
0
        private void reassemble(byte[][] past, byte[][] diff, byte[][] vectors)
        {
            Chunker c = new Chunker(chunkSize, state.channelWidth, state.channelHeight, state.channelWidth, 1);
            int     pixelTL;

            for (int i = 0; i < c.getNumChunks(); i++)
            {
                pixelTL = c.chunkIndexToPixelIndex(i);

                //update channels to be difference.
                restoreChunk(state.channels[0], past[0], diff[0], vectors[0][i], pixelTL, state.channelWidth);
            }

            //Do the second two channels
            Size smaller = Subsample.deduceCbCrSize(state);

            c = new Chunker(chunkSize, smaller.Width, smaller.Height, smaller.Width, 1);
            for (int i = 0; i < c.getNumChunks(); i++)
            {
                pixelTL = c.chunkIndexToPixelIndex(i);

                restoreChunk(state.channels[1], past[1], diff[1], vectors[1][i], pixelTL, smaller.Width);
                restoreChunk(state.channels[2], past[2], diff[2], vectors[2][i], pixelTL, smaller.Width);
            }
        }
Esempio n. 2
0
        public virtual Bitmap view()
        {
            if (isDirty)
            {
                clean();
            }
            if (state != null && (state.type == DataBlob.Type.Image || state.bmp != null))
            {
                return(state.bmp);
            }
            if (state != null && state.type == DataBlob.Type.Channels && state.channels != null)
            {
                Size s = Subsample.deduceCbCrSize(state);

                Bitmap     bmp     = new Bitmap(state.channelWidth, state.channelHeight, PixelFormat.Format24bppRgb);
                BitmapData bmpData = bmp.LockBits(
                    new Rectangle(0, 0, bmp.Width, bmp.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadWrite,
                    bmp.PixelFormat);

                IntPtr ptr = bmpData.Scan0;
                //copy bytes
                int    nBytes    = Math.Abs(bmpData.Stride) * bmp.Height;
                byte[] rgbValues = new byte[nBytes];
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, nBytes);


                //order: B,G,R,  B,G,R,  ...
                int channelIndex   = 0;
                int counter        = 0;
                int channelIndexRB = 0;
                for (int y = 0; y < state.imageHeight; y++)
                {
                    channelIndex   = y * state.channelWidth;
                    channelIndexRB = y * s.Width;
                    counter        = y * bmpData.Stride;

                    for (int x = 0; x < state.imageWidth; x++)
                    {
                        rgbValues[counter + 2] = state.channels[0][channelIndex];
                        if (y < s.Height && x < s.Width)
                        {
                            rgbValues[counter + 1] = state.channels[1][channelIndexRB];
                            rgbValues[counter + 0] = state.channels[2][channelIndexRB];
                            channelIndexRB++;
                        }
                        counter += 3;
                        channelIndex++;
                    }
                }
                System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, nBytes);

                bmp.UnlockBits(bmpData);
                state.bmp = bmp;
                return(bmp);
            }

            //Debug.Write("View missing in " + properties["name"].getString() + "\n");
            return(null);
        }
Esempio n. 3
0
        private void readChannels(BinaryReader reader, DataBlob ch)
        {
            Chunker c = new Chunker(8, ch.channelWidth, ch.channelHeight, ch.channelWidth, 1);

            readChannel(reader, ch.channels[0], c);
            Size s = Subsample.deduceCbCrSize(ch);

            c = new Chunker(8, s.Width, s.Height, s.Width, 1);
            readChannel(reader, ch.channels[1], c);
            readChannel(reader, ch.channels[2], c);
        }
Esempio n. 4
0
        protected static void writeChannels(BinaryWriter writer, DataBlob ch)
        {
            Chunker c = new Chunker(8, ch.channelWidth, ch.channelHeight, ch.channelWidth, 1);

            writeChannel(writer, ch.channels[0], c);
            Size s = Subsample.deduceCbCrSize(ch);

            c = new Chunker(8, s.Width, s.Height, s.Width, 1);
            writeChannel(writer, ch.channels[1], c);
            writeChannel(writer, ch.channels[2], c);
        }
Esempio n. 5
0
        private void calcMoVec(byte[][] chOld, byte[][] chNew)
        {
            //for each channel
            //chunk state.channels into 8x8 blocks
            //compare each block with blocks surrounding them in the arg channels
            //over x = [-7,7] (range 15 values)
            //and  y = [-7,7] (range 15 values)


            //Do the first channel
            Chunker c = new Chunker(chunkSize, state.channelWidth, state.channelHeight, state.channelWidth, 1);
            int     pixelTL;
            byte    offset;

            //need to set vState.channelWidth and vState.channelHeight correctly, I think....
            vState.channels[0]   = new byte[c.getNumChunks()];
            vState.channelWidth  = c.getChunksWide();
            vState.channelHeight = c.getChunksHigh();

            for (int i = 0; i < c.getNumChunks(); i++)
            {
                pixelTL = c.chunkIndexToPixelIndex(i);
                //find best match given search area
                offset = findOffsetVector(chNew[0], chOld[0], pixelTL, state.channelWidth);
                //save best match vector
                vState.channels[0][i] = offset;
                //update channels to be difference.
                if (i == 20)
                {
                    i = 20;
                }
                setDiff(state.channels[0], chNew[0], chOld[0], pixelTL, offset, state.channelWidth);
            }

            //Do the second two channels
            Size smaller = Subsample.deduceCbCrSize(state);

            c = new Chunker(chunkSize, smaller.Width, smaller.Height, smaller.Width, 1);
            vState.channels[1] = new byte[c.getNumChunks()];
            vState.channels[2] = new byte[c.getNumChunks()];
            for (int i = 0; i < c.getNumChunks(); i++)
            {
                pixelTL = c.chunkIndexToPixelIndex(i);
                offset  = findOffsetVector(chNew[1], chOld[1], pixelTL, smaller.Width);
                vState.channels[1][i] = offset;
                setDiff(state.channels[1], chNew[1], chOld[1], pixelTL, offset, smaller.Width);
                //offset = findOffsetVector(state.channels[2], channels[2], pixelTL, state.channelWidth);
                //Just use the same vectors for channel 3 as channel 2. Probably okay.
                vState.channels[2][i] = offset;
                setDiff(state.channels[2], chNew[2], chOld[2], pixelTL, offset, smaller.Width);
            }
        }
Esempio n. 6
0
        private void padChannels()
        {
            //pad the size
            Size ySize     = new Size(state.channelWidth, state.channelHeight);
            Size brOldSize = Subsample.deduceCbCrSize(state);
            Size brNewSize = Subsample.getPaddedCbCrSize(ySize, state.samplingMode);

            if (ySize.Width % 8 != 0)
            {
                ySize.Width += 8 - (ySize.Width % 8);
            }
            if (ySize.Height % 8 != 0)
            {
                ySize.Height += 8 - (ySize.Height % 8);
            }

            //create padded container
            byte[][] newChannels = new byte[3][];
            newChannels[0] = new byte[ySize.Width * ySize.Height];
            newChannels[1] = new byte[brNewSize.Width * brNewSize.Height];
            newChannels[2] = new byte[newChannels[1].Length];

            //copy array into larger container
            for (int y = 0; y < state.channelHeight; y++)
            {
                Array.Copy(state.channels[0], y * state.channelWidth, newChannels[0], y * ySize.Width, state.channelWidth);
            }
            for (int y = 0; y < brOldSize.Height; y++)
            {
                Array.Copy(state.channels[1], y * brOldSize.Width, newChannels[1], y * brNewSize.Width, brOldSize.Width);
                Array.Copy(state.channels[2], y * brOldSize.Width, newChannels[2], y * brNewSize.Width, brOldSize.Width);
                for (int x = brOldSize.Width; x < brNewSize.Width; x++)
                {
                    newChannels[1][y * brNewSize.Width + x] = 127;
                    newChannels[2][y * brNewSize.Width + x] = 127;
                }
            }

            //update state
            state.channelWidth  = ySize.Width;
            state.channelHeight = ySize.Height;
            state.channels      = newChannels;
        }