starling-framework
Version:
A fast, productive library for 2D cross-platform development.
100 lines (84 loc) • 3.27 kB
JavaScript
// Class: starling.textures.AtfData
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../hxClasses_stub").default;
var $import = require("./../../import_stub").default;
function _$UInt_UInt_$Impl_$() {return require("./../../_UInt/UInt_Impl_");}
function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");}
function openfl_errors_ArgumentError() {return $import(require("openfl/errors/ArgumentError"));}
function openfl_errors_Error() {return $import(require("openfl/errors/Error"));}
function Std() {return require("./../../Std");}
// Constructor
var AtfData = function(data) {
if(!AtfData.isAtfData(data)) {
throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("Invalid ATF data"));
}
if(data.get(6) == 255) {
data.position = 12;
} else {
data.position = 6;
}
var format = data.readUnsignedByte();
var _g = format & 127;
switch(_g) {
case 0:case 1:
this._format = "bgra";
break;
case 2:case 3:case 12:
this._format = "compressed";
break;
case 4:case 5:case 13:
this._format = "compressedAlpha";
break;
default:
throw new (js__$Boot_HaxeError().default)(new (openfl_errors_Error().default)("Invalid ATF format"));
}
this._width = (Std().default)["int"](Math.pow(2,(_$UInt_UInt_$Impl_$().default).toFloat(data.readUnsignedByte())));
this._height = (Std().default)["int"](Math.pow(2,(_$UInt_UInt_$Impl_$().default).toFloat(data.readUnsignedByte())));
this._numTextures = data.readUnsignedByte();
this._isCubeMap = (format & 128) != 0;
this._data = data;
if(data.get(5) != 0 && data.get(6) == 255) {
var emptyMipmaps = (data.get(5) & 1) == 1;
var numTextures = data.get(5) >> 1 & 127;
this._numTextures = emptyMipmaps ? 1 : numTextures;
}
}
// Meta
AtfData.__name__ = ["starling","textures","AtfData"];
AtfData.prototype = {
get_format: function() {
return this._format;
},
get_width: function() {
return this._width;
},
get_height: function() {
return this._height;
},
get_numTextures: function() {
return this._numTextures;
},
get_isCubeMap: function() {
return this._isCubeMap;
},
get_data: function() {
return this._data;
}
};
AtfData.prototype.__class__ = AtfData.prototype.constructor = $hxClasses["starling.textures.AtfData"] = AtfData;
// Init
Object.defineProperties(AtfData.prototype,{ "format" : { get : function () { return this.get_format (); }}, "width" : { get : function () { return this.get_width (); }}, "height" : { get : function () { return this.get_height (); }}, "numTextures" : { get : function () { return this.get_numTextures (); }}, "isCubeMap" : { get : function () { return this.get_isCubeMap (); }}, "data" : { get : function () { return this.get_data (); }}});
// Statics
AtfData.isAtfData = function(data) {
if((_$UInt_UInt_$Impl_$().default).gt(3,data.length)) {
return false;
} else {
var signature = String.fromCharCode(data.get(0)) + String.fromCharCode(data.get(1)) + String.fromCharCode(data.get(2));
return signature == "ATF";
}
}
// Export
exports.default = AtfData;