#if wxUSE_APPLE_IEEE
-#include <math.h>
+#include "wx/math.h"
/* Copyright (C) 1989-1991 Ken Turkowski. <turk@computer.org>
*
* Infinities are, however, preserved on IEEE machines.
*
* These routines have been tested on the following machines:
- * Apple Macintosh, MPW 3.1 C compiler
- * Apple Macintosh, THINK C compiler
- * Silicon Graphics IRIS, MIPS compiler
- * Cray X/MP and Y/MP
- * Digital Equipment VAX
- * Sequent Balance (Multiprocesor 386)
- * NeXT
+ * Apple Macintosh, MPW 3.1 C compiler
+ * Apple Macintosh, THINK C compiler
+ * Silicon Graphics IRIS, MIPS compiler
+ * Cray X/MP and Y/MP
+ * Digital Equipment VAX
+ * Sequent Balance (Multiprocesor 386)
+ * NeXT
*
*
* Implemented by Malcolm Slaney and Ken Turkowski.
* Silicon Graphics MIPS-based Iris.
****************************************************************/
-#ifdef applec /* The Apple C compiler works */
-# define FloatToUnsigned(f) ((wxUint32)(f))
-# define UnsignedToFloat(u) ((wxFloat64)(u))
+#ifdef applec /* The Apple C compiler works */
+# define FloatToUnsigned(f) ((wxUint32)(f))
+# define UnsignedToFloat(u) ((wxFloat64)(u))
#else /*applec*/
-# define FloatToUnsigned(f) ((wxUint32)(((wxInt32)((f) - 2147483648.0)) + 2147483647L) + 1)
-# define UnsignedToFloat(u) (((wxFloat64)((wxInt32)((u) - 2147483647L - 1))) + 2147483648.0)
+# define FloatToUnsigned(f) ((wxUint32)(((wxInt32)((f) - 2147483648.0)) + 2147483647L) + 1)
+# define UnsignedToFloat(u) (((wxFloat64)((wxInt32)((u) - 2147483647L - 1))) + 2147483648.0)
#endif /*applec*/
-
+
/****************************************************************
* Extended precision IEEE floating-point conversion routines.
* Extended is an 80-bit number as defined by Motorola,
wxFloat64 ConvertFromIeeeExtended(wxInt8* bytes)
{
- wxFloat64 f;
- wxInt32 expon;
- wxUint32 hiMant, loMant;
-
- expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
- hiMant = ((wxUint32)(bytes[2] & 0xFF) << 24)
- | ((wxUint32)(bytes[3] & 0xFF) << 16)
- | ((wxUint32)(bytes[4] & 0xFF) << 8)
- | ((wxUint32)(bytes[5] & 0xFF));
- loMant = ((wxUint32)(bytes[6] & 0xFF) << 24)
- | ((wxUint32)(bytes[7] & 0xFF) << 16)
- | ((wxUint32)(bytes[8] & 0xFF) << 8)
- | ((wxUint32)(bytes[9] & 0xFF));
-
- if (expon == 0 && hiMant == 0 && loMant == 0) {
- f = 0;
- }
- else {
- if (expon == 0x7FFF) { /* Infinity or NaN */
- f = HUGE_VAL;
- }
- else {
- expon -= 16383;
- f = ldexp(UnsignedToFloat(hiMant), expon-=31);
- f += ldexp(UnsignedToFloat(loMant), expon-=32);
- }
- }
-
- if (bytes[0] & 0x80)
- return -f;
- else
- return f;
+ wxFloat64 f;
+ wxInt32 expon;
+ wxUint32 hiMant, loMant;
+
+ expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
+ hiMant = ((wxUint32)(bytes[2] & 0xFF) << 24)
+ | ((wxUint32)(bytes[3] & 0xFF) << 16)
+ | ((wxUint32)(bytes[4] & 0xFF) << 8)
+ | ((wxUint32)(bytes[5] & 0xFF));
+ loMant = ((wxUint32)(bytes[6] & 0xFF) << 24)
+ | ((wxUint32)(bytes[7] & 0xFF) << 16)
+ | ((wxUint32)(bytes[8] & 0xFF) << 8)
+ | ((wxUint32)(bytes[9] & 0xFF));
+
+ if (expon == 0 && hiMant == 0 && loMant == 0) {
+ f = 0;
+ }
+ else {
+ if (expon == 0x7FFF) { /* Infinity or NaN */
+ f = HUGE_VAL;
+ }
+ else {
+ expon -= 16383;
+ f = ldexp(UnsignedToFloat(hiMant), expon-=31);
+ f += ldexp(UnsignedToFloat(loMant), expon-=32);
+ }
+ }
+
+ if (bytes[0] & 0x80)
+ return -f;
+ else
+ return f;
}
void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes)
{
- wxInt32 sign;
- wxInt32 expon;
- wxFloat64 fMant, fsMant;
- wxUint32 hiMant, loMant;
-
- if (num < 0) {
- sign = 0x8000;
- num *= -1;
- } else {
- sign = 0;
- }
-
- if (num == 0) {
- expon = 0; hiMant = 0; loMant = 0;
- }
- else {
- fMant = frexp(num, &expon);
- if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */
- expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */
- }
- else { /* Finite */
- expon += 16382;
- if (expon < 0) { /* denormalized */
- fMant = ldexp(fMant, expon);
- expon = 0;
- }
- expon |= sign;
- fMant = ldexp(fMant, 32); fsMant = floor(fMant); hiMant = FloatToUnsigned(fsMant);
- fMant = ldexp(fMant - fsMant, 32); fsMant = floor(fMant); loMant = FloatToUnsigned(fsMant);
- }
- }
-
- bytes[0] = expon >> 8;
- bytes[1] = expon;
- bytes[2] = hiMant >> 24;
- bytes[3] = hiMant >> 16;
- bytes[4] = hiMant >> 8;
- bytes[5] = hiMant;
- bytes[6] = loMant >> 24;
- bytes[7] = loMant >> 16;
- bytes[8] = loMant >> 8;
- bytes[9] = loMant;
+ wxInt32 sign;
+ wxInt32 expon;
+ wxFloat64 fMant, fsMant;
+ wxUint32 hiMant, loMant;
+
+ if (num < 0) {
+ sign = 0x8000;
+ num *= -1;
+ } else {
+ sign = 0;
+ }
+
+ if (num == 0) {
+ expon = 0; hiMant = 0; loMant = 0;
+ }
+ else {
+ fMant = frexp(num, &expon);
+ if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */
+ expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */
+ }
+ else { /* Finite */
+ expon += 16382;
+ if (expon < 0) { /* denormalized */
+ fMant = ldexp(fMant, expon);
+ expon = 0;
+ }
+ expon |= sign;
+ fMant = ldexp(fMant, 32); fsMant = floor(fMant); hiMant = FloatToUnsigned(fsMant);
+ fMant = ldexp(fMant - fsMant, 32); fsMant = floor(fMant); loMant = FloatToUnsigned(fsMant);
+ }
+ }
+
+ bytes[0] = expon >> 8;
+ bytes[1] = expon;
+ bytes[2] = hiMant >> 24;
+ bytes[3] = hiMant >> 16;
+ bytes[4] = hiMant >> 8;
+ bytes[5] = hiMant;
+ bytes[6] = loMant >> 24;
+ bytes[7] = loMant >> 16;
+ bytes[8] = loMant >> 8;
+ bytes[9] = loMant;
}
#include "wx/module.h"
#include "wx/hash.h"
#include "wx/utils.h"
+#include "wx/math.h"
// For memcpy
#include <string.h>
-#include <math.h>
#ifdef __SALFORDC__
#undef FAR
bool wxImage::ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b )
{
SetAlpha( NULL );
-
+
int w = M_IMGDATA->m_width,
h = M_IMGDATA->m_height;
-
+
unsigned char *alpha = GetAlpha();
unsigned char *data = GetData();
-
+
int x,y;
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
int i;
angle = -angle; // screen coordinates are a mirror image of "real" coordinates
-
+
bool has_alpha = HasAlpha();
// Create pointer-based array to accelerate access to wxImage's data
for (i = 1; i < GetHeight(); i++)
data[i] = data[i - 1] + (3 * GetWidth());
- // Same for alpha channel
+ // Same for alpha channel
unsigned char ** alpha = NULL;
if (has_alpha)
{
// array here (and in fact it would be slower).
//
unsigned char * dst = rotated.GetData();
-
+
unsigned char * alpha_dst = NULL;
if (has_alpha)
alpha_dst = rotated.GetAlpha();
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y1] + x1;
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y1] + x2;
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y2] + x2;
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y2] + x1;
( (w1 * *v1 + w2 * *v2 +
w3 * *v3 + w4 * *v4) /
(w1 + w2 + w3 + w4) );
-
+
if (has_alpha)
{
unsigned char *v1 = alpha[y1] + (x1);
*(dst++) = blank_r;
*(dst++) = blank_g;
*(dst++) = blank_b;
-
+
if (has_alpha)
*(alpha_dst++) = 0;
}
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[ys] + (xs);
*(dst++) = blank_r;
*(dst++) = blank_g;
*(dst++) = blank_b;
-
+
if (has_alpha)
*(alpha_dst++) = 255;
}
}
delete [] data;
-
+
if (has_alpha)
delete [] alpha;