![]() |
TurboWavelets.Net
Compact C# Implementation for very fast and flexible wavelet transformations
|
00001 // 00002 // OrderWavelet2D.cs 00003 // 00004 // Author: 00005 // Stefan Moebius 00006 // Date: 00007 // 2016-04-24 00008 // 00009 // Copyright (c) 2016 Stefan Moebius 00010 // 00011 // Permission is hereby granted, free of charge, to any person obtaining a copy 00012 // of this software and associated documentation files (the "Software"), to deal 00013 // in the Software without restriction, including without limitation the rights 00014 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00015 // copies of the Software, and to permit persons to whom the Software is 00016 // furnished to do so, subject to the following conditions: 00017 // 00018 // The above copyright notice and this permission notice shall be included in 00019 // all copies or substantial portions of the Software. 00020 // 00021 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00022 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00024 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00027 // THE SOFTWARE. 00028 00029 namespace TurboWavelets 00030 { 00034 public class OrderWavelet2D : Wavelet2D 00035 { 00039 protected const int AllowedMinSize = 2; 00040 00050 public OrderWavelet2D (int width, int height) 00051 : base(AllowedMinSize, AllowedMinSize, width, height) 00052 { 00053 } 00054 00065 public OrderWavelet2D (int width, int height, int minSize) 00066 : base(minSize, AllowedMinSize, width, height) 00067 { 00068 } 00069 00070 #pragma warning disable 1591 // do not show compiler warnings of the missing descriptions 00071 override protected void TransformRow (float[,] src, float[,] dst, int y, int length) 00072 { 00073 if (length >= AllowedMinSize) { 00074 int half = length >> 1; 00075 int offSrc = 0; 00076 // number of low-pass values 00077 int numLFValues = half + (length & 1); 00078 00079 for (int i = 0; i < half; i++) { 00080 dst [i, y] = src [offSrc, y]; 00081 dst [i + numLFValues, y] = src [offSrc + 1, y]; 00082 offSrc += 2; 00083 } 00084 if ((length & 1) != 0) 00085 dst [numLFValues - 1, y] = src [length - 1, y]; 00086 } else { 00087 for (int i = 0; i < length; i++) 00088 dst [i, y] = src [i, y]; 00089 } 00090 } 00091 00092 override protected void TransformCol (float[,] src, float[,] dst, int x, int length) 00093 { 00094 if (length >= AllowedMinSize) { 00095 int half = length >> 1; 00096 int offSrc = 0; 00097 // number of low-pass values 00098 int numLFValues = half + (length & 1); 00099 00100 for (int i = 0; i < half; i++) { 00101 dst [x, i] = src [x, offSrc]; 00102 dst [x, i + numLFValues] = src [x, offSrc + 1]; 00103 offSrc += 2; 00104 } 00105 if ((length & 1) != 0) 00106 dst [x, numLFValues - 1] = src [x, length - 1]; 00107 } else { 00108 for (int i = 0; i < length; i++) 00109 dst [x, i] = src [x, i]; 00110 } 00111 } 00112 00113 override protected void InvTransformRow (float[,] src, float[,] dst, int y, int length) 00114 { 00115 if (length >= AllowedMinSize) { 00116 int half = length >> 1; 00117 int offDst = 0; 00118 // number of low-pass values 00119 int numLFValues = half + (length & 1); 00120 00121 for (int i = 0; i < half; i++) { 00122 dst [offDst, y] = src [i, y]; 00123 dst [offDst + 1, y] = src [i + numLFValues, y]; 00124 offDst += 2; 00125 } 00126 if ((length & 1) != 0) 00127 dst [length - 1, y] = src [numLFValues - 1, y]; 00128 } else { 00129 for (int i = 0; i < length; i++) 00130 dst [i, y] = src [i, y]; 00131 } 00132 } 00133 00134 override protected void InvTransformCol (float[,] src, float[,] dst, int x, int length) 00135 { 00136 if (length >= AllowedMinSize) { 00137 int half = length >> 1; 00138 int offDst = 0; 00139 // number of low-pass values 00140 int numLFValues = half + (length & 1); 00141 00142 for (int i = 0; i < half; i++) { 00143 dst [x, offDst] = src [x, i]; 00144 dst [x, offDst + 1] = src [x, i + numLFValues]; 00145 offDst += 2; 00146 } 00147 if ((length & 1) != 0) 00148 dst [x, length - 1] = src [x, numLFValues - 1]; 00149 } else { 00150 for (int i = 0; i < length; i++) 00151 dst [x, i] = src [x, i]; 00152 } 00153 } 00154 #pragma warning restore 1591 00155 } 00156 }