Search code examples
imageimage-processingjpeg

What is the process to create a mirror-image of a JPG file without creating or using a decoder?


So, I'm kind of experimenting with image-manipulation at the byte-level (No 'Image' wrapper or libraries), so the language doesn't matter (I'm using C#) as much as the byte-manipulations, themselves.

I'm now trying to flip a a .jpg image (minus the magic number) over the x- and y-axis, but realized after some trial and error that I think the encoding is getting in the way. This is the code I'm using on a byte[] without the FF D8 or FFD9 includes:

    //No magic number included            
    public class MirrorImgOverXAndYAxes : IFunction
    {
        //No magic number included
        public byte[] Exec(byte[] jpgImage)
        {
            byte[] resultingImage = new byte[jpgImage.Length];

            for (var i = jpgImage.Length - 1; i >= 0; i--)
            {
                var indexToInsert = jpgImage.Length - 1 - i;
                resultingImage[indexToInsert] = jpgImage[i];
            }

            return resultingImage;
        }
    }

Right now, my assumption is that it's nowhere near as easy as this, and that I would have to build a full-blown decoder to be able to manipulate the image bytes like this.

Is it possible to create this mirror image without a decoder and would something like what I'm doing work?


Solution

  • Hi I guess just flipping a jpeg by switching the bytes position will not really work here, due to how jpg files are actually structured. if you want to learn more about that, you can look here enter link description here But you could try to convert the image to a format that actually saves it's pixels within a single byte. For example bitmaps (.bmp).