/// Format of the bit-packed rectangle is: /// /// bits | name | description /// ------+-------+------------------------- /// 5 | nbits | number of bits used in subsequent values /// nbits | xmin | minimum X value /// nbits | xmax | maximum X value /// nbits | ymin | minimum Y value /// nbits | ymax | maximum Y value /// /// If max values are less then min values the SWF is malformed; /// in this case this method will raise an swf_error and set the /// rectangle to the NULL rectangle. See is_null(). SWFRect readRect(SWFStream& in) { in.align(); in.ensureBits(5); const int nbits = in.read_uint(5); int minx = 0, maxx = 0, miny = 0, maxy = 0; if (nbits > 0) { in.ensureBits(nbits*4); minx = in.read_sint(nbits); maxx = in.read_sint(nbits); miny = in.read_sint(nbits); maxy = in.read_sint(nbits); } // Check if this SWFRect is valid. if (maxx < minx || maxy < miny) { // We set invalid rectangles to NULL, but we might instead // want to actually swap the values if the proprietary player // does so. TODO: check it out. IF_VERBOSE_MALFORMED_SWF( log_swferror(_("Invalid rectangle: " "minx=%g maxx=%g miny=%g maxy=%g"), minx, maxx, miny, maxy); );
SWFMatrix readSWFMatrix(SWFStream& in) { in.align(); in.ensureBits(1); const bool has_scale = in.read_bit(); std::int32_t sx = 65536; std::int32_t sy = 65536; if (has_scale) { in.ensureBits(5); const std::uint8_t scale_nbits = in.read_uint(5); if (scale_nbits) { in.ensureBits(scale_nbits * 2); sx = in.read_sint(scale_nbits); sy = in.read_sint(scale_nbits); } } in.ensureBits(1); const bool has_rotate = in.read_bit(); std::int32_t shx = 0; std::int32_t shy = 0; if (has_rotate) { in.ensureBits(5); unsigned int rotate_nbits = in.read_uint(5); if (rotate_nbits) { in.ensureBits(rotate_nbits * 2); shx = in.read_sint(rotate_nbits); shy = in.read_sint(rotate_nbits); } } in.ensureBits(5); const std::uint8_t translate_nbits = in.read_uint(5); std::int32_t tx = 0; std::int32_t ty = 0; if (translate_nbits) { in.ensureBits(translate_nbits * 2); tx = in.read_sint(translate_nbits); ty = in.read_sint(translate_nbits); } return SWFMatrix(sx, shx, shy, sy, tx, ty); }