001/*******************************************************************************
002 * This software is provided as a supplement to the authors' textbooks on digital
003 * image processing published by Springer-Verlag in various languages and editions.
004 * Permission to use and distribute this software is granted under the BSD 2-Clause
005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause).
006 * Copyright (c) 2006-2023 Wilhelm Burger, Mark J. Burge. All rights reserved.
007 * Visit https://imagingbook.com for additional details.
008 ******************************************************************************/
009package imagingbook.spectral.dct;
010
011/**
012 * <p>
013 * Direct (slow) implementation of the 2-dimensional DCT using tabulated cosine values. 
014 * Note that this class has no public constructor -
015 * instantiate sub-class {@link Dct2dDirect.Float} or {@link Dct2dDirect.Double}
016 * instead, as shown below. See Ch. 20 of [1] for additional details.
017 * </p>
018 * <p>
019 * Usage example (for {@code float} data):
020 * </p>
021 * <pre>
022 * float[][] data = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {-2, -1, 0}};
023 * int w = data.length;       // w = 4
024 * int h = data[0].length;    // h = 3
025 * Dct2d.Float dct = new Dct2dDirect.Float(w, h);
026 * dct.forward(data);  // data now is the 2D DCT spectrum
027 * dct.inverse(data);  // data now is the original 2D signal 
028 * ...</pre>
029 * <p>
030 * [1] W. Burger, M.J. Burge, <em>Digital Image Processing &ndash; An Algorithmic
031 * Introduction</em>, 3rd ed, Springer (2022).
032 * </p>
033 * 
034 * @author WB
035 * @see Dct1dDirect
036 */
037public class Dct2dDirect  extends Dct2dImp {
038        
039        private Dct2dDirect(int width, int height) {
040                super(width, height);
041        }
042        
043        // -------------------------------------------------------------------------
044        
045        /**
046         * Two-dimensional DCT implementation using {@code float} data. 
047         */
048        public static class Float extends Dct2dDirect implements Dct2d.Float {
049                
050                /**
051                 * Constructor.
052                 * 
053                 * @param width width of the data array (dimension 0)
054                 * @param height height of the data array (dimension 1)
055                 */
056                public Float(int width, int height) {
057                        super(width, height);
058                }
059                
060                // -------------------
061
062                @Override
063                public Dct1d.Float get1dDct(int size) {
064                        return new Dct1dDirect.Float(size);
065                }
066
067        }
068        
069        /**
070         * Two-dimensional DCT implementation using {@code double} data. 
071         */
072        public static class Double extends Dct2dDirect implements Dct2d.Double {
073                
074                /**
075                 * Constructor.
076                 * 
077                 * @param width width of the data array (dimension 0)
078                 * @param height height of the data array (dimension 1)
079                 */
080                public Double(int width, int height) {
081                        super(width, height);
082                }
083                
084                // -------------------
085
086                @Override
087                public Dct1d.Double get1dDct(int size) {
088                        return new Dct1dDirect.Double(size);
089                }
090
091        }
092
093}