// Compiled by ClojureScript 1.10.520 {}
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__orig_val__27738 = octet.buffer._STAR_byte_order_STAR_;
var _STAR_byte_order_STAR__temp_val__27739 = new cljs.core.Keyword(null,"little-endian","little-endian",1877303413);
octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR__temp_val__27739;

try{var map__27740 = octet.core.read.call(null,idx_buf,file_header);
var map__27740__$1 = (((((!((map__27740 == null))))?(((((map__27740.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27740.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27740):map__27740);
var size = cljs.core.get.call(null,map__27740__$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__27751 = 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__27751,(0),null);
var common = cljs.core.nth.call(null,vec__27751,(1),null);
var offset__$1 = (offset + size__$1);
var vec__27754 = octet.core.read_STAR_.call(null,idx_buf,(function (){var pred__27757 = cljs.core._EQ_;
var expr__27758 = new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(common);
if(cljs.core.truth_(pred__27757.call(null,weathergen.falcon.constants._RSC_IS_IMAGE_,expr__27758))){
return image_header;
} else {
if(cljs.core.truth_(pred__27757.call(null,weathergen.falcon.constants._RSC_IS_SOUND_,expr__27758))){
return sound_header;
} else {
if(cljs.core.truth_(pred__27757.call(null,weathergen.falcon.constants._RSC_IS_FLAT_,expr__27758))){
return flat_header;
} else {
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(expr__27758)].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__27754,(0),null);
var specifics = cljs.core.nth.call(null,vec__27754,(1),null);
var G__27760 = (offset__$1 + size__$2);
var G__27761 = cljs.core.conj.call(null,items,cljs.core.into.call(null,common,specifics));
offset = G__27760;
items = G__27761;
continue;
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR__orig_val__27738;
}}));
weathergen.falcon.files.images.palette = (function weathergen$falcon$files$images$palette(image_buf,image_data){
var map__27762 = image_data;
var map__27762__$1 = (((((!((map__27762 == null))))?(((((map__27762.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27762.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27762):map__27762);
var palette_size = cljs.core.get.call(null,map__27762__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__27762__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var _STAR_byte_order_STAR__orig_val__27764 = octet.buffer._STAR_byte_order_STAR_;
var _STAR_byte_order_STAR__temp_val__27765 = new cljs.core.Keyword(null,"little-endian","little-endian",1877303413);
octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR__temp_val__27765;

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__orig_val__27764;
}});
/**
 * 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__27766 = image_descriptor;
var map__27766__$1 = (((((!((map__27766 == null))))?(((((map__27766.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27766.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27766):map__27766);
var resource = cljs.core.get.call(null,map__27766__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__27766__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var base = cljs.core.get.call(null,map__27766__$1,new cljs.core.Keyword(null,"base","base",185279322));
var image_data = cljs.core.get.call(null,map__27766__$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),".rsc"].join(''));
var palette = weathergen.falcon.files.images.palette.call(null,image_buf,image_data);
var map__27767 = image_data;
var map__27767__$1 = (((((!((map__27767 == null))))?(((((map__27767.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27767.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27767):map__27767);
var palette_size = cljs.core.get.call(null,map__27767__$1,new cljs.core.Keyword(null,"palette-size","palette-size",-995698822));
var palette_offset = cljs.core.get.call(null,map__27767__$1,new cljs.core.Keyword(null,"palette-offset","palette-offset",1376573573));
var center = cljs.core.get.call(null,map__27767__$1,new cljs.core.Keyword(null,"center","center",-748944368));
var image_offset = cljs.core.get.call(null,map__27767__$1,new cljs.core.Keyword(null,"image-offset","image-offset",-1802347612));
var size = cljs.core.get.call(null,map__27767__$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__27768 = size;
var width = cljs.core.nth.call(null,vec__27768,(0),null);
var height = cljs.core.nth.call(null,vec__27768,(1),null);
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((((!(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_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__27773 = allocator.call(null,width,height);
var map__27773__$1 = (((((!((map__27773 == null))))?(((((map__27773.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27773.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27773):map__27773);
var set_pixel_BANG_ = cljs.core.get.call(null,map__27773__$1,new cljs.core.Keyword(null,"set-pixel!","set-pixel!",1287500897));
var finalize = cljs.core.get.call(null,map__27773__$1,new cljs.core.Keyword(null,"finalize","finalize",-1152897571));
var pixel_bytes = ((is_8_bit_QMARK_)?(1):(2));
var read_pixel = ((is_8_bit_QMARK_)?octet.buffer.read_ubyte:octet.buffer.read_ushort);
var _STAR_byte_order_STAR__orig_val__27775_27789 = octet.buffer._STAR_byte_order_STAR_;
var _STAR_byte_order_STAR__temp_val__27776_27790 = new cljs.core.Keyword(null,"little-endian","little-endian",1877303413);
octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR__temp_val__27776_27790;

try{var seq__27777_27791 = cljs.core.seq.call(null,cljs.core.range.call(null,height));
var chunk__27782_27792 = null;
var count__27783_27793 = (0);
var i__27784_27794 = (0);
while(true){
if((i__27784_27794 < count__27783_27793)){
var y_27795 = cljs.core._nth.call(null,chunk__27782_27792,i__27784_27794);
var seq__27785_27796 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__27786_27797 = null;
var count__27787_27798 = (0);
var i__27788_27799 = (0);
while(true){
if((i__27788_27799 < count__27787_27798)){
var x_27800 = cljs.core._nth.call(null,chunk__27786_27797,i__27788_27799);
var offset_27801 = (((8) + image_offset) + (pixel_bytes * (x_27800 + (y_27795 * width))));
var c_27802 = read_pixel.call(null,image_buf,offset_27801);
var raw_27803 = ((is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_27802):c_27802);
var r_27804 = ((raw_27803 >> (10)) & (31));
var g_27805 = ((raw_27803 >> (5)) & (31));
var b_27806 = (raw_27803 & (31));
var transparent_QMARK__27807 = (function (){var and__4120__auto__ = use_transparency_QMARK_;
if(and__4120__auto__){
if(is_8_bit_QMARK_){
return (c_27802 === (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_27804,g_27805,b_27806], null));
}
} else {
return and__4120__auto__;
}
})();
var argb_27808 = ((((((((transparent_QMARK__27807)?(0):(255)) << (8)) + (b_27806 * (8))) << (8)) + (g_27805 * (8))) << (8)) + (r_27804 * (8)));
set_pixel_BANG_.call(null,x_27800,y_27795,argb_27808);


var G__27809 = seq__27785_27796;
var G__27810 = chunk__27786_27797;
var G__27811 = count__27787_27798;
var G__27812 = (i__27788_27799 + (1));
seq__27785_27796 = G__27809;
chunk__27786_27797 = G__27810;
count__27787_27798 = G__27811;
i__27788_27799 = G__27812;
continue;
} else {
var temp__5720__auto___27813 = cljs.core.seq.call(null,seq__27785_27796);
if(temp__5720__auto___27813){
var seq__27785_27814__$1 = temp__5720__auto___27813;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__27785_27814__$1)){
var c__4550__auto___27815 = cljs.core.chunk_first.call(null,seq__27785_27814__$1);
var G__27816 = cljs.core.chunk_rest.call(null,seq__27785_27814__$1);
var G__27817 = c__4550__auto___27815;
var G__27818 = cljs.core.count.call(null,c__4550__auto___27815);
var G__27819 = (0);
seq__27785_27796 = G__27816;
chunk__27786_27797 = G__27817;
count__27787_27798 = G__27818;
i__27788_27799 = G__27819;
continue;
} else {
var x_27820 = cljs.core.first.call(null,seq__27785_27814__$1);
var offset_27821 = (((8) + image_offset) + (pixel_bytes * (x_27820 + (y_27795 * width))));
var c_27822 = read_pixel.call(null,image_buf,offset_27821);
var raw_27823 = ((is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_27822):c_27822);
var r_27824 = ((raw_27823 >> (10)) & (31));
var g_27825 = ((raw_27823 >> (5)) & (31));
var b_27826 = (raw_27823 & (31));
var transparent_QMARK__27827 = (function (){var and__4120__auto__ = use_transparency_QMARK_;
if(and__4120__auto__){
if(is_8_bit_QMARK_){
return (c_27822 === (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_27824,g_27825,b_27826], null));
}
} else {
return and__4120__auto__;
}
})();
var argb_27828 = ((((((((transparent_QMARK__27827)?(0):(255)) << (8)) + (b_27826 * (8))) << (8)) + (g_27825 * (8))) << (8)) + (r_27824 * (8)));
set_pixel_BANG_.call(null,x_27820,y_27795,argb_27828);


var G__27829 = cljs.core.next.call(null,seq__27785_27814__$1);
var G__27830 = null;
var G__27831 = (0);
var G__27832 = (0);
seq__27785_27796 = G__27829;
chunk__27786_27797 = G__27830;
count__27787_27798 = G__27831;
i__27788_27799 = G__27832;
continue;
}
} else {
}
}
break;
}

var G__27833 = seq__27777_27791;
var G__27834 = chunk__27782_27792;
var G__27835 = count__27783_27793;
var G__27836 = (i__27784_27794 + (1));
seq__27777_27791 = G__27833;
chunk__27782_27792 = G__27834;
count__27783_27793 = G__27835;
i__27784_27794 = G__27836;
continue;
} else {
var temp__5720__auto___27837 = cljs.core.seq.call(null,seq__27777_27791);
if(temp__5720__auto___27837){
var seq__27777_27838__$1 = temp__5720__auto___27837;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__27777_27838__$1)){
var c__4550__auto___27839 = cljs.core.chunk_first.call(null,seq__27777_27838__$1);
var G__27840 = cljs.core.chunk_rest.call(null,seq__27777_27838__$1);
var G__27841 = c__4550__auto___27839;
var G__27842 = cljs.core.count.call(null,c__4550__auto___27839);
var G__27843 = (0);
seq__27777_27791 = G__27840;
chunk__27782_27792 = G__27841;
count__27783_27793 = G__27842;
i__27784_27794 = G__27843;
continue;
} else {
var y_27844 = cljs.core.first.call(null,seq__27777_27838__$1);
var seq__27778_27845 = cljs.core.seq.call(null,cljs.core.range.call(null,width));
var chunk__27779_27846 = null;
var count__27780_27847 = (0);
var i__27781_27848 = (0);
while(true){
if((i__27781_27848 < count__27780_27847)){
var x_27849 = cljs.core._nth.call(null,chunk__27779_27846,i__27781_27848);
var offset_27850 = (((8) + image_offset) + (pixel_bytes * (x_27849 + (y_27844 * width))));
var c_27851 = read_pixel.call(null,image_buf,offset_27850);
var raw_27852 = ((is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_27851):c_27851);
var r_27853 = ((raw_27852 >> (10)) & (31));
var g_27854 = ((raw_27852 >> (5)) & (31));
var b_27855 = (raw_27852 & (31));
var transparent_QMARK__27856 = (function (){var and__4120__auto__ = use_transparency_QMARK_;
if(and__4120__auto__){
if(is_8_bit_QMARK_){
return (c_27851 === (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_27853,g_27854,b_27855], null));
}
} else {
return and__4120__auto__;
}
})();
var argb_27857 = ((((((((transparent_QMARK__27856)?(0):(255)) << (8)) + (b_27855 * (8))) << (8)) + (g_27854 * (8))) << (8)) + (r_27853 * (8)));
set_pixel_BANG_.call(null,x_27849,y_27844,argb_27857);


var G__27858 = seq__27778_27845;
var G__27859 = chunk__27779_27846;
var G__27860 = count__27780_27847;
var G__27861 = (i__27781_27848 + (1));
seq__27778_27845 = G__27858;
chunk__27779_27846 = G__27859;
count__27780_27847 = G__27860;
i__27781_27848 = G__27861;
continue;
} else {
var temp__5720__auto___27862__$1 = cljs.core.seq.call(null,seq__27778_27845);
if(temp__5720__auto___27862__$1){
var seq__27778_27863__$1 = temp__5720__auto___27862__$1;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__27778_27863__$1)){
var c__4550__auto___27864 = cljs.core.chunk_first.call(null,seq__27778_27863__$1);
var G__27865 = cljs.core.chunk_rest.call(null,seq__27778_27863__$1);
var G__27866 = c__4550__auto___27864;
var G__27867 = cljs.core.count.call(null,c__4550__auto___27864);
var G__27868 = (0);
seq__27778_27845 = G__27865;
chunk__27779_27846 = G__27866;
count__27780_27847 = G__27867;
i__27781_27848 = G__27868;
continue;
} else {
var x_27869 = cljs.core.first.call(null,seq__27778_27863__$1);
var offset_27870 = (((8) + image_offset) + (pixel_bytes * (x_27869 + (y_27844 * width))));
var c_27871 = read_pixel.call(null,image_buf,offset_27870);
var raw_27872 = ((is_8_bit_QMARK_)?cljs.core.nth.call(null,palette,c_27871):c_27871);
var r_27873 = ((raw_27872 >> (10)) & (31));
var g_27874 = ((raw_27872 >> (5)) & (31));
var b_27875 = (raw_27872 & (31));
var transparent_QMARK__27876 = (function (){var and__4120__auto__ = use_transparency_QMARK_;
if(and__4120__auto__){
if(is_8_bit_QMARK_){
return (c_27871 === (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_27873,g_27874,b_27875], null));
}
} else {
return and__4120__auto__;
}
})();
var argb_27877 = ((((((((transparent_QMARK__27876)?(0):(255)) << (8)) + (b_27875 * (8))) << (8)) + (g_27874 * (8))) << (8)) + (r_27873 * (8)));
set_pixel_BANG_.call(null,x_27869,y_27844,argb_27877);


var G__27878 = cljs.core.next.call(null,seq__27778_27863__$1);
var G__27879 = null;
var G__27880 = (0);
var G__27881 = (0);
seq__27778_27845 = G__27878;
chunk__27779_27846 = G__27879;
count__27780_27847 = G__27880;
i__27781_27848 = G__27881;
continue;
}
} else {
}
}
break;
}

var G__27882 = cljs.core.next.call(null,seq__27777_27838__$1);
var G__27883 = null;
var G__27884 = (0);
var G__27885 = (0);
seq__27777_27791 = G__27882;
chunk__27782_27792 = G__27883;
count__27783_27793 = G__27884;
i__27784_27794 = G__27885;
continue;
}
} else {
}
}
break;
}
}finally {octet.buffer._STAR_byte_order_STAR_ = _STAR_byte_order_STAR__orig_val__27775_27789;
}
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__27886 = image_descriptor;
var map__27886__$1 = (((((!((map__27886 == null))))?(((((map__27886.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27886.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27886):map__27886);
var resource = cljs.core.get.call(null,map__27886__$1,new cljs.core.Keyword(null,"resource","resource",251898836));
var image_id = cljs.core.get.call(null,map__27886__$1,new cljs.core.Keyword(null,"image-id","image-id",-988480565));
var art_dir = cljs.core.get.call(null,map__27886__$1,new cljs.core.Keyword(null,"art-dir","art-dir",67381390));
var idx_size = cljs.core.get.call(null,map__27886__$1,new cljs.core.Keyword(null,"idx-size","idx-size",893862481));
var idx_modified = cljs.core.get.call(null,map__27886__$1,new cljs.core.Keyword(null,"idx-modified","idx-modified",-1917929304));
var rsc_size = cljs.core.get.call(null,map__27886__$1,new cljs.core.Keyword(null,"rsc-size","rsc-size",-568560687));
var rsc_modified = cljs.core.get.call(null,map__27886__$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(resource),"/",cljs.core.str.cljs$core$IFn$_invoke$arity$1(image_id),"/",cljs.core.str.cljs$core$IFn$_invoke$arity$1(idx_size),"-",cljs.core.str.cljs$core$IFn$_invoke$arity$1(idx_modified),"-",cljs.core.str.cljs$core$IFn$_invoke$arity$1(rsc_size),"-",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),".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),".idx"].join('');
var rsc_path = [cljs.core.str.cljs$core$IFn$_invoke$arity$1(base),".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__27888_SHARP_){
return cljs.core._EQ_.call(null,image_id,new cljs.core.Keyword(null,"id","id",-1388402092).cljs$core$IFn$_invoke$arity$1(p1__27888_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));
if(cljs.core.not.call(null,image_data)){
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"warn","warn",-436710552),"weathergen.falcon.files.images",null,173,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay(((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,image_data){
return (function (){
return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, ["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], null);
});})(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))
,null)),null,-782082623);

return null;
} else {
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]);
}
});
