tesseract
3.03
|
00001 /********************************************************************** 00002 * File: mod128.c (Formerly dir128.c) 00003 * Description: Code to convert a DIR128 to an ICOORD. 00004 * Author: Ray Smith 00005 * Created: Tue Oct 22 11:56:09 BST 1991 00006 * 00007 * (C) Copyright 1991, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #include "mod128.h" 00021 00022 const inT16 idirtab[] = { 00023 1000, 0, 998, 49, 995, 98, 989, 146, 00024 980, 195, 970, 242, 956, 290, 941, 336, 00025 923, 382, 903, 427, 881, 471, 857, 514, 00026 831, 555, 803, 595, 773, 634, 740, 671, 00027 707, 707, 671, 740, 634, 773, 595, 803, 00028 555, 831, 514, 857, 471, 881, 427, 903, 00029 382, 923, 336, 941, 290, 956, 242, 970, 00030 195, 980, 146, 989, 98, 995, 49, 998, 00031 0, 1000, -49, 998, -98, 995, -146, 989, 00032 -195, 980, -242, 970, -290, 956, -336, 941, 00033 -382, 923, -427, 903, -471, 881, -514, 857, 00034 -555, 831, -595, 803, -634, 773, -671, 740, 00035 -707, 707, -740, 671, -773, 634, -803, 595, 00036 -831, 555, -857, 514, -881, 471, -903, 427, 00037 -923, 382, -941, 336, -956, 290, -970, 242, 00038 -980, 195, -989, 146, -995, 98, -998, 49, 00039 -1000, 0, -998, -49, -995, -98, -989, -146, 00040 -980, -195, -970, -242, -956, -290, -941, -336, 00041 -923, -382, -903, -427, -881, -471, -857, -514, 00042 -831, -555, -803, -595, -773, -634, -740, -671, 00043 -707, -707, -671, -740, -634, -773, -595, -803, 00044 -555, -831, -514, -857, -471, -881, -427, -903, 00045 -382, -923, -336, -941, -290, -956, -242, -970, 00046 -195, -980, -146, -989, -98, -995, -49, -998, 00047 0, -1000, 49, -998, 98, -995, 146, -989, 00048 195, -980, 242, -970, 290, -956, 336, -941, 00049 382, -923, 427, -903, 471, -881, 514, -857, 00050 555, -831, 595, -803, 634, -773, 671, -740, 00051 707, -707, 740, -671, 773, -634, 803, -595, 00052 831, -555, 857, -514, 881, -471, 903, -427, 00053 923, -382, 941, -336, 956, -290, 970, -242, 00054 980, -195, 989, -146, 995, -98, 998, -49 00055 }; 00056 00057 const ICOORD *dirtab = (ICOORD *) idirtab; 00058 00059 /********************************************************************** 00060 * DIR128::DIR128 00061 * 00062 * Quantize the direction of an FCOORD to make a DIR128. 00063 **********************************************************************/ 00064 00065 DIR128::DIR128( //from fcoord 00066 const FCOORD fc //vector to quantize 00067 ) { 00068 int high, low, current; //binary search 00069 00070 low = 0; 00071 if (fc.y () == 0) { 00072 if (fc.x () >= 0) 00073 dir = 0; 00074 else 00075 dir = MODULUS / 2; 00076 return; 00077 } 00078 high = MODULUS; 00079 do { 00080 current = (high + low) / 2; 00081 if (dirtab[current] * fc >= 0) 00082 low = current; 00083 else 00084 high = current; 00085 } 00086 while (high - low > 1); 00087 dir = low; 00088 } 00089 00090 00091 /********************************************************************** 00092 * dir_to_gradient 00093 * 00094 * Convert a direction to a vector. 00095 **********************************************************************/ 00096 00097 ICOORD DIR128::vector() const { //convert to vector 00098 return dirtab[dir]; //easy really 00099 }