function parseDDS(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, DDS_HEADER_LENGTH);

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

    if(!header[DDS_HEADER_PF_FLAGS] & DDPF_FOURCC) {
      errorCallback("Unsupported format, must contain a FourCC code");
      return 0;
    }

    // Determine what type of compressed data the file contains.
    var fourCC = header[DDS_HEADER_PF_FOURCC];
    var internalFormat;
    switch(fourCC) {
      case FOURCC_DXT1:
        internalFormat = COMPRESSED_RGB_S3TC_DXT1_EXT;
        break;

      case FOURCC_DXT3:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT3_EXT;
        break;

      case FOURCC_DXT5:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT5_EXT;
        break;

      case FOURCC_ATC:
        internalFormat = COMPRESSED_RGB_ATC_WEBGL;
        break;

      case FOURCC_ATCA:
        internalFormat = COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL;
        break;

      case FOURCC_ATCI:
        internalFormat = COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL;
        break;


      default:
        errorCallback("Unsupported FourCC code: " + int32ToFourCC(fourCC));
        return;
    }

    // Determine how many mipmap levels the file contains.
    var levels = 1;
    if(header[DDS_HEADER_FLAGS] & DDSD_MIPMAPCOUNT) {
      levels = Math.max(1, header[DDS_HEADER_MIPMAPCOUNT]);
    }

    // Gather other basic metrics and a view of the raw the DXT data.
    var width = header[DDS_HEADER_WIDTH];
    var height = header[DDS_HEADER_HEIGHT];
    var dataOffset = header[DDS_HEADER_SIZE] + 4;
    var dxtData = new Uint8Array(arrayBuffer, dataOffset);

    // Pass the DXT information to the callback for uploading.
    callback(dxtData, width, height, levels, internalFormat);
  }
// Parse a DDS file and provide information about the raw DXT data it contains to the given callback.
Parse a DDS file and provide information about the raw DXT data it contains to the given callback.
Parse a DDS file and provide information about the raw DXT data it contains to the given callback .
function parseDDS(arrayBuffer, callback, errorCallback) {
    if (!callback || !errorCallback) { return; }
    var header = new Int32Array(arrayBuffer, 0, DDS_HEADER_LENGTH);
    if(header[DDS_HEADER_MAGIC] != DDS_MAGIC) {
      errorCallback("Invalid magic number in DDS header");
      return 0;
    }
    if(!header[DDS_HEADER_PF_FLAGS] & DDPF_FOURCC) {
      errorCallback("Unsupported format, must contain a FourCC code");
      return 0;
    }
    var fourCC = header[DDS_HEADER_PF_FOURCC];
    var internalFormat;
    switch(fourCC) {
      case FOURCC_DXT1:
        internalFormat = COMPRESSED_RGB_S3TC_DXT1_EXT;
        break;
      case FOURCC_DXT3:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT3_EXT;
        break;
      case FOURCC_DXT5:
        internalFormat = COMPRESSED_RGBA_S3TC_DXT5_EXT;
        break;
      case FOURCC_ATC:
        internalFormat = COMPRESSED_RGB_ATC_WEBGL;
        break;
      case FOURCC_ATCA:
        internalFormat = COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL;
        break;
      case FOURCC_ATCI:
        internalFormat = COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL;
        break;
      default:
        errorCallback("Unsupported FourCC code: " + int32ToFourCC(fourCC));
        return;
    }
    var levels = 1;
    if(header[DDS_HEADER_FLAGS] & DDSD_MIPMAPCOUNT) {
      levels = Math.max(1, header[DDS_HEADER_MIPMAPCOUNT]);
    }
    var width = header[DDS_HEADER_WIDTH];
    var height = header[DDS_HEADER_HEIGHT];
    var dataOffset = header[DDS_HEADER_SIZE] + 4;
    var dxtData = new Uint8Array(arrayBuffer, dataOffset);
    callback(dxtData, width, height, levels, internalFormat);
  }
function parseDDS ( arrayBuffer , callback , errorCallback ) { if ( ! callback || ! errorCallback ) { return ; } var header = new Int32Array ( arrayBuffer , 0 , DDS_HEADER_LENGTH ) ; if ( header [ DDS_HEADER_MAGIC ] != DDS_MAGIC ) { errorCallback ( "Invalid magic number in DDS header" ) ; return 0 ; } if ( ! header [ DDS_HEADER_PF_FLAGS ] & DDPF_FOURCC ) { errorCallback ( "Unsupported format, must contain a FourCC code" ) ; return 0 ; } var fourCC = header [ DDS_HEADER_PF_FOURCC ] ; var internalFormat ; switch ( fourCC ) { case FOURCC_DXT1 : internalFormat = COMPRESSED_RGB_S3TC_DXT1_EXT ; break ; case FOURCC_DXT3 : internalFormat = COMPRESSED_RGBA_S3TC_DXT3_EXT ; break ; case FOURCC_DXT5 : internalFormat = COMPRESSED_RGBA_S3TC_DXT5_EXT ; break ; case FOURCC_ATC : internalFormat = COMPRESSED_RGB_ATC_WEBGL ; break ; case FOURCC_ATCA : internalFormat = COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL ; break ; case FOURCC_ATCI : internalFormat = COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL ; break ; default : errorCallback ( "Unsupported FourCC code: " + int32ToFourCC ( fourCC ) ) ; return ; } var levels = 1 ; if ( header [ DDS_HEADER_FLAGS ] & DDSD_MIPMAPCOUNT ) { levels = Math . max ( 1 , header [ DDS_HEADER_MIPMAPCOUNT ] ) ; } var width = header [ DDS_HEADER_WIDTH ] ; var height = header [ DDS_HEADER_HEIGHT ] ; var dataOffset = header [ DDS_HEADER_SIZE ] + 4 ; var dxtData = new Uint8Array ( arrayBuffer , dataOffset ) ; callback ( dxtData , width , height , levels , internalFormat ) ; }
Parse a DDS file and provide information about the raw DXT data it contains to the given callback.
Parse a DDS file and provide information about the raw DXT 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. // Determine how many mipmap levels the file contains. // Gather other basic metrics and a view of the raw the DXT data. // Pass the DXT information to the callback for uploading.