| 1 |
/* |
| 2 |
Copyright (c) 1993-2008, Cognitive Technologies |
| 3 |
All rights reserved. |
| 4 |
|
| 5 |
Разрешается повторное распространение и использование как в виде исходного кода, |
| 6 |
так и в двоичной форме, с изменениями или без, при соблюдении следующих условий: |
| 7 |
|
| 8 |
* При повторном распространении исходного кода должны оставаться указанное |
| 9 |
выше уведомление об авторском праве, этот список условий и последующий |
| 10 |
отказ от гарантий. |
| 11 |
* При повторном распространении двоичного кода в документации и/или в |
| 12 |
других материалах, поставляемых при распространении, должны сохраняться |
| 13 |
указанная выше информация об авторском праве, этот список условий и |
| 14 |
последующий отказ от гарантий. |
| 15 |
* Ни название Cognitive Technologies, ни имена ее сотрудников не могут |
| 16 |
быть использованы в качестве средства поддержки и/или продвижения |
| 17 |
продуктов, основанных на этом ПО, без предварительного письменного |
| 18 |
разрешения. |
| 19 |
|
| 20 |
ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК |
| 21 |
ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ, |
| 22 |
ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ |
| 23 |
ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ |
| 24 |
МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ |
| 25 |
НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ |
| 26 |
ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ |
| 27 |
НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ, |
| 28 |
СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ |
| 29 |
ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ, |
| 30 |
НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ |
| 31 |
ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ. |
| 32 |
|
| 33 |
Redistribution and use in source and binary forms, with or without modification, |
| 34 |
are permitted provided that the following conditions are met: |
| 35 |
|
| 36 |
* Redistributions of source code must retain the above copyright notice, |
| 37 |
this list of conditions and the following disclaimer. |
| 38 |
* Redistributions in binary form must reproduce the above copyright notice, |
| 39 |
this list of conditions and the following disclaimer in the documentation |
| 40 |
and/or other materials provided with the distribution. |
| 41 |
* Neither the name of the Cognitive Technologies nor the names of its |
| 42 |
contributors may be used to endorse or promote products derived from this |
| 43 |
software without specific prior written permission. |
| 44 |
|
| 45 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 46 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 47 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 48 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 49 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 50 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 51 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 52 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 53 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 54 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 55 |
*/ |
| 56 |
|
| 57 |
#include "lnslang.h" |
| 58 |
|
| 59 |
#include "smooth.h" |
| 60 |
#include "lns.h" |
| 61 |
/////////////////////////////////////////////////////////////////// |
| 62 |
static int32_t* buff=NULL; |
| 63 |
static int nLines=0; // count of lines passed through buffer |
| 64 |
static int width_dword =0; |
| 65 |
|
| 66 |
#define DEF_SMOOTH_HEIGHT 4 |
| 67 |
#define MAX_SMOOTH_HEIGHT 16 // crazy... |
| 68 |
|
| 69 |
static int nSmoothHeight=DEF_SMOOTH_HEIGHT; // count of lines smoothed vertically |
| 70 |
|
| 71 |
Bool smooth_start(int _width_dword) |
| 72 |
{ |
| 73 |
nSmoothHeight = LnsGetProfileInt("nSmoothHeight", DEF_SMOOTH_HEIGHT); |
| 74 |
if (nSmoothHeight < 0 || nSmoothHeight > MAX_SMOOTH_HEIGHT) |
| 75 |
nSmoothHeight = DEF_SMOOTH_HEIGHT; |
| 76 |
|
| 77 |
if (nSmoothHeight == 0) |
| 78 |
return TRUE; // no smoothing |
| 79 |
|
| 80 |
width_dword = _width_dword; |
| 81 |
buff = (int32_t *)(malloc(4*width_dword*(nSmoothHeight+1) ) ); |
| 82 |
if (buff==NULL) |
| 83 |
return FALSE; |
| 84 |
|
| 85 |
memset(buff, 0xff, 4*width_dword*(nSmoothHeight+1) ); // start - all white |
| 86 |
nLines =0; |
| 87 |
return TRUE; |
| 88 |
} |
| 89 |
|
| 90 |
int32_t smooth_get_height() // count of lines joined lines |
| 91 |
{ |
| 92 |
return nSmoothHeight; |
| 93 |
} |
| 94 |
|
| 95 |
int32_t* smooth_update(int32_t* new_line) |
| 96 |
{ |
| 97 |
if (nSmoothHeight==0 || nSmoothHeight==1) |
| 98 |
return new_line; |
| 99 |
|
| 100 |
int pos = 1 + (nLines % nSmoothHeight); // 1..nSmoothHeight used to keep lines |
| 101 |
// 0 pos used for result |
| 102 |
nLines++; |
| 103 |
|
| 104 |
memcpy(buff + pos * width_dword, new_line, 4*width_dword); // save line |
| 105 |
|
| 106 |
// make smooth |
| 107 |
if (nSmoothHeight == 4) |
| 108 |
{ |
| 109 |
int32_t* p0=buff; |
| 110 |
int32_t* p1=buff + width_dword; |
| 111 |
int32_t* p2=buff + width_dword*2; |
| 112 |
int32_t* p3=buff + width_dword*3; |
| 113 |
int32_t* p4=buff + width_dword*4; |
| 114 |
|
| 115 |
int wi = width_dword; |
| 116 |
while (wi--) |
| 117 |
{ |
| 118 |
*p0++ = ((*p1++) & (*p2++)) & ((*p3++) & (*p4++)); |
| 119 |
} |
| 120 |
|
| 121 |
return buff; |
| 122 |
} |
| 123 |
if (nSmoothHeight == 3) |
| 124 |
{ |
| 125 |
int32_t* p0=buff; |
| 126 |
int32_t* p1=buff + width_dword; |
| 127 |
int32_t* p2=buff + width_dword*2; |
| 128 |
int32_t* p3=buff + width_dword*3; |
| 129 |
|
| 130 |
int wi = width_dword; |
| 131 |
while (wi--) |
| 132 |
{ |
| 133 |
*p0++ = ((*p1++) & (*p2++)) & ((*p3++)); |
| 134 |
} |
| 135 |
} |
| 136 |
if (nSmoothHeight == 2) |
| 137 |
{ |
| 138 |
int32_t* p0=buff; |
| 139 |
int32_t* p1=buff + width_dword; |
| 140 |
int32_t* p2=buff + width_dword*2; |
| 141 |
|
| 142 |
int wi = width_dword; |
| 143 |
while (wi--) |
| 144 |
{ |
| 145 |
*p0++ = ((*p1++) & (*p2++)); |
| 146 |
} |
| 147 |
} |
| 148 |
if (nSmoothHeight > 4) |
| 149 |
{ |
| 150 |
int32_t* p0=buff; |
| 151 |
int wi = width_dword; |
| 152 |
while (wi--) |
| 153 |
{ |
| 154 |
*p0 = 0xffffffff; |
| 155 |
int sh = nSmoothHeight; |
| 156 |
int32_t* p1=p0; |
| 157 |
while (sh--) |
| 158 |
{ |
| 159 |
p1 += width_dword; |
| 160 |
*p0 &= *p1; |
| 161 |
} |
| 162 |
p0++; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
return buff; |
| 167 |
} |
| 168 |
|
| 169 |
void smooth_finish() |
| 170 |
{ |
| 171 |
if (buff) |
| 172 |
{ |
| 173 |
free(buff); |
| 174 |
buff = NULL; |
| 175 |
} |
| 176 |
} |