Esempio n. 1
0
        public byte[] insertHeaders(Stream stream, List<Dictionary<string, object>> headers = null)
        {
            long idx;
            BinaryReader br = new BinaryReader(stream);

            if (headers == null || headers.Count == 0) {
                headers = _headers;
            }

            // Check if data is jpeg
            if (br.SHORT(0) != 0xFFD8) {
                throw new ImageError(ImageError.WRONG_FORMAT);
            }

            if (headers.Count != 0) {
                idx = br.SHORT(2) == 0xFFE0 ? 4 + br.SHORT(4) : 2;

                for (int i = 0, max = headers.Count; i < max; i++) {
                    br.SEGMENT((int)idx, 0, (byte[])headers[i]["segment"]);
                    idx += Convert.ToInt32(headers[i]["length"]);
                }
            }
            return br.SEGMENT();
        }
Esempio n. 2
0
        public byte[] stripHeaders(Stream stream)
        {
            JPEG img = new JPEG(stream);
            List<Dictionary<string, object>> headers = img.extractHeaders();
            BinaryReader br = new BinaryReader(stream);

            for (int i = headers.Count - 1; i >= 0; i--)
            {
                br.SEGMENT(Convert.ToInt32(headers[i]["start"]), Convert.ToInt32(headers[i]["length"]), new byte[0]);
            }
            return br.SEGMENT();
        }