// 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_34596 = 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__34597 = octet.core.read.call(null,idx_buf,file_header);
var map__34597__$1 = ((((!((map__34597 == null)))?((((map__34597.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34597.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34597):map__34597);
var size = cljs.core.get.call(null,map__34597__$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__34599 = 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__34599,(0),null);
var common = cljs.core.nth.call(null,vec__34599,(1),null);
var offset__$1 = (offset + size__$1);
var vec__34602 = octet.core.read_STAR_.call(null,idx_buf,(function (){var pred__34605 = cljs.core._EQ_;
var expr__34606 = new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(common);
if(cljs.core.truth_(pred__34605.call(null,weathergen.falcon.constants._RSC_IS_IMAGE_,expr__34606))){
return image_header;
} else {
if(cljs.core.truth_(pred__34605.call(null,weathergen.falcon.constants._RSC_IS_SOUND_,expr__34606))){
return sound_header;
} else {
if(cljs.core.truth_(pred__34605.call(null,weathergen.falcon.constants._RSC_IS_FLAT_,expr__34606))){
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__34606)].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__34602,(0),null);
var specifics = cljs.core.nth.call(null,vec__34602,(1),null);
var G__34608 = (offset__$1 + size__$2);
var G__34609 = cljs.core.conj.call(null,items,cljs.core.into.call(null,common,specifics));
offset = G__34608;
items = G__34609;
continue;
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34596;
}}));
weathergen.falcon.files.images.palette = (function weathergen$falcon$files$images$palette(image_buf,image_data){
var map__34613 = image_data;
var map__34613__$1 = ((((!((map__34613 == null)))?((((map__34613.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34613.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34613):map__34613);
var palette_size = cljs.core.get.call(null,map__34613__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34613__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var _STAR_byte_order_STAR_34615 = 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_34615;
}});
/**
 * 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__34638 = image_descriptor;
var map__34638__$1 = ((((!((map__34638 == null)))?((((map__34638.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34638.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34638):map__34638);
var resource = cljs.core.get.call(null,map__34638__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34638__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var base = cljs.core.get.call(null,map__34638__$1,new cljs.core.Keyword(null,"base","base",185279322));
var image_data = cljs.core.get.call(null,map__34638__$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__34639 = image_data;
var map__34639__$1 = ((((!((map__34639 == null)))?((((map__34639.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34639.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34639):map__34639);
var palette_size = cljs.core.get.call(null,map__34639__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34639__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var center = cljs.core.get.call(null,map__34639__$1,new cljs.core.Keyword(null,"center","center",-748944368));
var image_offset = cljs.core.get.call(null,map__34639__$1,new cljs.core.Keyword(null,"image-offset","image-offset",-1802347612));
var size = cljs.core.get.call(null,map__34639__$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__34640 = size;
var width = cljs.core.nth.call(null,vec__34640,(0),null);
var height = cljs.core.nth.call(null,vec__34640,(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__34638,map__34638__$1,resource,image_id,base,image_data,image_buf,palette,map__34639,map__34639__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34640,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__34638,map__34638__$1,resource,image_id,base,image_data,image_buf,palette,map__34639,map__34639__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34640,width,height))
,null)),null,1994597491);

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__34645 = allocator.call(null,width,height);
var map__34645__$1 = ((((!((map__34645 == null)))?((((map__34645.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34645.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34645):map__34645);
var set_pixel_BANG_ = cljs.core.get.call(null,map__34645__$1,new cljs.core.Keyword(null,"set-pixel!","set-pixel!",1287500897));
var finalize = cljs.core.get.call(null,map__34645__$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_34647_34660 = 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__34648_34661 = cljs.core.seq.call(null,cljs.core.range.call(null,height));
var chunk__34653_34662 = null;
var count__34654_34663 = (0);
var i__34655_34664 = (0);
while(true){
if((i__34655_34664 < count__34654_34663)){
var y_34665 = cljs.core._nth.call(null,chunk__34653_34662,i__34655_34664);
var seq__34656_34666 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34657_34667 = null;
var count__34658_34668 = (0);
var i__34659_34669 = (0);
while(true){
if((i__34659_34669 < count__34658_34668)){
var x_34670 = cljs.core._nth.call(null,chunk__34657_34667,i__34659_34669);
var offset_34671 = (((8) + image_offset) + (pixel_bytes * (x_34670 + (y_34665 * width))));
var c_34672 = read_pixel.call(null,image_buf,offset_34671);
var raw_34673 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34672):c_34672);
var r_34674 = ((raw_34673 >> (10)) & (31));
var g_34675 = ((raw_34673 >> (5)) & (31));
var b_34676 = (raw_34673 & (31));
var transparent_QMARK__34677 = (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_34672 === (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_34674,g_34675,b_34676], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34678 = (((((((cljs.core.truth_(transparent_QMARK__34677)?(0):(255)) << (8)) + (b_34676 * (8))) << (8)) + (g_34675 * (8))) << (8)) + (r_34674 * (8)));
set_pixel_BANG_.call(null,x_34670,y_34665,argb_34678);

var G__34679 = seq__34656_34666;
var G__34680 = chunk__34657_34667;
var G__34681 = count__34658_34668;
var G__34682 = (i__34659_34669 + (1));
seq__34656_34666 = G__34679;
chunk__34657_34667 = G__34680;
count__34658_34668 = G__34681;
i__34659_34669 = G__34682;
continue;
} else {
var temp__5278__auto___34683 = cljs.core.seq.call(null,seq__34656_34666);
if(temp__5278__auto___34683){
var seq__34656_34684__$1 = temp__5278__auto___34683;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34656_34684__$1)){
var c__24059__auto___34685 = cljs.core.chunk_first.call(null,seq__34656_34684__$1);
var G__34686 = cljs.core.chunk_rest.call(null,seq__34656_34684__$1);
var G__34687 = c__24059__auto___34685;
var G__34688 = cljs.core.count.call(null,c__24059__auto___34685);
var G__34689 = (0);
seq__34656_34666 = G__34686;
chunk__34657_34667 = G__34687;
count__34658_34668 = G__34688;
i__34659_34669 = G__34689;
continue;
} else {
var x_34690 = cljs.core.first.call(null,seq__34656_34684__$1);
var offset_34691 = (((8) + image_offset) + (pixel_bytes * (x_34690 + (y_34665 * width))));
var c_34692 = read_pixel.call(null,image_buf,offset_34691);
var raw_34693 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34692):c_34692);
var r_34694 = ((raw_34693 >> (10)) & (31));
var g_34695 = ((raw_34693 >> (5)) & (31));
var b_34696 = (raw_34693 & (31));
var transparent_QMARK__34697 = (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_34692 === (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_34694,g_34695,b_34696], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34698 = (((((((cljs.core.truth_(transparent_QMARK__34697)?(0):(255)) << (8)) + (b_34696 * (8))) << (8)) + (g_34695 * (8))) << (8)) + (r_34694 * (8)));
set_pixel_BANG_.call(null,x_34690,y_34665,argb_34698);

var G__34699 = cljs.core.next.call(null,seq__34656_34684__$1);
var G__34700 = null;
var G__34701 = (0);
var G__34702 = (0);
seq__34656_34666 = G__34699;
chunk__34657_34667 = G__34700;
count__34658_34668 = G__34701;
i__34659_34669 = G__34702;
continue;
}
} else {
}
}
break;
}

var G__34703 = seq__34648_34661;
var G__34704 = chunk__34653_34662;
var G__34705 = count__34654_34663;
var G__34706 = (i__34655_34664 + (1));
seq__34648_34661 = G__34703;
chunk__34653_34662 = G__34704;
count__34654_34663 = G__34705;
i__34655_34664 = G__34706;
continue;
} else {
var temp__5278__auto___34707 = cljs.core.seq.call(null,seq__34648_34661);
if(temp__5278__auto___34707){
var seq__34648_34708__$1 = temp__5278__auto___34707;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34648_34708__$1)){
var c__24059__auto___34709 = cljs.core.chunk_first.call(null,seq__34648_34708__$1);
var G__34710 = cljs.core.chunk_rest.call(null,seq__34648_34708__$1);
var G__34711 = c__24059__auto___34709;
var G__34712 = cljs.core.count.call(null,c__24059__auto___34709);
var G__34713 = (0);
seq__34648_34661 = G__34710;
chunk__34653_34662 = G__34711;
count__34654_34663 = G__34712;
i__34655_34664 = G__34713;
continue;
} else {
var y_34714 = cljs.core.first.call(null,seq__34648_34708__$1);
var seq__34649_34715 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34650_34716 = null;
var count__34651_34717 = (0);
var i__34652_34718 = (0);
while(true){
if((i__34652_34718 < count__34651_34717)){
var x_34719 = cljs.core._nth.call(null,chunk__34650_34716,i__34652_34718);
var offset_34720 = (((8) + image_offset) + (pixel_bytes * (x_34719 + (y_34714 * width))));
var c_34721 = read_pixel.call(null,image_buf,offset_34720);
var raw_34722 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34721):c_34721);
var r_34723 = ((raw_34722 >> (10)) & (31));
var g_34724 = ((raw_34722 >> (5)) & (31));
var b_34725 = (raw_34722 & (31));
var transparent_QMARK__34726 = (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_34721 === (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_34723,g_34724,b_34725], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34727 = (((((((cljs.core.truth_(transparent_QMARK__34726)?(0):(255)) << (8)) + (b_34725 * (8))) << (8)) + (g_34724 * (8))) << (8)) + (r_34723 * (8)));
set_pixel_BANG_.call(null,x_34719,y_34714,argb_34727);

var G__34728 = seq__34649_34715;
var G__34729 = chunk__34650_34716;
var G__34730 = count__34651_34717;
var G__34731 = (i__34652_34718 + (1));
seq__34649_34715 = G__34728;
chunk__34650_34716 = G__34729;
count__34651_34717 = G__34730;
i__34652_34718 = G__34731;
continue;
} else {
var temp__5278__auto___34732__$1 = cljs.core.seq.call(null,seq__34649_34715);
if(temp__5278__auto___34732__$1){
var seq__34649_34733__$1 = temp__5278__auto___34732__$1;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34649_34733__$1)){
var c__24059__auto___34734 = cljs.core.chunk_first.call(null,seq__34649_34733__$1);
var G__34735 = cljs.core.chunk_rest.call(null,seq__34649_34733__$1);
var G__34736 = c__24059__auto___34734;
var G__34737 = cljs.core.count.call(null,c__24059__auto___34734);
var G__34738 = (0);
seq__34649_34715 = G__34735;
chunk__34650_34716 = G__34736;
count__34651_34717 = G__34737;
i__34652_34718 = G__34738;
continue;
} else {
var x_34739 = cljs.core.first.call(null,seq__34649_34733__$1);
var offset_34740 = (((8) + image_offset) + (pixel_bytes * (x_34739 + (y_34714 * width))));
var c_34741 = read_pixel.call(null,image_buf,offset_34740);
var raw_34742 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34741):c_34741);
var r_34743 = ((raw_34742 >> (10)) & (31));
var g_34744 = ((raw_34742 >> (5)) & (31));
var b_34745 = (raw_34742 & (31));
var transparent_QMARK__34746 = (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_34741 === (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_34743,g_34744,b_34745], null));
}
} else {
return and__23136__auto__;
}
})();
var argb_34747 = (((((((cljs.core.truth_(transparent_QMARK__34746)?(0):(255)) << (8)) + (b_34745 * (8))) << (8)) + (g_34744 * (8))) << (8)) + (r_34743 * (8)));
set_pixel_BANG_.call(null,x_34739,y_34714,argb_34747);

var G__34748 = cljs.core.next.call(null,seq__34649_34733__$1);
var G__34749 = null;
var G__34750 = (0);
var G__34751 = (0);
seq__34649_34715 = G__34748;
chunk__34650_34716 = G__34749;
count__34651_34717 = G__34750;
i__34652_34718 = G__34751;
continue;
}
} else {
}
}
break;
}

var G__34752 = cljs.core.next.call(null,seq__34648_34708__$1);
var G__34753 = null;
var G__34754 = (0);
var G__34755 = (0);
seq__34648_34661 = G__34752;
chunk__34653_34662 = G__34753;
count__34654_34663 = G__34754;
i__34655_34664 = G__34755;
continue;
}
} else {
}
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34647_34660;
}
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__34758 = image_descriptor;
var map__34758__$1 = ((((!((map__34758 == null)))?((((map__34758.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34758.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34758):map__34758);
var resource = cljs.core.get.call(null,map__34758__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34758__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var art_dir = cljs.core.get.call(null,map__34758__$1,new cljs.core.Keyword(null,"art-dir","art-dir",67381390));
var idx_size = cljs.core.get.call(null,map__34758__$1,new cljs.core.Keyword(null,"idx-size","idx-size",893862481));
var idx_modified = cljs.core.get.call(null,map__34758__$1,new cljs.core.Keyword(null,"idx-modified","idx-modified",-1917929304));
var rsc_size = cljs.core.get.call(null,map__34758__$1,new cljs.core.Keyword(null,"rsc-size","rsc-size",-568560687));
var rsc_modified = cljs.core.get.call(null,map__34758__$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__34760_SHARP_){
return cljs.core._EQ_.call(null,image_id,new cljs.core.Keyword(null,"id","id",-1388402092).cljs$core$IFn$_invoke$arity$1(p1__34760_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_34763_34765 = cljs.core._STAR_print_newline_STAR_;
var _STAR_print_fn_STAR_34764_34766 = cljs.core._STAR_print_fn_STAR_;
cljs.core._STAR_print_newline_STAR_ = true;

cljs.core._STAR_print_fn_STAR_ = ((function (_STAR_print_newline_STAR_34763_34765,_STAR_print_fn_STAR_34764_34766,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_34763_34765,_STAR_print_fn_STAR_34764_34766,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_34764_34766;

cljs.core._STAR_print_newline_STAR_ = _STAR_print_newline_STAR_34763_34765;
}
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]);
});
