gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/stream.cpp


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/stream.cpp
Date: Sat, 15 Mar 2008 08:00:53 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/03/15 08:00:53

Modified files:
        .              : ChangeLog 
        server         : stream.cpp 

Log message:
        use the float conversion function found in action_buffer,
        hopefully working fine on big endian hosts (to be tested).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5923&r2=1.5924
http://cvs.savannah.gnu.org/viewcvs/gnash/server/stream.cpp?cvsroot=gnash&r1=1.49&r2=1.50

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5923
retrieving revision 1.5924
diff -u -b -r1.5923 -r1.5924
--- ChangeLog   15 Mar 2008 07:47:24 -0000      1.5923
+++ ChangeLog   15 Mar 2008 08:00:52 -0000      1.5924
@@ -1,3 +1,9 @@
+2008-03-15 Sandro Santilli <address@hidden>
+
+       * server/stream.cpp: use the float conversion function found
+         in action_buffer, hopefully working fine on big endian hosts
+         (to be tested).
+
 2008-03-14  Rob Savoye  <address@hidden>
 
        * doc/C/Makefile.am: Install the preformatted info pages too.

Index: server/stream.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/stream.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- server/stream.cpp   14 Mar 2008 22:33:56 -0000      1.49
+++ server/stream.cpp   15 Mar 2008 08:00:53 -0000      1.50
@@ -224,15 +224,54 @@
        return static_cast<float> ( read_s16() );
 }
 
+// Read a little-endian 32-bit float from p
+// and return it as a host-endian float.
+static float
+convert_float_little(const void *p)
+{
+       // Hairy union for endian detection and munging
+       union {
+               float   f;
+               boost::uint32_t i;
+               struct {        // for endian detection
+                       boost::uint16_t s0;
+                       boost::uint16_t s1;
+               } s;
+               struct {        // for byte-swapping
+                       boost::uint8_t c0;
+                       boost::uint8_t c1;
+                       boost::uint8_t c2;
+                       boost::uint8_t c3;
+               } c;
+       } u;
+
+       u.f = 1.0;
+       switch (u.s.s0) {
+       case 0x0000:    // little-endian host
+               memcpy(&u.i, p, 4);
+               break;
+       case 0x3f80:    // big-endian host
+           {
+               const boost::uint8_t *cp = (const boost::uint8_t *) p;
+               u.c.c0 = cp[3];
+               u.c.c1 = cp[2];
+               u.c.c2 = cp[1];
+               u.c.c3 = cp[0];
+           }
+           break;
+       default:
+           log_error(_("Native floating point format not recognised"));
+           abort();
+       }
+       
+       return u.f;
+}
+
 /// Read a 32bit (1:sign 8:exp 23:mantissa) floating point value
 float  stream::read_long_float()
 {
-       char data[4];
-       data[0] = read_u8();
-       data[1] = read_u8();
-       data[2] = read_u8();
-       data[3] = read_u8();
-       return *((float *)data);
+       char data[4]; read(data, 4); // would align
+       return convert_float_little(data); 
 }
 
 // Read a 64-bit double value




reply via email to

[Prev in Thread] Current Thread [Next in Thread]