krita
kis_autobrush_resource.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kis_autobrush_resource.h"
00020 #include <kdebug.h>
00021
00022 void KisAutobrushShape::createBrush( QImage* img)
00023 {
00024 img->create(m_w, m_h, 32);
00025 for(int j = 0; j < m_h; j++)
00026 {
00027 for(int i = 0; i < m_w; i++)
00028 {
00029 Q_INT8 v = valueAt(i,j);
00030 img->setPixel( i, j, qRgb(v,v,v));
00031 }
00032 }
00033 }
00034
00035 KisAutobrushCircleShape::KisAutobrushCircleShape(Q_INT32 w, Q_INT32 h, double fh, double fv)
00036 : KisAutobrushShape( w, h, w / 2.0 - fh, h / 2.0 - fv),
00037 m_xcentre ( w / 2.0 ),
00038 m_ycentre ( h / 2.0 ),
00039 m_xcoef ( 2.0 / w ),
00040 m_ycoef ( 2.0 / h ),
00041 m_xfadecoef ( (m_fh == 0) ? 1 : ( 1.0 / m_fh)),
00042 m_yfadecoef ( (m_fv == 0) ? 1 : ( 1.0 / m_fv))
00043 {
00044 }
00045 Q_INT8 KisAutobrushCircleShape::valueAt(Q_INT32 x, Q_INT32 y)
00046 {
00047 double xr = (x - m_xcentre) + 0.5;
00048 double yr = (y - m_ycentre) + 0.5;
00049 double n = norme( xr * m_xcoef, yr * m_ycoef);
00050 if( n > 1 )
00051 {
00052 return 255;
00053 }
00054 else
00055 {
00056 double normeFade = norme( xr * m_xfadecoef, yr * m_yfadecoef );
00057 if( normeFade > 1)
00058 {
00059 double xle, yle;
00060
00061
00062
00063
00064 if( xr == 0 )
00065 {
00066 xle = 0;
00067 yle = yr > 0 ? 1/m_ycoef : -1/m_ycoef;
00068 } else {
00069 double c = yr / (double)xr;
00070 xle = sqrt(1 / norme( m_xcoef, c * m_ycoef ));
00071 xle = xr > 0 ? xle : -xle;
00072 yle = xle * c;
00073 }
00074
00075 double normeFadeLimitE = norme( xle * m_xfadecoef, yle * m_yfadecoef );
00076 return (uchar)(255 * ( normeFade - 1 ) / ( normeFadeLimitE - 1 ));
00077 } else {
00078 return 0;
00079 }
00080 }
00081 }
00082
00083 KisAutobrushRectShape::KisAutobrushRectShape(Q_INT32 w, Q_INT32 h, double fh, double fv)
00084 : KisAutobrushShape( w, h, w / 2.0 - fh, h / 2.0 - fv),
00085 m_xcentre ( w / 2.0 ),
00086 m_ycentre ( h / 2.0 ),
00087 m_c( fv/fh)
00088 {
00089 }
00090 Q_INT8 KisAutobrushRectShape::valueAt(Q_INT32 x, Q_INT32 y)
00091 {
00092 double xr = QABS(x - m_xcentre);
00093 double yr = QABS(y - m_ycentre);
00094 if( xr > m_fh || yr > m_fv )
00095 {
00096 if( yr <= ((xr - m_fh) * m_c + m_fv ) )
00097 {
00098 return (uchar)(255 * (xr - m_fh) / (m_w - m_fh));
00099 } else {
00100 return (uchar)(255 * (yr - m_fv) / (m_w - m_fv));
00101 }
00102 }
00103 else {
00104 return 0;
00105 }
00106 }
|