2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
17 namespace ImageEffects
{
25 static inline void blur_mmx(void *px
, __m64
& v
, __m64
& alpha
)
30 "movd %[pixel], %[t1]\n"
31 "punpcklbw %[t1], %[t2]\n"
33 "psubw %[accum], %[t2]\n"
34 "pmulhw %[alpha], %[t2]\n"
36 "paddw %[t2], %[accum]\n"
37 "movq %[accum], %[t1]\n"
39 // "pand %[mask], %[t1]\n"
40 "packuswb %[t1], %[t1]\n"
41 "movd %[t1], %[pixel]\n"
42 : [pixel
] "+m"(*(uint32_t*)px
)
47 // , [mask] "y"(0x00ff00ff00ff00ffULL)
51 void expblur_mmx( QImage
&img
, int radius
)
56 /* Calculate the alpha such that 90% of
57 the kernel is within the radius.
58 (Kernel extends to infinity)
60 uint16_t alpha
= (uint16_t)((1<<15)*(1.0f
-expf(-2.3f
/(radius
+1.f
))));
63 QRgb
*ptr
= (QRgb
*)img
.bits();
66 int hw
= (img
.height()-1)*img
.width();
70 for(int row
=0;row
<h
;row
++)
73 uint8_t *cptr
= (uint8_t*)(ptr
+row
*w
);
77 for(int index
=1; index
<w
; index
++)
78 blur_mmx(&cptr
[index
*4], z
.v
, a
.v
);
80 for(int index
=w
-2; index
>=0; index
--)
81 blur_mmx(&cptr
[index
*4], z
.v
, a
.v
);
84 for(int col
=0;col
<w
;col
++)
87 uint8_t *cptr
= (uint8_t*)(ptr
+col
);
92 for(int index
=w
; index
<hw
; index
+=w
)
93 blur_mmx(&cptr
[index
*4], z
.v
, a
.v
);
95 for(int index
=hw
-w
; index
>=0; index
-=w
)
96 blur_mmx(&cptr
[index
*4], z
.v
, a
.v
);
103 } //end namespace ImageEffects