private void flipY(WritableRaster raster) {
        int minX = raster.getMinX();
        int minY = raster.getMinY();
        int height = raster.getHeight();
        int width = raster.getWidth();
        int maxY = minY + height - 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[width*numBands];
            int[] iData1 = new int[width*numBands];

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

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

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

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

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