Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef int Color;
- #define GetRValue( x ) ( unsigned char )( x & 0x000000FF );
- #define GetGValue( x ) ( unsigned char )( x & 0x0000FF00 >> 8 );
- #define GetBValue( x ) ( unsigned char )( x & 0x00FF0000 >> 16 );
- Color AverageColor( Color *Input, int length ) {
- int i;
- int ColorBytes[4];
- int SuperBytes[4];
- int Check[4];
- float LengthSngs[4];
- ColorBytes[0] = ColorBytes[1] = ColorBytes[2] = ColorBytes[3] = 0;
- SuperBytes[0] = SuperBytes[1] = SuperBytes[2] = SuperBytes[3] = 0;
- __asm {
- MOVUPS XMM1, ColorBytes ;ColorBytes in den MMX-Speicher schieben
- MOVUPS Check, XMM1
- }
- for( i = 0; i < length; i++ ) {
- SuperBytes[0] = GetRValue( Input[i] );
- SuperBytes[1] = GetGValue( Input[i] );
- SuperBytes[2] = GetBValue( Input[i] );
- __asm {
- MOVUPS XMM2, SuperBytes ;SuperBytes in das zweite MMX-Register schreiben
- PADDD XMM1, XMM2 ;Parallel addieren... Das Ergebnis steht jetzt in XMM1!
- ;Also erstmal nichts weiter machen...
- MOVUPS Check, XMM1
- }
- }
- LengthSngs[0] = ( float )length;
- LengthSngs[1] = ( float )length;
- LengthSngs[2] = ( float )length;
- LengthSngs[3] = 0.0f;
- __asm {
- MOVAPS XMM2, XMM1 ;fertiges zeug in xmm2 laden, damits zurückgerechnet werden kann
- CVTDQ2PS XMM1, XMM2 ;Alles in Floats umwandeln, damits ans dividieren gehen kann
- MOVUPS XMM2, LengthSngs
- DIVPS XMM1, XMM2
- MOVAPS XMM2, XMM1 ;fertiges zeug in xmm2 laden, damits zurückgerechnet werden kann
- CVTPS2DQ XMM1, XMM2 ;Die Umwandlung zurück in integer machen
- MOVUPS ColorBytes, XMM1 ;Die umgewandelten Daten zurückladen
- }
- return (ColorBytes[2] << 16) | (ColorBytes[1] << 8) | (ColorBytes[0]);
- }
- int _tmain(int argc, _TCHAR* argv[]) {
- int CLRS[2];
- std::cin >> CLRS[0];
- std::cin >> CLRS[1];
- std::cout << AverageColor( CLRS, 2 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment