Package tv.porst.swfretools.parser.structures

Source Code of tv.porst.swfretools.parser.structures.GradientParser

package tv.porst.swfretools.parser.structures;

import static tv.porst.swfretools.parser.SWFParserHelpers.parseUBits;

import java.util.ArrayList;
import java.util.List;

import tv.porst.splib.binaryparser.UBits;
import tv.porst.swfretools.parser.SWFBinaryParser;
import tv.porst.swfretools.parser.SWFParserException;

/**
* Parses Gradient structures.
*
* @author sp
*/
public final class GradientParser {

  /**
   * Parses a Gradient structure.
   *
   * @param parser The parser that parses the structure.
   * @param fieldName Name of the structure in the parent structure.
   *
   * @return The parsed structure.
   *
   * @throws SWFParserException Thrown if the structure could not be parsed.
   */
  public static Gradient parse(final SWFBinaryParser parser, final String fieldName) throws SWFParserException {

    final UBits spreadMode = parseUBits(parser, 2, 0x00006, fieldName + "::SpreadMode");
    final UBits interpolationMode = parseUBits(parser, 2, 0x00006, fieldName + "::InterpolationMode");
    final UBits numGradients = parseUBits(parser, 4, 0x00006, fieldName + "::NumGradients");

    final List<GradRecord> gradientRecords = new ArrayList<GradRecord>();

    for (int i=0;i<numGradients.value();i++) {
      gradientRecords.add(GradRecordParser.parse(parser, String.format(fieldName + "::GradientRecord[%d]", i)));
    }

    return new Gradient(spreadMode, interpolationMode, numGradients, new GradRecordList(gradientRecords));
  }
}
TOP

Related Classes of tv.porst.swfretools.parser.structures.GradientParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.