function parsePVR(arrayBuffer, callback, errorCallback) {
    // Callbacks must be provided.
    if (!callback || !errorCallback) { return; }

    // Get a view of the arrayBuffer that represents the DDS header.
    var header = new Int32Array(arrayBuffer, 0, PVR_HEADER_LENGTH);

    // Do some sanity checks to make sure this is a valid DDS file.
    if(header[PVR_HEADER_MAGIC] != PVR_MAGIC) {
      errorCallback("Invalid magic number in PVR header");
      return 0;
    }

    // Determine what type of compressed data the file contains.
    var format = header[PVR_HEADER_FORMAT];
    var internalFormat;
    switch(format) {
      case PVR_FORMAT_2BPP_RGB:
        internalFormat = COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
        break;

      case PVR_FORMAT_2BPP_RGBA:
        internalFormat = COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
        break;

      case PVR_FORMAT_4BPP_RGB:
        internalFormat = COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
        break;

      case PVR_FORMAT_4BPP_RGBA:
        internalFormat = COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
        break;

      case PVR_FORMAT_ETC1:
        internalFormat = COMPRESSED_RGB_ETC1_WEBGL;
        break;

      case PVR_FORMAT_DXT1:
        internalFormat = COMPRESSED_RGB_S3TC_DXT1_EXT;
        break;

      case PVR_FORMAT_DXT3:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT3_EXT;
        break;

      case PVR_FORMAT_DXT5:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT5_EXT;
        break;

      default:
        errorCallback("Unsupported PVR format: " + format);
        return;
    }

    // Gather other basic metrics and a view of the raw the DXT data.
    var width = header[PVR_HEADER_WIDTH];
    var height = header[PVR_HEADER_HEIGHT];
    var levels = header[PVR_HEADER_MIPMAPCOUNT];
    var dataOffset = header[PVR_HEADER_METADATA] + 52;
    var pvrtcData = new Uint8Array(arrayBuffer, dataOffset);

    // Pass the PVRTC information to the callback for uploading.
    callback(pvrtcData, width, height, levels, internalFormat);
  }
// Parse a PVR file and provide information about the raw texture data it contains to the given callback.
Parse a PVR file and provide information about the raw texture data it contains to the given callback.
Parse a PVR file and provide information about the raw texture data it contains to the given callback .
function parsePVR(arrayBuffer, callback, errorCallback) {
    if (!callback || !errorCallback) { return; }
    var header = new Int32Array(arrayBuffer, 0, PVR_HEADER_LENGTH);
    if(header[PVR_HEADER_MAGIC] != PVR_MAGIC) {
      errorCallback("Invalid magic number in PVR header");
      return 0;
    }
    var format = header[PVR_HEADER_FORMAT];
    var internalFormat;
    switch(format) {
      case PVR_FORMAT_2BPP_RGB:
        internalFormat = COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
        break;
      case PVR_FORMAT_2BPP_RGBA:
        internalFormat = COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
        break;
      case PVR_FORMAT_4BPP_RGB:
        internalFormat = COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
        break;
      case PVR_FORMAT_4BPP_RGBA:
        internalFormat = COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
        break;
      case PVR_FORMAT_ETC1:
        internalFormat = COMPRESSED_RGB_ETC1_WEBGL;
        break;
      case PVR_FORMAT_DXT1:
        internalFormat = COMPRESSED_RGB_S3TC_DXT1_EXT;
        break;
      case PVR_FORMAT_DXT3:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT3_EXT;
        break;
      case PVR_FORMAT_DXT5:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT5_EXT;
        break;
      default:
        errorCallback("Unsupported PVR format: " + format);
        return;
    }
    var width = header[PVR_HEADER_WIDTH];
    var height = header[PVR_HEADER_HEIGHT];
    var levels = header[PVR_HEADER_MIPMAPCOUNT];
    var dataOffset = header[PVR_HEADER_METADATA] + 52;
    var pvrtcData = new Uint8Array(arrayBuffer, dataOffset);
    callback(pvrtcData, width, height, levels, internalFormat);
  }
function parsePVR ( arrayBuffer , callback , errorCallback ) { if ( ! callback || ! errorCallback ) { return ; } var header = new Int32Array ( arrayBuffer , 0 , PVR_HEADER_LENGTH ) ; if ( header [ PVR_HEADER_MAGIC ] != PVR_MAGIC ) { errorCallback ( "Invalid magic number in PVR header" ) ; return 0 ; } var format = header [ PVR_HEADER_FORMAT ] ; var internalFormat ; switch ( format ) { case PVR_FORMAT_2BPP_RGB : internalFormat = COMPRESSED_RGB_PVRTC_2BPPV1_IMG ; break ; case PVR_FORMAT_2BPP_RGBA : internalFormat = COMPRESSED_RGBA_PVRTC_2BPPV1_IMG ; break ; case PVR_FORMAT_4BPP_RGB : internalFormat = COMPRESSED_RGB_PVRTC_4BPPV1_IMG ; break ; case PVR_FORMAT_4BPP_RGBA : internalFormat = COMPRESSED_RGBA_PVRTC_4BPPV1_IMG ; break ; case PVR_FORMAT_ETC1 : internalFormat = COMPRESSED_RGB_ETC1_WEBGL ; break ; case PVR_FORMAT_DXT1 : internalFormat = COMPRESSED_RGB_S3TC_DXT1_EXT ; break ; case PVR_FORMAT_DXT3 : internalFormat = COMPRESSED_RGBA_S3TC_DXT3_EXT ; break ; case PVR_FORMAT_DXT5 : internalFormat = COMPRESSED_RGBA_S3TC_DXT5_EXT ; break ; default : errorCallback ( "Unsupported PVR format: " + format ) ; return ; } var width = header [ PVR_HEADER_WIDTH ] ; var height = header [ PVR_HEADER_HEIGHT ] ; var levels = header [ PVR_HEADER_MIPMAPCOUNT ] ; var dataOffset = header [ PVR_HEADER_METADATA ] + 52 ; var pvrtcData = new Uint8Array ( arrayBuffer , dataOffset ) ; callback ( pvrtcData , width , height , levels , internalFormat ) ; }
Parse a PVR file and provide information about the raw texture data it contains to the given callback.
Parse a PVR file and provide information about the raw texture data it contains to the given callback .
// Callbacks must be provided. // Get a view of the arrayBuffer that represents the DDS header. // Do some sanity checks to make sure this is a valid DDS file. // Determine what type of compressed data the file contains. // Gather other basic metrics and a view of the raw the DXT data. // Pass the PVRTC information to the callback for uploading.