// 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_34598 = 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__34599 = octet.core.read.call(null,idx_buf,file_header);
var map__34599__$1 = ((((!((map__34599 == null)))?((((map__34599.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34599.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34599):map__34599);
var size = cljs.core.get.call(null,map__34599__$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__34601 = 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__34601,(0),null);
var common = cljs.core.nth.call(null,vec__34601,(1),null);
var offset__$1 = (offset + size__$1);
var vec__34604 = octet.core.read_STAR_.call(null,idx_buf,(function (){var pred__34607 = cljs.core._EQ_;
var expr__34608 = new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(common);
if(cljs.core.truth_(pred__34607.call(null,weathergen.falcon.constants._RSC_IS_IMAGE_,expr__34608))){
return image_header;
} else {
if(cljs.core.truth_(pred__34607.call(null,weathergen.falcon.constants._RSC_IS_SOUND_,expr__34608))){
return sound_header;
} else {
if(cljs.core.truth_(pred__34607.call(null,weathergen.falcon.constants._RSC_IS_FLAT_,expr__34608))){
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__34608)].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__34604,(0),null);
var specifics = cljs.core.nth.call(null,vec__34604,(1),null);
var G__34610 = (offset__$1 + size__$2);
var G__34611 = cljs.core.conj.call(null,items,cljs.core.into.call(null,common,specifics));
offset = G__34610;
items = G__34611;
continue;
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34598;
}}));
weathergen.falcon.files.images.palette = (function weathergen$falcon$files$images$palette(image_buf,image_data){
var map__34615 = image_data;
var map__34615__$1 = ((((!((map__34615 == null)))?((((map__34615.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34615.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34615):map__34615);
var palette_size = cljs.core.get.call(null,map__34615__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34615__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var _STAR_byte_order_STAR_34617 = 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_34617;
}});
/**
 * 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__34640 = image_descriptor;
var map__34640__$1 = ((((!((map__34640 == null)))?((((map__34640.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34640.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34640):map__34640);
var resource = cljs.core.get.call(null,map__34640__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34640__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var base = cljs.core.get.call(null,map__34640__$1,new cljs.core.Keyword(null,"base","base",185279322));
var image_data = cljs.core.get.call(null,map__34640__$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__34641 = image_data;
var map__34641__$1 = ((((!((map__34641 == null)))?((((map__34641.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34641.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34641):map__34641);
var palette_size = cljs.core.get.call(null,map__34641__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__34641__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var center = cljs.core.get.call(null,map__34641__$1,new cljs.core.Keyword(null,"center","center",-748944368));
var image_offset = cljs.core.get.call(null,map__34641__$1,new cljs.core.Keyword(null,"image-offset","image-offset",-1802347612));
var size = cljs.core.get.call(null,map__34641__$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__34642 = size;
var width = cljs.core.nth.call(null,vec__34642,(0),null);
var height = cljs.core.nth.call(null,vec__34642,(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__34640,map__34640__$1,resource,image_id,base,image_data,image_buf,palette,map__34641,map__34641__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34642,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__34640,map__34640__$1,resource,image_id,base,image_data,image_buf,palette,map__34641,map__34641__$1,palette_size,palette_offset,center,image_offset,size,is_8_bit_QMARK_,use_transparency_QMARK_,vec__34642,width,height))
,null)),null,-977863822);

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__34647 = allocator.call(null,width,height);
var map__34647__$1 = ((((!((map__34647 == null)))?((((map__34647.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34647.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34647):map__34647);
var set_pixel_BANG_ = cljs.core.get.call(null,map__34647__$1,new cljs.core.Keyword(null,"set-pixel!","set-pixel!",1287500897));
var finalize = cljs.core.get.call(null,map__34647__$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_34649_34662 = 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__34650_34663 = cljs.core.seq.call(null,cljs.core.range.call(null,height));
var chunk__34655_34664 = null;
var count__34656_34665 = (0);
var i__34657_34666 = (0);
while(true){
if((i__34657_34666 < count__34656_34665)){
var y_34667 = cljs.core._nth.call(null,chunk__34655_34664,i__34657_34666);
var seq__34658_34668 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34659_34669 = null;
var count__34660_34670 = (0);
var i__34661_34671 = (0);
while(true){
if((i__34661_34671 < count__34660_34670)){
var x_34672 = cljs.core._nth.call(null,chunk__34659_34669,i__34661_34671);
var offset_34673 = (((8) + image_offset) + (pixel_bytes * (x_34672 + (y_34667 * width))));
var c_34674 = read_pixel.call(null,image_buf,offset_34673);
var raw_34675 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34674):c_34674);
var r_34676 = ((raw_34675 >> (10)) & (31));
var g_34677 = ((raw_34675 >> (5)) & (31));
var b_34678 = (raw_34675 & (31));
var transparent_QMARK__34679 = (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_34674 === (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_34676,g_34677,b_34678], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34680 = (((((((cljs.core.truth_(transparent_QMARK__34679)?(0):(255)) << (8)) + (b_34678 * (8))) << (8)) + (g_34677 * (8))) << (8)) + (r_34676 * (8)));
set_pixel_BANG_.call(null,x_34672,y_34667,argb_34680);

var G__34681 = seq__34658_34668;
var G__34682 = chunk__34659_34669;
var G__34683 = count__34660_34670;
var G__34684 = (i__34661_34671 + (1));
seq__34658_34668 = G__34681;
chunk__34659_34669 = G__34682;
count__34660_34670 = G__34683;
i__34661_34671 = G__34684;
continue;
} else {
var temp__5278__auto___34685 = cljs.core.seq.call(null,seq__34658_34668);
if(temp__5278__auto___34685){
var seq__34658_34686__$1 = temp__5278__auto___34685;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34658_34686__$1)){
var c__24249__auto___34687 = cljs.core.chunk_first.call(null,seq__34658_34686__$1);
var G__34688 = cljs.core.chunk_rest.call(null,seq__34658_34686__$1);
var G__34689 = c__24249__auto___34687;
var G__34690 = cljs.core.count.call(null,c__24249__auto___34687);
var G__34691 = (0);
seq__34658_34668 = G__34688;
chunk__34659_34669 = G__34689;
count__34660_34670 = G__34690;
i__34661_34671 = G__34691;
continue;
} else {
var x_34692 = cljs.core.first.call(null,seq__34658_34686__$1);
var offset_34693 = (((8) + image_offset) + (pixel_bytes * (x_34692 + (y_34667 * width))));
var c_34694 = read_pixel.call(null,image_buf,offset_34693);
var raw_34695 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34694):c_34694);
var r_34696 = ((raw_34695 >> (10)) & (31));
var g_34697 = ((raw_34695 >> (5)) & (31));
var b_34698 = (raw_34695 & (31));
var transparent_QMARK__34699 = (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_34694 === (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_34696,g_34697,b_34698], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34700 = (((((((cljs.core.truth_(transparent_QMARK__34699)?(0):(255)) << (8)) + (b_34698 * (8))) << (8)) + (g_34697 * (8))) << (8)) + (r_34696 * (8)));
set_pixel_BANG_.call(null,x_34692,y_34667,argb_34700);

var G__34701 = cljs.core.next.call(null,seq__34658_34686__$1);
var G__34702 = null;
var G__34703 = (0);
var G__34704 = (0);
seq__34658_34668 = G__34701;
chunk__34659_34669 = G__34702;
count__34660_34670 = G__34703;
i__34661_34671 = G__34704;
continue;
}
} else {
}
}
break;
}

var G__34705 = seq__34650_34663;
var G__34706 = chunk__34655_34664;
var G__34707 = count__34656_34665;
var G__34708 = (i__34657_34666 + (1));
seq__34650_34663 = G__34705;
chunk__34655_34664 = G__34706;
count__34656_34665 = G__34707;
i__34657_34666 = G__34708;
continue;
} else {
var temp__5278__auto___34709 = cljs.core.seq.call(null,seq__34650_34663);
if(temp__5278__auto___34709){
var seq__34650_34710__$1 = temp__5278__auto___34709;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34650_34710__$1)){
var c__24249__auto___34711 = cljs.core.chunk_first.call(null,seq__34650_34710__$1);
var G__34712 = cljs.core.chunk_rest.call(null,seq__34650_34710__$1);
var G__34713 = c__24249__auto___34711;
var G__34714 = cljs.core.count.call(null,c__24249__auto___34711);
var G__34715 = (0);
seq__34650_34663 = G__34712;
chunk__34655_34664 = G__34713;
count__34656_34665 = G__34714;
i__34657_34666 = G__34715;
continue;
} else {
var y_34716 = cljs.core.first.call(null,seq__34650_34710__$1);
var seq__34651_34717 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__34652_34718 = null;
var count__34653_34719 = (0);
var i__34654_34720 = (0);
while(true){
if((i__34654_34720 < count__34653_34719)){
var x_34721 = cljs.core._nth.call(null,chunk__34652_34718,i__34654_34720);
var offset_34722 = (((8) + image_offset) + (pixel_bytes * (x_34721 + (y_34716 * width))));
var c_34723 = read_pixel.call(null,image_buf,offset_34722);
var raw_34724 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34723):c_34723);
var r_34725 = ((raw_34724 >> (10)) & (31));
var g_34726 = ((raw_34724 >> (5)) & (31));
var b_34727 = (raw_34724 & (31));
var transparent_QMARK__34728 = (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_34723 === (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_34725,g_34726,b_34727], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34729 = (((((((cljs.core.truth_(transparent_QMARK__34728)?(0):(255)) << (8)) + (b_34727 * (8))) << (8)) + (g_34726 * (8))) << (8)) + (r_34725 * (8)));
set_pixel_BANG_.call(null,x_34721,y_34716,argb_34729);

var G__34730 = seq__34651_34717;
var G__34731 = chunk__34652_34718;
var G__34732 = count__34653_34719;
var G__34733 = (i__34654_34720 + (1));
seq__34651_34717 = G__34730;
chunk__34652_34718 = G__34731;
count__34653_34719 = G__34732;
i__34654_34720 = G__34733;
continue;
} else {
var temp__5278__auto___34734__$1 = cljs.core.seq.call(null,seq__34651_34717);
if(temp__5278__auto___34734__$1){
var seq__34651_34735__$1 = temp__5278__auto___34734__$1;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__34651_34735__$1)){
var c__24249__auto___34736 = cljs.core.chunk_first.call(null,seq__34651_34735__$1);
var G__34737 = cljs.core.chunk_rest.call(null,seq__34651_34735__$1);
var G__34738 = c__24249__auto___34736;
var G__34739 = cljs.core.count.call(null,c__24249__auto___34736);
var G__34740 = (0);
seq__34651_34717 = G__34737;
chunk__34652_34718 = G__34738;
count__34653_34719 = G__34739;
i__34654_34720 = G__34740;
continue;
} else {
var x_34741 = cljs.core.first.call(null,seq__34651_34735__$1);
var offset_34742 = (((8) + image_offset) + (pixel_bytes * (x_34741 + (y_34716 * width))));
var c_34743 = read_pixel.call(null,image_buf,offset_34742);
var raw_34744 = (cljs.core.truth_(is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_34743):c_34743);
var r_34745 = ((raw_34744 >> (10)) & (31));
var g_34746 = ((raw_34744 >> (5)) & (31));
var b_34747 = (raw_34744 & (31));
var transparent_QMARK__34748 = (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_34743 === (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_34745,g_34746,b_34747], null));
}
} else {
return and__23326__auto__;
}
})();
var argb_34749 = (((((((cljs.core.truth_(transparent_QMARK__34748)?(0):(255)) << (8)) + (b_34747 * (8))) << (8)) + (g_34746 * (8))) << (8)) + (r_34745 * (8)));
set_pixel_BANG_.call(null,x_34741,y_34716,argb_34749);

var G__34750 = cljs.core.next.call(null,seq__34651_34735__$1);
var G__34751 = null;
var G__34752 = (0);
var G__34753 = (0);
seq__34651_34717 = G__34750;
chunk__34652_34718 = G__34751;
count__34653_34719 = G__34752;
i__34654_34720 = G__34753;
continue;
}
} else {
}
}
break;
}

var G__34754 = cljs.core.next.call(null,seq__34650_34710__$1);
var G__34755 = null;
var G__34756 = (0);
var G__34757 = (0);
seq__34650_34663 = G__34754;
chunk__34655_34664 = G__34755;
count__34656_34665 = G__34756;
i__34657_34666 = G__34757;
continue;
}
} else {
}
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR_34649_34662;
}
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__34760 = image_descriptor;
var map__34760__$1 = ((((!((map__34760 == null)))?((((map__34760.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34760.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34760):map__34760);
var resource = cljs.core.get.call(null,map__34760__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__34760__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var art_dir = cljs.core.get.call(null,map__34760__$1,new cljs.core.Keyword(null,"art-dir","art-dir",67381390));
var idx_size = cljs.core.get.call(null,map__34760__$1,new cljs.core.Keyword(null,"idx-size","idx-size",893862481));
var idx_modified = cljs.core.get.call(null,map__34760__$1,new cljs.core.Keyword(null,"idx-modified","idx-modified",-1917929304));
var rsc_size = cljs.core.get.call(null,map__34760__$1,new cljs.core.Keyword(null,"rsc-size","rsc-size",-568560687));
var rsc_modified = cljs.core.get.call(null,map__34760__$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__34762_SHARP_){
return cljs.core._EQ_.call(null,image_id,new cljs.core.Keyword(null,"id","id",-1388402092).cljs$core$IFn$_invoke$arity$1(p1__34762_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_34765_34767 = cljs.core._STAR_print_newline_STAR_;
var _STAR_print_fn_STAR_34766_34768 = cljs.core._STAR_print_fn_STAR_;
cljs.core._STAR_print_newline_STAR_ = true;

cljs.core._STAR_print_fn_STAR_ = ((function (_STAR_print_newline_STAR_34765_34767,_STAR_print_fn_STAR_34766_34768,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_34765_34767,_STAR_print_fn_STAR_34766_34768,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_34766_34768;

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