// 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_34700 = 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__34701 = octet.core.read.call(null,idx_buf,file_header);
var map__34701__$1 = ((((!((map__34701 == null)))?((((map__34701.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34701.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34701):map__34701);
var size = cljs.core.get.call(null,map__34701__$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__34703 = 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__34703,(0),null);
var common = cljs.core.nth.call(null,vec__34703,(1),null);
var offset__$1 = (offset + size__$1);
var vec__34706 = octet.core.read_STAR_.call(null,idx_buf,(function (){var pred__34709 = cljs.core._EQ_;
var expr__34710 = new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(common);
if(cljs.core.truth_(pred__34709.call(null,weathergen.falcon.constants._RSC_IS_IMAGE_,expr__34710))){
return image_header;
} else {
if(cljs.core.truth_(pred__34709.call(null,weathergen.falcon.constants._RSC_IS_SOUND_,expr__34710))){
return sound_header;
} else {
if(cljs.core.truth_(pred__34709.call(null,weathergen.falcon.constants._RSC_IS_FLAT_,expr__34710))){
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__34710)].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__34706,(0),null);
var specifics = cljs.core.nth.call(null,vec__34706,(1),null);
var G__34712 = (offset__$1 + size__$2);
var G__34713 = cljs.core.conj.call(null,items,cljs.core.into.call(null,common,specifics));
offset = G__34712;
items = G__34713;
continue;
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34700;
}}));
weathergen.falcon.files.images.palette = (function weathergen$falcon$files$images$palette(image_buf,image_data){
var map__34717 = image_data;
var map__34717__$1 = ((((!((map__34717 == null)))?((((map__34717.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34717.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34717):map__34717);
var palette_size = cljs.core.get.call(null,map__34717__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34717__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var _STAR_byte_order_STAR_34719 = 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_34719;
}});
/**
 * 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__34742 = image_descriptor;
var map__34742__$1 = ((((!((map__34742 == null)))?((((map__34742.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34742.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34742):map__34742);
var resource = cljs.core.get.call(null,map__34742__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34742__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var base = cljs.core.get.call(null,map__34742__$1,new cljs.core.Keyword(null,"base","base",185279322));
var image_data = cljs.core.get.call(null,map__34742__$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__34743 = image_data;
var map__34743__$1 = ((((!((map__34743 == null)))?((((map__34743.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34743.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34743):map__34743);
var palette_size = cljs.core.get.call(null,map__34743__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34743__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var center = cljs.core.get.call(null,map__34743__$1,new cljs.core.Keyword(null,"center","center",-748944368));
var image_offset = cljs.core.get.call(null,map__34743__$1,new cljs.core.Keyword(null,"image-offset","image-offset",-1802347612));
var size = cljs.core.get.call(null,map__34743__$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__34744 = size;
var width = cljs.core.nth.call(null,vec__34744,(0),null);
var height = cljs.core.nth.call(null,vec__34744,(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__34742,map__34742__$1,resource,image_id,base,image_data,image_buf,palette,map__34743,map__34743__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34744,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__34742,map__34742__$1,resource,image_id,base,image_data,image_buf,palette,map__34743,map__34743__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34744,width,height))
,null)),null,785561877);

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__34749 = allocator.call(null,width,height);
var map__34749__$1 = ((((!((map__34749 == null)))?((((map__34749.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34749.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34749):map__34749);
var set_pixel_BANG_ = cljs.core.get.call(null,map__34749__$1,new cljs.core.Keyword(null,"set-pixel!","set-pixel!",1287500897));
var finalize = cljs.core.get.call(null,map__34749__$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_34751_34764 = 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__34752_34765 = cljs.core.seq.call(null,cljs.core.range.call(null,height));
var chunk__34757_34766 = null;
var count__34758_34767 = (0);
var i__34759_34768 = (0);
while(true){
if((i__34759_34768 < count__34758_34767)){
var y_34769 = cljs.core._nth.call(null,chunk__34757_34766,i__34759_34768);
var seq__34760_34770 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34761_34771 = null;
var count__34762_34772 = (0);
var i__34763_34773 = (0);
while(true){
if((i__34763_34773 < count__34762_34772)){
var x_34774 = cljs.core._nth.call(null,chunk__34761_34771,i__34763_34773);
var offset_34775 = (((8) + image_offset) + (pixel_bytes * (x_34774 + (y_34769 * width))));
var c_34776 = read_pixel.call(null,image_buf,offset_34775);
var raw_34777 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34776):c_34776);
var r_34778 = ((raw_34777 >> (10)) & (31));
var g_34779 = ((raw_34777 >> (5)) & (31));
var b_34780 = (raw_34777 & (31));
var transparent_QMARK__34781 = (function (){var and__23326__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23326__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34776 === (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_34778,g_34779,b_34780], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34782 = (((((((cljs.core.truth_(transparent_QMARK__34781)?(0):(255)) << (8)) + (b_34780 * (8))) << (8)) + (g_34779 * (8))) << (8)) + (r_34778 * (8)));
set_pixel_BANG_.call(null,x_34774,y_34769,argb_34782);

var G__34783 = seq__34760_34770;
var G__34784 = chunk__34761_34771;
var G__34785 = count__34762_34772;
var G__34786 = (i__34763_34773 + (1));
seq__34760_34770 = G__34783;
chunk__34761_34771 = G__34784;
count__34762_34772 = G__34785;
i__34763_34773 = G__34786;
continue;
} else {
var temp__5278__auto___34787 = cljs.core.seq.call(null,seq__34760_34770);
if(temp__5278__auto___34787){
var seq__34760_34788__$1 = temp__5278__auto___34787;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34760_34788__$1)){
var c__24249__auto___34789 = cljs.core.chunk_first.call(null,seq__34760_34788__$1);
var G__34790 = cljs.core.chunk_rest.call(null,seq__34760_34788__$1);
var G__34791 = c__24249__auto___34789;
var G__34792 = cljs.core.count.call(null,c__24249__auto___34789);
var G__34793 = (0);
seq__34760_34770 = G__34790;
chunk__34761_34771 = G__34791;
count__34762_34772 = G__34792;
i__34763_34773 = G__34793;
continue;
} else {
var x_34794 = cljs.core.first.call(null,seq__34760_34788__$1);
var offset_34795 = (((8) + image_offset) + (pixel_bytes * (x_34794 + (y_34769 * width))));
var c_34796 = read_pixel.call(null,image_buf,offset_34795);
var raw_34797 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34796):c_34796);
var r_34798 = ((raw_34797 >> (10)) & (31));
var g_34799 = ((raw_34797 >> (5)) & (31));
var b_34800 = (raw_34797 & (31));
var transparent_QMARK__34801 = (function (){var and__23326__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23326__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34796 === (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_34798,g_34799,b_34800], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34802 = (((((((cljs.core.truth_(transparent_QMARK__34801)?(0):(255)) << (8)) + (b_34800 * (8))) << (8)) + (g_34799 * (8))) << (8)) + (r_34798 * (8)));
set_pixel_BANG_.call(null,x_34794,y_34769,argb_34802);

var G__34803 = cljs.core.next.call(null,seq__34760_34788__$1);
var G__34804 = null;
var G__34805 = (0);
var G__34806 = (0);
seq__34760_34770 = G__34803;
chunk__34761_34771 = G__34804;
count__34762_34772 = G__34805;
i__34763_34773 = G__34806;
continue;
}
} else {
}
}
break;
}

var G__34807 = seq__34752_34765;
var G__34808 = chunk__34757_34766;
var G__34809 = count__34758_34767;
var G__34810 = (i__34759_34768 + (1));
seq__34752_34765 = G__34807;
chunk__34757_34766 = G__34808;
count__34758_34767 = G__34809;
i__34759_34768 = G__34810;
continue;
} else {
var temp__5278__auto___34811 = cljs.core.seq.call(null,seq__34752_34765);
if(temp__5278__auto___34811){
var seq__34752_34812__$1 = temp__5278__auto___34811;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34752_34812__$1)){
var c__24249__auto___34813 = cljs.core.chunk_first.call(null,seq__34752_34812__$1);
var G__34814 = cljs.core.chunk_rest.call(null,seq__34752_34812__$1);
var G__34815 = c__24249__auto___34813;
var G__34816 = cljs.core.count.call(null,c__24249__auto___34813);
var G__34817 = (0);
seq__34752_34765 = G__34814;
chunk__34757_34766 = G__34815;
count__34758_34767 = G__34816;
i__34759_34768 = G__34817;
continue;
} else {
var y_34818 = cljs.core.first.call(null,seq__34752_34812__$1);
var seq__34753_34819 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34754_34820 = null;
var count__34755_34821 = (0);
var i__34756_34822 = (0);
while(true){
if((i__34756_34822 < count__34755_34821)){
var x_34823 = cljs.core._nth.call(null,chunk__34754_34820,i__34756_34822);
var offset_34824 = (((8) + image_offset) + (pixel_bytes * (x_34823 + (y_34818 * width))));
var c_34825 = read_pixel.call(null,image_buf,offset_34824);
var raw_34826 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34825):c_34825);
var r_34827 = ((raw_34826 >> (10)) & (31));
var g_34828 = ((raw_34826 >> (5)) & (31));
var b_34829 = (raw_34826 & (31));
var transparent_QMARK__34830 = (function (){var and__23326__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23326__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34825 === (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_34827,g_34828,b_34829], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34831 = (((((((cljs.core.truth_(transparent_QMARK__34830)?(0):(255)) << (8)) + (b_34829 * (8))) << (8)) + (g_34828 * (8))) << (8)) + (r_34827 * (8)));
set_pixel_BANG_.call(null,x_34823,y_34818,argb_34831);

var G__34832 = seq__34753_34819;
var G__34833 = chunk__34754_34820;
var G__34834 = count__34755_34821;
var G__34835 = (i__34756_34822 + (1));
seq__34753_34819 = G__34832;
chunk__34754_34820 = G__34833;
count__34755_34821 = G__34834;
i__34756_34822 = G__34835;
continue;
} else {
var temp__5278__auto___34836__$1 = cljs.core.seq.call(null,seq__34753_34819);
if(temp__5278__auto___34836__$1){
var seq__34753_34837__$1 = temp__5278__auto___34836__$1;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34753_34837__$1)){
var c__24249__auto___34838 = cljs.core.chunk_first.call(null,seq__34753_34837__$1);
var G__34839 = cljs.core.chunk_rest.call(null,seq__34753_34837__$1);
var G__34840 = c__24249__auto___34838;
var G__34841 = cljs.core.count.call(null,c__24249__auto___34838);
var G__34842 = (0);
seq__34753_34819 = G__34839;
chunk__34754_34820 = G__34840;
count__34755_34821 = G__34841;
i__34756_34822 = G__34842;
continue;
} else {
var x_34843 = cljs.core.first.call(null,seq__34753_34837__$1);
var offset_34844 = (((8) + image_offset) + (pixel_bytes * (x_34843 + (y_34818 * width))));
var c_34845 = read_pixel.call(null,image_buf,offset_34844);
var raw_34846 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34845):c_34845);
var r_34847 = ((raw_34846 >> (10)) & (31));
var g_34848 = ((raw_34846 >> (5)) & (31));
var b_34849 = (raw_34846 & (31));
var transparent_QMARK__34850 = (function (){var and__23326__auto__ = use_transparency_QMARK_;
if(cljs.core.truth_(and__23326__auto__)){
if(cljs.core.truth_(is_8_bit_QMARK_)){
return (c_34845 === (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_34847,g_34848,b_34849], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34851 = (((((((cljs.core.truth_(transparent_QMARK__34850)?(0):(255)) << (8)) + (b_34849 * (8))) << (8)) + (g_34848 * (8))) << (8)) + (r_34847 * (8)));
set_pixel_BANG_.call(null,x_34843,y_34818,argb_34851);

var G__34852 = cljs.core.next.call(null,seq__34753_34837__$1);
var G__34853 = null;
var G__34854 = (0);
var G__34855 = (0);
seq__34753_34819 = G__34852;
chunk__34754_34820 = G__34853;
count__34755_34821 = G__34854;
i__34756_34822 = G__34855;
continue;
}
} else {
}
}
break;
}

var G__34856 = cljs.core.next.call(null,seq__34752_34812__$1);
var G__34857 = null;
var G__34858 = (0);
var G__34859 = (0);
seq__34752_34765 = G__34856;
chunk__34757_34766 = G__34857;
count__34758_34767 = G__34858;
i__34759_34768 = G__34859;
continue;
}
} else {
}
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34751_34764;
}
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__34862 = image_descriptor;
var map__34862__$1 = ((((!((map__34862 == null)))?((((map__34862.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34862.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34862):map__34862);
var resource = cljs.core.get.call(null,map__34862__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34862__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var art_dir = cljs.core.get.call(null,map__34862__$1,new cljs.core.Keyword(null,"art-dir","art-dir",67381390));
var idx_size = cljs.core.get.call(null,map__34862__$1,new cljs.core.Keyword(null,"idx-size","idx-size",893862481));
var idx_modified = cljs.core.get.call(null,map__34862__$1,new cljs.core.Keyword(null,"idx-modified","idx-modified",-1917929304));
var rsc_size = cljs.core.get.call(null,map__34862__$1,new cljs.core.Keyword(null,"rsc-size","rsc-size",-568560687));
var rsc_modified = cljs.core.get.call(null,map__34862__$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__34864_SHARP_){
return cljs.core._EQ_.call(null,image_id,new cljs.core.Keyword(null,"id","id",-1388402092).cljs$core$IFn$_invoke$arity$1(p1__34864_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__24430__auto__ = (new goog.string.StringBuffer());
var _STAR_print_newline_STAR_34867_34869 = cljs.core._STAR_print_newline_STAR_;
var _STAR_print_fn_STAR_34868_34870 = cljs.core._STAR_print_fn_STAR_;
cljs.core._STAR_print_newline_STAR_ = true;

cljs.core._STAR_print_fn_STAR_ = ((function (_STAR_print_newline_STAR_34867_34869,_STAR_print_fn_STAR_34868_34870,sb__24430__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__24431__auto__){
return sb__24430__auto__.append(x__24431__auto__);
});})(_STAR_print_newline_STAR_34867_34869,_STAR_print_fn_STAR_34868_34870,sb__24430__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_34868_34870;

cljs.core._STAR_print_newline_STAR_ = _STAR_print_newline_STAR_34867_34869;
}
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(sb__24430__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]);
});
