1 /* 2 * Copyright 2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #ifndef SUPPORT_H 10 #define SUPPORT_H 11 12 #include <Rect.h> 13 14 // constrain 15 inline void 16 constrain(float& value, float min, float max) 17 { 18 if (value < min) 19 value = min; 20 if (value > max) 21 value = max; 22 } 23 24 #ifdef __INTEL__ 25 26 // constrain_int32_0_255_asm 27 inline int32 28 constrain_int32_0_255_asm(int32 value) { 29 asm("movl $0, %%ecx\n\t" 30 "movl $255, %%edx\n\t" 31 "cmpl %%ecx, %%eax\n\t" 32 "cmovl %%ecx, %%eax\n\t" 33 "cmpl %%edx, %%eax\n\t" 34 "cmovg %%edx, %%eax" 35 : "=a" (value) 36 : "a" (value) 37 : "%ecx", "%edx" ); 38 return value; 39 } 40 41 #define constrain_int32_0_255 constrain_int32_0_255_asm 42 43 #else 44 45 inline int32 46 constrain_int32_0_255_c(int32 value) 47 { 48 return max_c(0, min_c(255, value)); 49 } 50 51 #define constrain_int32_0_255 constrain_int32_0_255_c 52 53 #endif 54 55 // rect_to_int 56 inline void 57 rect_to_int(BRect r, 58 int32& left, int32& top, int32& right, int32& bottom) 59 { 60 left = (int32)floorf(r.left); 61 top = (int32)floorf(r.top); 62 right = (int32)ceilf(r.right); 63 bottom = (int32)ceilf(r.bottom); 64 } 65 66 67 # endif // SUPPORT_H 68