// Compiled by ClojureScript 1.9.562 {}
goog.provide('weathergen.falcon.files.images');
goog.require('cljs.core');
goog.require('taoensso.timbre');
goog.require('octet.core');
goog.require('weathergen.falcon.constants');
goog.require('weathergen.filesystem');
goog.require('weathergen.util');
weathergen.falcon.files.images.read_index = cljs.core.memoize.call(null,(function (path){
var common_header = octet.core.spec.call(null,new cljs.core.Keyword(null,"type","type",1174270348),octet.core.int32,new cljs.core.Keyword(null,"id","id",-1388402092),octet.core.string.call(null,(32)));
var image_header = octet.core.spec.call(null,new cljs.core.Keyword(null,"flags","flags",1775418075),octet.core.int32,new cljs.core.Keyword(null,"center","center",-748944368),octet.core.repeat.call(null,(2),octet.core.int16),new cljs.core.Keyword(null,"size","size",1098693007),octet.core.repeat.call(null,(2),octet.core.int16),new cljs.core.Keyword(null,"image-offset","image-offset",-1802347612),octet.core.int32,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822),octet.core.int32,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573),octet.core.int32);
var sound_header = octet.core.spec.call(null,new cljs.core.Keyword(null,"flags","flags",1775418075),octet.core.int32,new cljs.core.Keyword(null,"channels","channels",1132759174),octet.core.int16,new cljs.core.Keyword(null,"sound-type","sound-type",-1070198063),octet.core.int16,new cljs.core.Keyword(null,"offset","offset",296498311),octet.core.int32,new cljs.core.Keyword(null,"header-size","header-size",-111873897),octet.core.int32);
var flat_header = octet.core.spec.call(null,new cljs.core.Keyword(null,"offset","offset",296498311),octet.core.int32,new cljs.core.Keyword(null,"size","size",1098693007),octet.core.int32);
var file_header = octet.core.spec.call(null,new cljs.core.Keyword(null,"size","size",1098693007),octet.core.int32,new cljs.core.Keyword(null,"version","version",425292698),octet.core.int32);
var idx_buf = weathergen.filesystem.file_buf.call(null,path);
var _STAR_byte_order_STAR_34776 = octet.buffer._STAR_byte_order_STAR_;
octet.buffer._STAR_byte_order_STAR_ = new cljs.core.Keyword(null,"little-endian","little-endian",1877303413);

try{var map__34777 = octet.core.read.call(null,idx_buf,file_header);
var map__34777__$1 = ((((!((map__34777 == null)))?((((map__34777.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34777.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34777):map__34777);
var size = cljs.core.get.call(null,map__34777__$1,new cljs.core.Keyword(null,"size","size",1098693007));
var offset = octet.core.size.call(null,file_header);
var items = cljs.core.PersistentVector.EMPTY;
while(true){
if(!(((size - offset) > (0)))){
return items;
} else {
var vec__34779 = octet.core.read_STAR_.call(null,idx_buf,common_header,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"offset","offset",296498311),offset], null));
var size__$1 = cljs.core.nth.call(null,vec__34779,(0),null);
var common = cljs.core.nth.call(null,vec__34779,(1),null);
var offset__$1 = (offset + size__$1);
var vec__34782 = octet.core.read_STAR_.call(null,idx_buf,(function (){var pred__34785 = cljs.core._EQ_;
var expr__34786 = new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(common);
if(cljs.core.truth_(pred__34785.call(null,weathergen.falcon.constants._RSC_IS_IMAGE_,expr__34786))){
return image_header;
} else {
if(cljs.core.truth_(pred__34785.call(null,weathergen.falcon.constants._RSC_IS_SOUND_,expr__34786))){
return sound_header;
} else {
if(cljs.core.truth_(pred__34785.call(null,weathergen.falcon.constants._RSC_IS_FLAT_,expr__34786))){
return flat_header;
} else {
throw (new Error([cljs.core.str.cljs$core$IFn$_invoke$arity$1("No matching clause: "),cljs.core.str.cljs$core$IFn$_invoke$arity$1(expr__34786)].join('')));
}
}
}
})(),new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"offset","offset",296498311),offset__$1], null));
var size__$2 = cljs.core.nth.call(null,vec__34782,(0),null);
var specifics = cljs.core.nth.call(null,vec__34782,(1),null);
var G__34788 = (offset__$1 + size__$2);
var G__34789 = cljs.core.conj.call(null,items,cljs.core.into.call(null,common,specifics));
offset = G__34788;
items = G__34789;
continue;
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34776;
}}));
weathergen.falcon.files.images.palette = (function weathergen$falcon$files$images$palette(image_buf,image_data){
var map__34793 = image_data;
var map__34793__$1 = ((((!((map__34793 == null)))?((((map__34793.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34793.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34793):map__34793);
var palette_size = cljs.core.get.call(null,map__34793__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34793__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var _STAR_byte_order_STAR_34795 = octet.buffer._STAR_byte_order_STAR_;
octet.buffer._STAR_byte_order_STAR_ = new cljs.core.Keyword(null,"little-endian","little-endian",1877303413);

try{return octet.core.read.call(null,image_buf,octet.core.repeat.call(null,palette_size,octet.core.uint16),new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"offset","offset",296498311),(palette_offset + (8))], null));
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34795;
}});
/**
 * Reads image described by `image-descriptor`. `allocator` is a
 *   function of a width and height. It returns a map of two functions.
 *   The function under `:set-pixel!` will be called with x, y, and argb
 *   for each pixel in the image, where argb is a long in 0xAABBGGRR
 *   format. The function under the `:finalize` key will be called with
 *   no arguments after all pixels are set. `read-image` returns the
 *   result of calling the finalize function.
 */
weathergen.falcon.files.images.read_image = (function weathergen$falcon$files$images$read_image(mission,image_descriptor,allocator){
var map__34818 = image_descriptor;
var map__34818__$1 = ((((!((map__34818 == null)))?((((map__34818.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34818.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34818):map__34818);
var resource = cljs.core.get.call(null,map__34818__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34818__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var base = cljs.core.get.call(null,map__34818__$1,new cljs.core.Keyword(null,"base","base",185279322));
var image_data = cljs.core.get.call(null,map__34818__$1,new cljs.core.Keyword(null,"image-data","image-data",-377483758));
var image_buf = weathergen.filesystem.file_buf.call(null,[cljs.core.str.cljs$core$IFn$_invoke$arity$1(base),cljs.core.str.cljs$core$IFn$_invoke$arity$1(".rsc")].join(''));
var palette = weathergen.falcon.files.images.palette.call(null,image_buf,image_data);
var map__34819 = image_data;
var map__34819__$1 = ((((!((map__34819 == null)))?((((map__34819.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34819.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34819):map__34819);
var palette_size = cljs.core.get.call(null,map__34819__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34819__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var center = cljs.core.get.call(null,map__34819__$1,new cljs.core.Keyword(null,"center","center",-748944368));
var image_offset = cljs.core.get.call(null,map__34819__$1,new cljs.core.Keyword(null,"image-offset","image-offset",-1802347612));
var size = cljs.core.get.call(null,map__34819__$1,new cljs.core.Keyword(null,"size","size",1098693007));
var is_8_bit_QMARK_ = weathergen.util.has_flag_QMARK_.call(null,new cljs.core.Keyword(null,"flags","flags",1775418075).cljs$core$IFn$_invoke$arity$1(image_data),weathergen.falcon.constants._RSC_8_BIT_);
var use_transparency_QMARK_ = weathergen.util.has_flag_QMARK_.call(null,new cljs.core.Keyword(null,"flags","flags",1775418075).cljs$core$IFn$_invoke$arity$1(image_data),weathergen.falcon.constants._RSC_USECOLORKEY_);
var vec__34820 = size;
var width = cljs.core.nth.call(null,vec__34820,(0),null);
var height = cljs.core.nth.call(null,vec__34820,(1),null);
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"debug","debug",-1608172596),"weathergen.falcon.files.images",null,94,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay(((function (map__34818,map__34818__$1,resource,image_id,base,image_data,image_buf,palette,map__34819,map__34819__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34820,width,height){
return (function (){
return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, ["read-image",new cljs.core.Keyword(null,"image-descriptor","image-descriptor",-1531626249),image_descriptor], null);
});})(map__34818,map__34818__$1,resource,image_id,base,image_data,image_buf,palette,map__34819,map__34819__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34820,width,height))
,null)),null,-1225932056);

if(cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(image_data),weathergen.falcon.constants._RSC_IS_IMAGE_)){
} else {
throw cljs.core.ex_info.call(null,"Not an image",new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"reason","reason",-2070751759),new cljs.core.Keyword("weathergen.falcon.files.images","not-an-image","weathergen.falcon.files.images/not-an-image",-961229360)], null));
}

if((cljs.core.not.call(null,is_8_bit_QMARK_)) && (cljs.core.not.call(null,weathergen.util.has_flag_QMARK_.call(null,new cljs.core.Keyword(null,"flags","flags",1775418075).cljs$core$IFn$_invoke$arity$1(image_data),weathergen.falcon.constants._RSC_16_BIT_)))){
throw cljs.core.ex_info.call(null,"Image is neither 8-bit nor 16-bit",new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"reason","reason",-2070751759),new cljs.core.Keyword("weathergen.falcon.files.images","bit-size-unknown","weathergen.falcon.files.images/bit-size-unknown",1319239173)], null));
} else {
}

var map__34825 = allocator.call(null,width,height);
var map__34825__$1 = ((((!((map__34825 == null)))?((((map__34825.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34825.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34825):map__34825);
var set_pixel_BANG_ = cljs.core.get.call(null,map__34825__$1,new cljs.core.Keyword(null,"set-pixel!","set-pixel!",1287500897));
var finalize = cljs.core.get.call(null,map__34825__$1,new cljs.core.Keyword(null,"finalize","finalize",-1152897571));
var pixel_bytes = (cljs.core.truth_(is_8_bit_QMARK_)?(1):(2));
var read_pixel = (cljs.core.truth_(is_8_bit_QMARK_)?octet.buffer.read_ubyte:octet.buffer.read_ushort);
var _STAR_byte_order_STAR_34827_34840 = octet.buffer._STAR_byte_order_STAR_;
octet.buffer._STAR_byte_order_STAR_ = new cljs.core.Keyword(null,"little-endian","little-endian",1877303413);

try{var seq__34828_34841 = cljs.core.seq.call(null,cljs.core.range.call(null,height));
var chunk__34833_34842 = null;
var count__34834_34843 = (0);
var i__34835_34844 = (0);
while(true){
if((i__34835_34844 < count__34834_34843)){
var y_34845 = cljs.core._nth.call(null,chunk__34833_34842,i__34835_34844);
var seq__34836_34846 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34837_34847 = null;
var count__34838_34848 = (0);
var i__34839_34849 = (0);
while(true){
if((i__34839_34849 < count__34838_34848)){
var x_34850 = cljs.core._nth.call(null,chunk__34837_34847,i__34839_34849);
var offset_34851 = (((8) + image_offset) + (pixel_bytes * (x_34850 + (y_34845 * width))));
var c_34852 = read_pixel.call(null,image_buf,offset_34851);
var raw_34853 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34852):c_34852);
var r_34854 = ((raw_34853 >> (10)) & (31));
var g_34855 = ((raw_34853 >> (5)) & (31));
var b_34856 = (raw_34853 & (31));
var transparent_QMARK__34857 = (function (){var and__23136__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23136__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34852 === (0));
} else {
return cljs.core._EQ_.call(null,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [(31),(0),(31)], null),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [r_34854,g_34855,b_34856], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34858 = (((((((cljs.core.truth_(transparent_QMARK__34857)?(0):(255)) << (8)) + (b_34856 * (8))) << (8)) + (g_34855 * (8))) << (8)) + (r_34854 * (8)));
set_pixel_BANG_.call(null,x_34850,y_34845,argb_34858);

var G__34859 = seq__34836_34846;
var G__34860 = chunk__34837_34847;
var G__34861 = count__34838_34848;
var G__34862 = (i__34839_34849 + (1));
seq__34836_34846 = G__34859;
chunk__34837_34847 = G__34860;
count__34838_34848 = G__34861;
i__34839_34849 = G__34862;
continue;
} else {
var temp__5278__auto___34863 = cljs.core.seq.call(null,seq__34836_34846);
if(temp__5278__auto___34863){
var seq__34836_34864__$1 = temp__5278__auto___34863;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34836_34864__$1)){
var c__24059__auto___34865 = cljs.core.chunk_first.call(null,seq__34836_34864__$1);
var G__34866 = cljs.core.chunk_rest.call(null,seq__34836_34864__$1);
var G__34867 = c__24059__auto___34865;
var G__34868 = cljs.core.count.call(null,c__24059__auto___34865);
var G__34869 = (0);
seq__34836_34846 = G__34866;
chunk__34837_34847 = G__34867;
count__34838_34848 = G__34868;
i__34839_34849 = G__34869;
continue;
} else {
var x_34870 = cljs.core.first.call(null,seq__34836_34864__$1);
var offset_34871 = (((8) + image_offset) + (pixel_bytes * (x_34870 + (y_34845 * width))));
var c_34872 = read_pixel.call(null,image_buf,offset_34871);
var raw_34873 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34872):c_34872);
var r_34874 = ((raw_34873 >> (10)) & (31));
var g_34875 = ((raw_34873 >> (5)) & (31));
var b_34876 = (raw_34873 & (31));
var transparent_QMARK__34877 = (function (){var and__23136__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23136__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34872 === (0));
} else {
return cljs.core._EQ_.call(null,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [(31),(0),(31)], null),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [r_34874,g_34875,b_34876], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34878 = (((((((cljs.core.truth_(transparent_QMARK__34877)?(0):(255)) << (8)) + (b_34876 * (8))) << (8)) + (g_34875 * (8))) << (8)) + (r_34874 * (8)));
set_pixel_BANG_.call(null,x_34870,y_34845,argb_34878);

var G__34879 = cljs.core.next.call(null,seq__34836_34864__$1);
var G__34880 = null;
var G__34881 = (0);
var G__34882 = (0);
seq__34836_34846 = G__34879;
chunk__34837_34847 = G__34880;
count__34838_34848 = G__34881;
i__34839_34849 = G__34882;
continue;
}
} else {
}
}
break;
}

var G__34883 = seq__34828_34841;
var G__34884 = chunk__34833_34842;
var G__34885 = count__34834_34843;
var G__34886 = (i__34835_34844 + (1));
seq__34828_34841 = G__34883;
chunk__34833_34842 = G__34884;
count__34834_34843 = G__34885;
i__34835_34844 = G__34886;
continue;
} else {
var temp__5278__auto___34887 = cljs.core.seq.call(null,seq__34828_34841);
if(temp__5278__auto___34887){
var seq__34828_34888__$1 = temp__5278__auto___34887;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34828_34888__$1)){
var c__24059__auto___34889 = cljs.core.chunk_first.call(null,seq__34828_34888__$1);
var G__34890 = cljs.core.chunk_rest.call(null,seq__34828_34888__$1);
var G__34891 = c__24059__auto___34889;
var G__34892 = cljs.core.count.call(null,c__24059__auto___34889);
var G__34893 = (0);
seq__34828_34841 = G__34890;
chunk__34833_34842 = G__34891;
count__34834_34843 = G__34892;
i__34835_34844 = G__34893;
continue;
} else {
var y_34894 = cljs.core.first.call(null,seq__34828_34888__$1);
var seq__34829_34895 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34830_34896 = null;
var count__34831_34897 = (0);
var i__34832_34898 = (0);
while(true){
if((i__34832_34898 < count__34831_34897)){
var x_34899 = cljs.core._nth.call(null,chunk__34830_34896,i__34832_34898);
var offset_34900 = (((8) + image_offset) + (pixel_bytes * (x_34899 + (y_34894 * width))));
var c_34901 = read_pixel.call(null,image_buf,offset_34900);
var raw_34902 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34901):c_34901);
var r_34903 = ((raw_34902 >> (10)) & (31));
var g_34904 = ((raw_34902 >> (5)) & (31));
var b_34905 = (raw_34902 & (31));
var transparent_QMARK__34906 = (function (){var and__23136__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23136__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34901 === (0));
} else {
return cljs.core._EQ_.call(null,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [(31),(0),(31)], null),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [r_34903,g_34904,b_34905], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34907 = (((((((cljs.core.truth_(transparent_QMARK__34906)?(0):(255)) << (8)) + (b_34905 * (8))) << (8)) + (g_34904 * (8))) << (8)) + (r_34903 * (8)));
set_pixel_BANG_.call(null,x_34899,y_34894,argb_34907);

var G__34908 = seq__34829_34895;
var G__34909 = chunk__34830_34896;
var G__34910 = count__34831_34897;
var G__34911 = (i__34832_34898 + (1));
seq__34829_34895 = G__34908;
chunk__34830_34896 = G__34909;
count__34831_34897 = G__34910;
i__34832_34898 = G__34911;
continue;
} else {
var temp__5278__auto___34912__$1 = cljs.core.seq.call(null,seq__34829_34895);
if(temp__5278__auto___34912__$1){
var seq__34829_34913__$1 = temp__5278__auto___34912__$1;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34829_34913__$1)){
var c__24059__auto___34914 = cljs.core.chunk_first.call(null,seq__34829_34913__$1);
var G__34915 = cljs.core.chunk_rest.call(null,seq__34829_34913__$1);
var G__34916 = c__24059__auto___34914;
var G__34917 = cljs.core.count.call(null,c__24059__auto___34914);
var G__34918 = (0);
seq__34829_34895 = G__34915;
chunk__34830_34896 = G__34916;
count__34831_34897 = G__34917;
i__34832_34898 = G__34918;
continue;
} else {
var x_34919 = cljs.core.first.call(null,seq__34829_34913__$1);
var offset_34920 = (((8) + image_offset) + (pixel_bytes * (x_34919 + (y_34894 * width))));
var c_34921 = read_pixel.call(null,image_buf,offset_34920);
var raw_34922 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34921):c_34921);
var r_34923 = ((raw_34922 >> (10)) & (31));
var g_34924 = ((raw_34922 >> (5)) & (31));
var b_34925 = (raw_34922 & (31));
var transparent_QMARK__34926 = (function (){var and__23136__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23136__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34921 === (0));
} else {
return cljs.core._EQ_.call(null,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [(31),(0),(31)], null),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [r_34923,g_34924,b_34925], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34927 = (((((((cljs.core.truth_(transparent_QMARK__34926)?(0):(255)) << (8)) + (b_34925 * (8))) << (8)) + (g_34924 * (8))) << (8)) + (r_34923 * (8)));
set_pixel_BANG_.call(null,x_34919,y_34894,argb_34927);

var G__34928 = cljs.core.next.call(null,seq__34829_34913__$1);
var G__34929 = null;
var G__34930 = (0);
var G__34931 = (0);
seq__34829_34895 = G__34928;
chunk__34830_34896 = G__34929;
count__34831_34897 = G__34930;
i__34832_34898 = G__34931;
continue;
}
} else {
}
}
break;
}

var G__34932 = cljs.core.next.call(null,seq__34828_34888__$1);
var G__34933 = null;
var G__34934 = (0);
var G__34935 = (0);
seq__34828_34841 = G__34932;
chunk__34833_34842 = G__34933;
count__34834_34843 = G__34934;
i__34835_34844 = G__34935;
continue;
}
} else {
}
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34827_34840;
}
return finalize.call(null);
});
/**
 * Return a string unique to this image. Intended to be used as a key
 *   for caching across sessions.
 */
weathergen.falcon.files.images.cache_key = (function weathergen$falcon$files$images$cache_key(image_descriptor){
var map__34938 = image_descriptor;
var map__34938__$1 = ((((!((map__34938 == null)))?((((map__34938.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34938.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34938):map__34938);
var resource = cljs.core.get.call(null,map__34938__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34938__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var art_dir = cljs.core.get.call(null,map__34938__$1,new cljs.core.Keyword(null,"art-dir","art-dir",67381390));
var idx_size = cljs.core.get.call(null,map__34938__$1,new cljs.core.Keyword(null,"idx-size","idx-size",893862481));
var idx_modified = cljs.core.get.call(null,map__34938__$1,new cljs.core.Keyword(null,"idx-modified","idx-modified",-1917929304));
var rsc_size = cljs.core.get.call(null,map__34938__$1,new cljs.core.Keyword(null,"rsc-size","rsc-size",-568560687));
var rsc_modified = cljs.core.get.call(null,map__34938__$1,new cljs.core.Keyword(null,"rsc-modified","rsc-modified",-250537226));
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(art_dir),cljs.core.str.cljs$core$IFn$_invoke$arity$1("/"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(resource),cljs.core.str.cljs$core$IFn$_invoke$arity$1("/"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(image_id),cljs.core.str.cljs$core$IFn$_invoke$arity$1("/"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(idx_size),cljs.core.str.cljs$core$IFn$_invoke$arity$1("-"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(idx_modified),cljs.core.str.cljs$core$IFn$_invoke$arity$1("-"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(rsc_size),cljs.core.str.cljs$core$IFn$_invoke$arity$1("-"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(rsc_modified)].join('');
});
/**
 * Creates an image descriptor.
 */
weathergen.falcon.files.images.make_descriptor = (function weathergen$falcon$files$images$make_descriptor(mission,resource,image_id){
var data_dir = new cljs.core.Keyword(null,"data-dir","data-dir",2038801936).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"installation","installation",943147954).cljs$core$IFn$_invoke$arity$1(mission));
var theater_art_dir = new cljs.core.Keyword(null,"art-dir","art-dir",67381390).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"theater","theater",258922071).cljs$core$IFn$_invoke$arity$1(mission));
var install_art_dir = new cljs.core.Keyword(null,"art-dir","art-dir",67381390).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"installation","installation",943147954).cljs$core$IFn$_invoke$arity$1(mission));
var theater_resource = weathergen.filesystem.path_combine.call(null,data_dir,theater_art_dir,resource);
var install_resource = weathergen.filesystem.path_combine.call(null,data_dir,install_art_dir,resource);
var theater_resource_QMARK_ = weathergen.filesystem.exists_QMARK_.call(null,[cljs.core.str.cljs$core$IFn$_invoke$arity$1(theater_resource),cljs.core.str.cljs$core$IFn$_invoke$arity$1(".idx")].join(''));
var resource_art_dir = (cljs.core.truth_(theater_resource_QMARK_)?theater_art_dir:install_art_dir);
var base = weathergen.filesystem.path_combine.call(null,data_dir,(cljs.core.truth_(theater_resource_QMARK_)?theater_resource:install_resource));
var idx_path = [cljs.core.str.cljs$core$IFn$_invoke$arity$1(base),cljs.core.str.cljs$core$IFn$_invoke$arity$1(".idx")].join('');
var rsc_path = [cljs.core.str.cljs$core$IFn$_invoke$arity$1(base),cljs.core.str.cljs$core$IFn$_invoke$arity$1(".rsc")].join('');
var idx_stats = weathergen.filesystem.stat.call(null,idx_path);
var rsc_stats = weathergen.filesystem.stat.call(null,rsc_path);
var data_dir__$1 = new cljs.core.Keyword(null,"data-dir","data-dir",2038801936).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"installation","installation",943147954).cljs$core$IFn$_invoke$arity$1(mission));
var index = weathergen.falcon.files.images.read_index.call(null,idx_path);
var image_data = cljs.core.first.call(null,cljs.core.filter.call(null,((function (data_dir,theater_art_dir,install_art_dir,theater_resource,install_resource,theater_resource_QMARK_,resource_art_dir,base,idx_path,rsc_path,idx_stats,rsc_stats,data_dir__$1,index){
return (function (p1__34940_SHARP_){
return cljs.core._EQ_.call(null,image_id,new cljs.core.Keyword(null,"id","id",-1388402092).cljs$core$IFn$_invoke$arity$1(p1__34940_SHARP_));
});})(data_dir,theater_art_dir,install_art_dir,theater_resource,install_resource,theater_resource_QMARK_,resource_art_dir,base,idx_path,rsc_path,idx_stats,rsc_stats,data_dir__$1,index))
,index));
var _ = (cljs.core.truth_(image_data)?null:(function(){throw (new Error([cljs.core.str.cljs$core$IFn$_invoke$arity$1("Assert failed: "),cljs.core.str.cljs$core$IFn$_invoke$arity$1((function (){var sb__24240__auto__ = (new goog.string.StringBuffer());
var _STAR_print_newline_STAR_34943_34945 = cljs.core._STAR_print_newline_STAR_;
var _STAR_print_fn_STAR_34944_34946 = cljs.core._STAR_print_fn_STAR_;
cljs.core._STAR_print_newline_STAR_ = true;

cljs.core._STAR_print_fn_STAR_ = ((function (_STAR_print_newline_STAR_34943_34945,_STAR_print_fn_STAR_34944_34946,sb__24240__auto__,data_dir,theater_art_dir,install_art_dir,theater_resource,install_resource,theater_resource_QMARK_,resource_art_dir,base,idx_path,rsc_path,idx_stats,rsc_stats,data_dir__$1,index,image_data){
return (function (x__24241__auto__){
return sb__24240__auto__.append(x__24241__auto__);
});})(_STAR_print_newline_STAR_34943_34945,_STAR_print_fn_STAR_34944_34946,sb__24240__auto__,data_dir,theater_art_dir,install_art_dir,theater_resource,install_resource,theater_resource_QMARK_,resource_art_dir,base,idx_path,rsc_path,idx_stats,rsc_stats,data_dir__$1,index,image_data))
;

try{cljs.core.print.call(null,"Couldn't find an image with that ID",new cljs.core.Keyword(null,"resource","resource",251898836),resource,new cljs.core.Keyword(null,"image-id","image-id",-988480565),image_id);
}finally {cljs.core._STAR_print_fn_STAR_ = _STAR_print_fn_STAR_34944_34946;

cljs.core._STAR_print_newline_STAR_ = _STAR_print_newline_STAR_34943_34945;
}
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(sb__24240__auto__)].join('');
})()),cljs.core.str.cljs$core$IFn$_invoke$arity$1("\n"),cljs.core.str.cljs$core$IFn$_invoke$arity$1("image-data")].join('')))})());
return cljs.core.PersistentHashMap.fromArrays([new cljs.core.Keyword(null,"idx-modified","idx-modified",-1917929304),new cljs.core.Keyword(null,"image-id","image-id",-988480565),new cljs.core.Keyword(null,"art-dir","art-dir",67381390),new cljs.core.Keyword(null,"idx-size","idx-size",893862481),new cljs.core.Keyword(null,"rsc-size","rsc-size",-568560687),new cljs.core.Keyword(null,"image-data","image-data",-377483758),new cljs.core.Keyword(null,"resource","resource",251898836),new cljs.core.Keyword(null,"rsc-modified","rsc-modified",-250537226),new cljs.core.Keyword(null,"base","base",185279322)],[new cljs.core.Keyword(null,"modified","modified",-2134587826).cljs$core$IFn$_invoke$arity$1(idx_stats),image_id,resource_art_dir,new cljs.core.Keyword(null,"size","size",1098693007).cljs$core$IFn$_invoke$arity$1(idx_stats),new cljs.core.Keyword(null,"size","size",1098693007).cljs$core$IFn$_invoke$arity$1(rsc_stats),image_data,resource,new cljs.core.Keyword(null,"modified","modified",-2134587826).cljs$core$IFn$_invoke$arity$1(rsc_stats),base]);
});
