private void flipX(WritableRaster raster) {
        int minX = raster.getMinX();
        int minY = raster.getMinY();
        int height = raster.getHeight();
        int width = raster.getWidth();
        int maxX = minX + width - 1; // Inclusive
        int numBands = raster.getNumBands();

        switch (raster.getSampleModel().getDataType()) {
        case DataBuffer.TYPE_BYTE:
        case DataBuffer.TYPE_SHORT:
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_INT:
            int[] iData0 = new int[height*numBands];
            int[] iData1 = new int[height*numBands];

            for (int i = 0; i < width/2; i++) {
                raster.getPixels(minX + i, minY, 1, height, iData0);
                raster.getPixels(maxX - i, minY, 1, height, iData1);

                raster.setPixels(minX + i, minY, 1, height, iData1);
                raster.setPixels(maxX - i, minY, 1, height, iData0);
            }
            break;

        case DataBuffer.TYPE_FLOAT:
            float[] fData0 = new float[height*numBands];
            float[] fData1 = new float[height*numBands];

            for (int i = 0; i < width/2; i++) {
                raster.getPixels(minX + i, minY, 1, height, fData0);
                raster.getPixels(maxX - i, minY, 1, height, fData1);

                raster.setPixels(minX + i, minY, 1, height, fData1);
                raster.setPixels(maxX - i, minY, 1, height, fData0);
            }
            break;

        case DataBuffer.TYPE_DOUBLE:
            double[] dData0 = new double[height*numBands];
            double[] dData1 = new double[height*numBands];

            for (int i = 0; i < width/2; i++) {
                raster.getPixels(minX + i, minY, 1, height, dData0);
                raster.getPixels(maxX - i, minY, 1, height, dData1);

                raster.setPixels(minX + i, minY, 1, height, dData1);
                raster.setPixels(maxX - i, minY, 1, height, dData0);
            }
            break;
        }
    }