diff --git a/Data/SWF/Format.in.lhs b/Data/SWF/Format.in.lhs index 345bf08..b8657ce 100644 --- a/Data/SWF/Format.in.lhs +++ b/Data/SWF/Format.in.lhs @@ -464,13 +464,16 @@ MATRIX Field Type Comment HasScale UB[1] Has scale values if equal to 1 ScaleBits If HasScale = 1, UB[5] Bits in each scale value field + requiredBitsFB mATRIX_scaleX `max` requiredBitsFB mATRIX_scaleY ScaleX If HasScale = 1, FB[ScaleBits] x scale value ScaleY If HasScale = 1, FB[ScaleBits] y scale value HasRotate UB[1] Has rotate and skew values if equal to 1 RotateBits If HasRotate = 1, UB[5] Bits in each rotate value field + requiredBitsFB mATRIX_rotateSkew0 `max` requiredBitsFB mATRIX_rotateSkew1 RotateSkew0 If HasRotate = 1, FB[RotateBits] First rotate and skew value RotateSkew1 If HasRotate = 1, FB[RotateBits] Second rotate and skew value TranslateBits UB[5] Bits in each translate value field + requiredBitsSB mATRIX_translateX `max` requiredBitsSB mATRIX_translateY TranslateX SB[TranslateBits] x translate value in twips TranslateY SB[TranslateBits] y translate value in twips Padding PADDING8 Padding to byte boundary diff --git a/Data/SWF/Format.lhs b/Data/SWF/Format.lhs index 4d2ac15..96a52a4 100644 --- a/Data/SWF/Format.lhs +++ b/Data/SWF/Format.lhs @@ -551,9 +551,9 @@ p20: MATRIX record \begin{code} -data MATRIX = MATRIX{mATRIX_scale :: Maybe (UB, FB, FB), - mATRIX_rotate :: Maybe (UB, FB, FB), mATRIX_translateBits :: UB, - mATRIX_translateX :: SB, mATRIX_translateY :: SB} +data MATRIX = MATRIX{mATRIX_scale :: Maybe (FB, FB), + mATRIX_rotate :: Maybe (FB, FB), mATRIX_translateX :: SB, + mATRIX_translateY :: SB} deriving (Eq, Show, Typeable, Data) getMATRIX = do mATRIX_hasScale <- getFlag @@ -561,13 +561,13 @@ getMATRIX (do mATRIX_scaleBits <- getUB 5 mATRIX_scaleX <- getFB mATRIX_scaleBits mATRIX_scaleY <- getFB mATRIX_scaleBits - return (mATRIX_scaleBits, mATRIX_scaleX, mATRIX_scaleY)) + return (mATRIX_scaleX, mATRIX_scaleY)) mATRIX_hasRotate <- getFlag mATRIX_rotate <- maybeHas mATRIX_hasRotate (do mATRIX_rotateBits <- getUB 5 mATRIX_rotateSkew0 <- getFB mATRIX_rotateBits mATRIX_rotateSkew1 <- getFB mATRIX_rotateBits - return (mATRIX_rotateBits, mATRIX_rotateSkew0, mATRIX_rotateSkew1)) + return (mATRIX_rotateSkew0, mATRIX_rotateSkew1)) mATRIX_translateBits <- getUB 5 mATRIX_translateX <- getSB mATRIX_translateBits mATRIX_translateY <- getSB mATRIX_translateBits @@ -579,86 +579,61 @@ putMATRIX MATRIX{..} case mATRIX_scale of Just x | mATRIX_hasScale -> case x of - (mATRIX_scaleBits, mATRIX_scaleX, mATRIX_scaleY) -> do if - requiredBitsUB - mATRIX_scaleBits - <= 5 - then - putUB 5 - mATRIX_scaleBits - else - inconsistent - "fst (fromJust (mATRIX_scale (x :: MATRIX)))" - ("Bit count incorrect: required " - ++ - show - (requiredBitsUB - mATRIX_scaleBits) - ++ - " bits to store the value " - ++ - show - mATRIX_scaleBits - ++ - ", but only have available " - ++ - show - 5) - if - requiredBitsFB - mATRIX_scaleX - <= - mATRIX_scaleBits - then - putFB - mATRIX_scaleBits - mATRIX_scaleX - else - inconsistent - "snd (fromJust (mATRIX_scale (x :: MATRIX)))" - ("Bit count incorrect: required " - ++ - show - (requiredBitsFB - mATRIX_scaleX) - ++ - " bits to store the value " - ++ - show - mATRIX_scaleX - ++ - ", but only have available " - ++ - show - mATRIX_scaleBits) - if - requiredBitsFB - mATRIX_scaleY - <= - mATRIX_scaleBits - then - putFB - mATRIX_scaleBits - mATRIX_scaleY - else - inconsistent - "thd (fromJust (mATRIX_scale (x :: MATRIX)))" - ("Bit count incorrect: required " - ++ - show - (requiredBitsFB - mATRIX_scaleY) - ++ - " bits to store the value " - ++ - show - mATRIX_scaleY - ++ - ", but only have available " - ++ - show - mATRIX_scaleBits) - return () + (mATRIX_scaleX, mATRIX_scaleY) -> do let mATRIX_scaleBits + = requiredBitsFB mATRIX_scaleX + `max` + requiredBitsFB mATRIX_scaleY + if requiredBitsUB mATRIX_scaleBits <= 5 + then putUB 5 mATRIX_scaleBits else + inconsistent + "fromJust (mATRIX_scale (x :: MATRIX))" + ("Bit count incorrect: required " + ++ + show + (requiredBitsUB + mATRIX_scaleBits) + ++ + " bits to store the value " ++ + show mATRIX_scaleBits ++ + ", but only have available " + ++ show 5) + if + requiredBitsFB mATRIX_scaleX <= + mATRIX_scaleBits + then + putFB mATRIX_scaleBits mATRIX_scaleX + else + inconsistent + "fst (fromJust (mATRIX_scale (x :: MATRIX)))" + ("Bit count incorrect: required " + ++ + show + (requiredBitsFB mATRIX_scaleX) + ++ + " bits to store the value " ++ + show mATRIX_scaleX ++ + ", but only have available " + ++ + show mATRIX_scaleBits) + if + requiredBitsFB mATRIX_scaleY <= + mATRIX_scaleBits + then + putFB mATRIX_scaleBits mATRIX_scaleY + else + inconsistent + "snd (fromJust (mATRIX_scale (x :: MATRIX)))" + ("Bit count incorrect: required " + ++ + show + (requiredBitsFB mATRIX_scaleY) + ++ + " bits to store the value " ++ + show mATRIX_scaleY ++ + ", but only have available " + ++ + show mATRIX_scaleBits) + return () | otherwise -> inconsistent "mATRIX_scale (x :: MATRIX)" "Should have a Just iff mATRIX_hasScale is True" @@ -671,11 +646,14 @@ putMATRIX MATRIX{..} case mATRIX_rotate of Just x | mATRIX_hasRotate -> case x of - (mATRIX_rotateBits, mATRIX_rotateSkew0, - mATRIX_rotateSkew1) -> do if requiredBitsUB mATRIX_rotateBits <= 5 - then putUB 5 mATRIX_rotateBits else + (mATRIX_rotateSkew0, + mATRIX_rotateSkew1) -> do let mATRIX_rotateBits + = requiredBitsFB mATRIX_rotateSkew0 `max` + requiredBitsFB mATRIX_rotateSkew1 + if requiredBitsUB mATRIX_rotateBits <= 5 then + putUB 5 mATRIX_rotateBits else inconsistent - "fst (fromJust (mATRIX_rotate (x :: MATRIX)))" + "fromJust (mATRIX_rotate (x :: MATRIX))" ("Bit count incorrect: required " ++ show (requiredBitsUB mATRIX_rotateBits) ++ " bits to store the value " ++ @@ -688,7 +666,7 @@ putMATRIX MATRIX{..} then putFB mATRIX_rotateBits mATRIX_rotateSkew0 else inconsistent - "snd (fromJust (mATRIX_rotate (x :: MATRIX)))" + "fst (fromJust (mATRIX_rotate (x :: MATRIX)))" ("Bit count incorrect: required " ++ show (requiredBitsFB mATRIX_rotateSkew0) ++ @@ -702,7 +680,7 @@ putMATRIX MATRIX{..} then putFB mATRIX_rotateBits mATRIX_rotateSkew1 else inconsistent - "thd (fromJust (mATRIX_rotate (x :: MATRIX)))" + "snd (fromJust (mATRIX_rotate (x :: MATRIX)))" ("Bit count incorrect: required " ++ show (requiredBitsFB mATRIX_rotateSkew1) ++ @@ -718,9 +696,12 @@ putMATRIX MATRIX{..} inconsistent "mATRIX_rotate (x :: MATRIX)" "Should have a Nothing iff mATRIX_hasRotate is False" | otherwise -> return () + let mATRIX_translateBits + = requiredBitsSB mATRIX_translateX `max` + requiredBitsSB mATRIX_translateY if requiredBitsUB mATRIX_translateBits <= 5 then putUB 5 mATRIX_translateBits else - inconsistent "mATRIX_translateBits (x :: MATRIX)" + inconsistent "x :: MATRIX" ("Bit count incorrect: required " ++ show (requiredBitsUB mATRIX_translateBits) ++ " bits to store the value " ++ diff --git a/tests/DefineShapeAlignment.hs b/tests/DefineShapeAlignment.hs index 3ab9526..9478a4f 100644 --- a/tests/DefineShapeAlignment.hs +++ b/tests/DefineShapeAlignment.hs @@ -32,9 +32,8 @@ define_shape = DefineShape { GradientFill { fILLSTYLE_linearRadial = Linear, fILLSTYLE_gradientMatrix = MATRIX { - mATRIX_scale = Just (5,FIXED {fIXED_decimal = 9, fIXED_integer = 0},FIXED {fIXED_decimal = 13, fIXED_integer = 0}), - mATRIX_rotate = Just (16,FIXED {fIXED_decimal = 49822, fIXED_integer = 0},FIXED {fIXED_decimal = 24676, fIXED_integer = 0}), - mATRIX_translateBits = 15, + mATRIX_scale = Just (FIXED {fIXED_decimal = 9, fIXED_integer = 0},FIXED {fIXED_decimal = 13, fIXED_integer = 0}), + mATRIX_rotate = Just (FIXED {fIXED_decimal = 49822, fIXED_integer = 0},FIXED {fIXED_decimal = 24676, fIXED_integer = 0}), mATRIX_translateX = 5002, mATRIX_translateY = -10301 }, diff --git a/tests/SpecificationExample.hs b/tests/SpecificationExample.hs index 1dcfd88..9205910 100644 --- a/tests/SpecificationExample.hs +++ b/tests/SpecificationExample.hs @@ -101,7 +101,6 @@ swf = Swf { placeObject2_matrix = Just (MATRIX { mATRIX_scale = Nothing, mATRIX_rotate = Nothing, - mATRIX_translateBits = 0, mATRIX_translateX = 0, mATRIX_translateY = 0 }),