Changeset 6176 for extensions/ColorStat
- Timestamp:
- May 13, 2010, 10:21:05 PM (15 years ago)
- Location:
- extensions/ColorStat
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/ColorStat/admin/cstat_config.tpl
r6107 r6176 25 25 <script type="text/javascript"> 26 26 27 function displayConfig(tabsheet) 28 { 29 switch(tabsheet) 30 { 31 case 'database': 32 $('#iDisplayConfigDatabase').css('display', 'block'); 33 $('#iDisplayConfigStatSearch').css('display', 'none'); 34 $('#iDisplayConfigDisplay').css('display', 'none'); 35 break; 36 case 'statsearch': 37 $('#iDisplayConfigDatabase').css('display', 'none'); 38 $('#iDisplayConfigStatSearch').css('display', 'block'); 39 $('#iDisplayConfigDisplay').css('display', 'none'); 40 break; 41 case 'display': 42 $('#iDisplayConfigDatabase').css('display', 'none'); 43 $('#iDisplayConfigStatSearch').css('display', 'none'); 44 $('#iDisplayConfigDisplay').css('display', 'block'); 45 break; 46 } 47 48 } 27 49 28 50 function init() … … 38 60 }); 39 61 $("#icstat_stat_minPct_slider a").addClass('gcBgInput'); 62 displayConfig('database'); 40 63 } 41 64 … … 48 71 {/literal} 49 72 50 73 {$configTabsheet} 51 74 52 75 <h2>{'cstat_config_plugin'|@translate}</h2> … … 54 77 <form id="iConfig" method="post" action="" class="general"> 55 78 56 <fieldset> 57 <legend>{'cstat_stat_and_search'|@translate}</legend> 79 <div id='iDisplayConfigDatabase' style='display:none;'> 58 80 59 <table class="formtable"> 60 <tr> 61 <td colspan="2">{'cstat_percent_min_significant'|@translate}</td> 62 </tr> 63 <tr> 64 <td> 65 <input type="hidden" name="f_stat_minPct" id="icstat_stat_minPct" value="{$datas.minPct}"> 66 <div id="icstat_stat_minPct_slider" class="gcBgInput gcBorderInput"></div> 67 </td> 68 <td width="90px"> 69 <div id="icstat_stat_minPct_display"></div> 70 </td> 71 </tr> 72 </table> 81 </div> 73 82 74 </fieldset> 83 <div id='iDisplayConfigStatSearch' style='display:none;'> 84 <fieldset> 85 <legend>{'cstat_stat_and_search'|@translate}</legend> 75 86 87 <table class="formtable"> 88 <tr> 89 <td colspan="2">{'cstat_percent_min_significant'|@translate}</td> 90 </tr> 91 <tr> 92 <td> 93 <input type="hidden" name="f_stat_minPct" id="icstat_stat_minPct" value="{$datas.minPct}"> 94 <div id="icstat_stat_minPct_slider" class="gcBgInput gcBorderInput"></div> 95 </td> 96 <td width="90px"> 97 <div id="icstat_stat_minPct_display"></div> 98 </td> 99 </tr> 100 </table> 101 </fieldset> 102 </div> 76 103 77 <fieldset> 78 <legend>{'cstat_gallery_integration'|@translate}</legend> 104 <div id='iDisplayConfigDisplay' style='display:none;'> 105 <fieldset> 106 <legend>{'cstat_gallery_integration'|@translate}</legend> 79 107 80 <label>81 <input type="checkbox" id='idisplay_gallery_showColorsCBox' onclick="$('#idisplay_gallery_showColors').val(($('#idisplay_gallery_showColorsCBox').get(0).checked=='on')?'y':'n');" {if $datas.showColors=='y'}checked{/if} >82 {'cstat_display_colors_on_image'|@translate}83 <input type="hidden" id='idisplay_gallery_showColors' name='f_display_gallery_showColors' value='{$datas.showColors}'>84 </label>108 <label> 109 <input type="checkbox" id='idisplay_gallery_showColorsCBox' onclick="$('#idisplay_gallery_showColors').val(($('#idisplay_gallery_showColorsCBox').get(0).checked=='on')?'y':'n');" {if $datas.showColors=='y'}checked{/if} > 110 {'cstat_display_colors_on_image'|@translate} 111 <input type="hidden" id='idisplay_gallery_showColors' name='f_display_gallery_showColors' value='{$datas.showColors}'> 112 </label> 85 113 86 </fieldset> 87 88 114 </fieldset> 115 </div> 89 116 90 117 <input type="submit" value="{'cstat_apply'|@translate}" name="submit_save_config" style="margin-left:1em;" > -
extensions/ColorStat/admin/cstat_search.tpl
r6107 r6176 1 {known_script id="jquery.ui" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.core.packed.js"}2 {known_script id="jquery.ui.dialog" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.dialog.packed.js"}3 {known_script id="jquery.tipTip" src=$ROOT_URL|@cat:"themes/default/js/plugins/jquery.tipTip.minified.js"}4 5 {known_script id="gpc.pagesNavigator" src=$ROOT_URL|@cat:"plugins/GrumPluginClasses/js/pagesNavigator.js"}6 7 8 {literal}9 <script type="text/javascript">10 var cb=null;11 12 interfaceManager = function(optionsToSet)13 {14 var pn=null;15 var requestNumber=0;16 17 options =18 {19 requestCriterionsVisible:'',20 requestCriterionsHidden:'',21 requestResult:'',22 requestResultContent:'',23 requestResultNfo:'',24 requestResultPagesNavigator:'',25 requestResultRequestNumber:0,26 onPageChange:null,27 numberPerPage:30,28 };29 30 /**31 *32 */33 this.doAction = function(fct)34 {35 switch(fct)36 {37 case 'queryResult':38 /* function 'queryResult' : when query is executed, prepare the interface39 */40 if(arguments.length==3)41 {42 displayQueryResult(arguments[1], arguments[2]);43 }44 break;45 case 'queryPage':46 /* function 'queryPage' : display returned page47 */48 if(arguments.length==3)49 {50 displayQueryPage(arguments[1], arguments[2]);51 }52 break;53 case 'show':54 /* function 'show' : show/hide the query/result55 */56 if(arguments.length==2)57 {58 show(arguments[1]);59 }60 break;61 case 'setOptions':62 /* function 'setOptions' : allows to set options after the object was63 * created64 */65 if(arguments.length==2)66 {67 setOptions(arguments[1]);68 }69 break;70 }71 }72 73 /**74 * returns the current request number75 */76 this.getRequestNumber = function ()77 {78 return(requestNumber);79 }80 81 /**82 * returns the number of items per page83 */84 this.getNumberPerPage = function ()85 {86 return(options.numberPerPage);87 }88 89 /**90 * this function show/hide the different panels91 * 'buildQuery' : hide the result panel and display the panel to build query92 * 'resultQuery' : hide the panel to build query and display the result panel93 */94 var show = function(mode)95 {96 switch(mode)97 {98 case 'buildQuery':99 $('.'+options.requestCriterionsVisible).css('display', 'block');100 $('.'+options.requestCriterionsHidden).css('display', 'none');101 $('.'+options.requestResult).css('display', 'none');102 break;103 case 'resultQuery':104 $('#iResultQueryContent').html("<br><img src='./plugins/GrumPluginClasses/icons/processing.gif'>");105 $('.'+options.requestCriterionsVisible).css('display', 'none');106 $('.'+options.requestCriterionsHidden).css('display', 'block');107 $('.'+options.requestResult).css('display', 'block');108 break;109 }110 }111 112 /**113 * this function display the number of items found and prepare the page114 * navigator115 *116 * @param String nfo : 2 information separated with a semi-colon ';'117 * requestNumber;numberOfItems118 */119 var displayQueryResult = function (isSuccess, nfo)120 {121 if(isSuccess)122 {123 nfo=nfo.split(';');124 125 requestNumber=nfo[0];126 $('#iResultQueryNfo').html(nfo[1]);127 pn.doAction('setOptions', { numberItem:nfo[1], defaultPage:1 } );128 show('resultQuery');129 }130 else131 {132 //$('#'+options.requestResultContent).html("");133 show('buildQuery');134 alert('Something is wrong on the server-side !');135 }136 }137 138 139 /**140 * this function display the number of items found and prepare the page141 * navigator142 *143 * @param String nfo : 2 information separated with a semi-colon ';'144 * requestNumber;numberOfItems145 */146 var displayQueryPage = function (isSuccess, nfo)147 {148 if(isSuccess)149 {150 $('#iResultQueryContent').html(nfo);151 }152 else153 {154 alert('Something is wrong on the server-side !');155 }156 }157 158 159 /**160 *161 * @param Object optionsToSet : set the given options162 */163 var setOptions = function(optionsToSet)164 {165 if(typeof optionsToSet=='object')166 {167 options = jQuery.extend(options, optionsToSet);168 }169 }170 171 /**172 * initialize the object173 */174 var init = function (optionsToSet)175 {176 setOptions(optionsToSet);177 178 pn = new pagesNavigator(options.requestResultPagesNavigator,179 {180 itemPerPage:options.numberPerPage,181 displayNumPage:9,182 classActive:'pnActive{/literal}{$datas.themeName}{literal}',183 classInactive:'pnInactive{/literal}{$datas.themeName}{literal}',184 onPageChange: function (page)185 {186 if(options.onPageChange!=null && jQuery.isFunction(options.onPageChange))187 {188 options.onPageChange(requestNumber, page, options.numberPerPage);189 }190 },191 }192 );193 194 requestNumber=options.requestResultRequestNumber;195 }196 197 init(optionsToSet);198 }199 200 201 function init()202 {203 im = new interfaceManager(204 {205 requestCriterionsVisible:'cRequestCriterions',206 requestCriterionsHidden:'cModifyRequest',207 requestResult:'cResultQuery',208 requestResultContent:'iResultQueryContent',209 requestResultNfo:'iResultQueryNfo',210 requestResultPagesNavigator:'iPagesNavigator',211 }212 );213 214 requestBuilderOptions.imgEditUrl='{/literal}{$ROOT_URL}{$themeconf.admin_icon_dir}{literal}/edit_s.png';215 requestBuilderOptions.imgDeleteUrl='{/literal}{$ROOT_URL}{$themeconf.admin_icon_dir}{literal}/delete.png';216 requestBuilderOptions.classGroup='gcBorderInput gcTextInput';217 requestBuilderOptions.classItem='gcBgInput gcTextInput';218 requestBuilderOptions.classOperator='cbOperator cbOperatorBg{/literal}{$datas.themeName}{literal} gcLinkHover';219 requestBuilderOptions.onRequestSuccess = function (msg) { im.doAction('queryResult', true, msg); cb.doAction('getPage', im.getRequestNumber(), 1, im.getNumberPerPage()); };220 requestBuilderOptions.onRequestError = function (msg) { im.doAction('queryResult', false, msg); };221 requestBuilderOptions.onGetPageSuccess = function (msg) { im.doAction('queryPage', true, msg); };222 requestBuilderOptions.onGetPageError = function (msg) { im.doAction('queryPage', false, msg); };223 224 cb = new criteriaBuilder('iListColorsChoosen', requestBuilderOptions);225 226 im.doAction('setOptions',227 { onPageChange:228 function (requestNumber, page, numberPerPage)229 {230 $('#iResultQueryContent').html("<br><img src='./plugins/GrumPluginClasses/icons/processing.gif'>");231 cb.doAction('getPage', requestNumber, page, numberPerPage);232 }233 }234 );235 236 }237 238 239 240 </script>241 {/literal}242 243 {$datas.dialogBox}244 1 245 2 <h2>{'cstat_search_by_color'|@translate}</h2> 246 3 247 <form> 248 <fieldset> 249 <legend>{'cstat_search_criterion'|@translate}</legend> 250 251 <div id='iRequestCriterions' class='cRequestCriterions'> 252 <div style='width:100%;min-height:250px;margin-bottom:8px;'> 253 <ul id='iListColorsChoosen'> 254 </ul> 255 </div> 256 257 <div class='gcBgInput cbButtons'>{literal}<a onclick="colorBox.show({cBuilder:cb});">{/literal}{'cstat_add_colors'|@translate}</a></div> 258 <div class='gcBgInput cbButtons'>{literal}<a onclick="cb.doAction('clear');">{/literal}{'cstat_clear_colors'|@translate}</a></div> 259 </div> 260 <div class='cModifyRequest' style='display:none;'> 261 <div class='gcBgInput cbButtons'>{literal}<a onclick="im.doAction('show', 'buildQuery');">{/literal}{'cstat_do_modify_request'|@translate}</a></div> 262 </div> 263 264 </fieldset> 265 266 <input type="button" class='cRequestCriterions' style="margin-left:1em;" onclick="cb.doAction('send');" value="{'cstat_search'|@translate}"> 267 </form> 268 269 <fieldset id='iResultQuery' style='display:none;' class='cResultQuery'> 270 <legend>{'cstat_result_query'|@translate}</legend> 271 272 <div id='iResultQueryContent' style='width:100%;min-height:250px;max-height:450px;overflow:auto;margin-bottom:8px;'></div> 273 274 <div class='gcBgInput gcTextInput'> 275 <div id='iPagesNavigator' style='float:right;'></div> 276 <div style='text-align:left;padding:4px;'>{'cstat_number_of_item_found'|@translate} : <span id='iResultQueryNfo'></span></div> 277 </div> 278 279 </fieldset> 280 281 282 <script type="text/javascript"> 283 init(); 284 </script> 4 {$cstat_search_page} -
extensions/ColorStat/cstat.css
r6107 r6176 41 41 } 42 42 43 44 #iListColorsChoosen { padding:0px; }45 46 #iListColorsChoosen ul li, #dragHelper ul li {47 clear:both;48 min-height:32px;49 list-style-image:none;50 list-style-position:outside;51 list-style-type:none;52 margin:4px;53 padding:0px;54 }55 56 #iListColorsChoosen ul { padding:0px; }57 58 59 .cbGroup { border-width:1px; border-style:solid; padding:0px; margin:2px; min-height:30px; list-style:none; }60 .cbItem { padding:2px; margin:8px; min-height:34px; list-style:none; }61 62 #iListColorsChoosen ul li.cbItem, #dragHelper ul li.cbItem { padding:2px; }63 64 .cbItemButtons { padding:2px; }65 .cbItem img { cursor: pointer; }66 67 .cbSortHandle { cursor:move; }68 69 div.cbOperator {70 cursor:pointer;71 padding:4px;72 text-align:left;73 font-weight:bold;74 }75 76 div.cbOperatorBgroma {77 background:#333333;78 }79 80 div.cbOperatorBgclear {81 background:#dbe8f3;82 }83 84 .cbButtons {85 float:left;86 margin:2px;87 padding:8px;88 }89 90 .helper {91 border:2px dashed #777777;92 }93 94 .cPnActive, .cPnDisabled, .cPnInactive { margin:2px; padding:2px; min-width:20px; text-align:center; }95 .pnInactiveclear, .pnInactiveroma { cursor:pointer; }96 .pnInactiveclear:hover { background:#F1F1F1; }97 .pnActiveclear { background:#F1F1F1; font-weight:bold; }98 .pnInactiveroma:hover { background:#999999; color:#444444; }99 .pnActiveroma { background:#999999; color:#444444; font-weight:bold; }100 #iPagesNavigator ul { margin:0px; }101 102 43 .color1px { border-spacing:1px; } 103 44 .color0px { border-spacing:0px; } -
extensions/ColorStat/cstat_aip.class.inc.php
r6107 r6176 221 221 dirname($this->getFileLocation()).'/admin/cstat_stat.tpl'); 222 222 223 $colorTable= $this->getColorTableWithStat();223 $colorTable=CStat_functions::getColorTableWithStat(); 224 224 225 225 226 226 $datas=Array( 227 227 //'themeconf' => Array('name' => $template->get_themeconf('name')), 228 'colorTable' => $this->htmlColorTable(228 'colorTable' => CStat_functions::htmlColorTable( 229 229 $colorTable, 230 230 ($this->config['analyze_colorTable']=='small')?19:10, 231 231 "", 232 "color0px" 232 "color0px", 233 "<br>" 233 234 ), 234 235 'urlRequest' => $this->getAdminLink(), … … 250 251 dirname($this->getFileLocation()).'/admin/cstat_search.tpl'); 251 252 252 $datas=Array( 253 'dialogBox' => $this->dialogBoxColor(), 254 'themeName' => $template->get_themeconf('name'), 255 ); 256 257 $template->assign('datas', $datas); 253 $template->assign('cstat_search_page', GPCRequestBuilder::displaySearchPage()); 258 254 259 255 $template->assign_var_from_handle('CSTAT_BODY_PAGE', 'body_page'); … … 297 293 { 298 294 global $template, $lang; 295 296 $configTabs=new GPCTabSheet('configTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); 297 $configTabs->add('database', 298 l10n('cstat_database'), 299 '', true, "displayConfig('database');"); 300 $configTabs->add('statsearch', 301 l10n('cstat_stat_and_search'), 302 '', false, "displayConfig('statsearch');"); 303 $configTabs->add('display', 304 l10n('cstat_gallery_integration'), 305 '', false, "displayConfig('display');"); 306 $configTabs->assign(); 299 307 300 308 $template->set_filename('body_page', … … 390 398 391 399 392 protected function getGeneralStats()393 {394 $returned=Array(395 'nbImages' => 0,396 'totalTime' => 0,397 'pixelsAnalyzedMax' => 0,398 'pixelsAnalyzedMin' => 0,399 'pixelsAnalyzedAvg' => 0,400 'pixelsAnalyzedSum' => 0,401 'totalPixels' => 0,402 'ppsMax' => 0,403 'ppsMin' => 0,404 'ppsAvg' => 0,405 'qualityMax' => 0,406 'qualityMin' => 0,407 'qualityAvg' => 0,408 );409 $sql="SELECT COUNT(image_id) AS nbImages,410 SUM(time) AS totalTime,411 MAX(analyzed_pixels) AS pixelsAnalyzedMax,412 MIN(analyzed_pixels) AS pixelsAnalyzedMin,413 AVG(analyzed_pixels) AS pixelsAnalyzedAvg,414 SUM(analyzed_pixels) AS pixelsAnalyzedSum,415 SUM(num_pixels) AS totalPixels,416 MAX(pps) AS ppsMax,417 MIN(pps) AS ppsMin,418 AVG(pps) AS ppsAvg,419 MAX(quality) AS qualityMax,420 MIN(quality) AS qualityMin,421 AVG(quality) AS qualityAvg422 FROM ".$this->tables['images']."423 WHERE analyzed='y';";424 $result=pwg_query($sql);425 if($result)426 {427 while($row=pwg_db_fetch_assoc($result))428 {429 $returned=$row;430 }431 }432 return($returned);433 }434 435 436 400 /** 437 401 * make consolidation for the color_table : … … 626 590 { 627 591 $colorTable=ColorStat::getColorTable( 628 $this->colorTableSize[$this->config['analyze_colorTable']][0],629 $this->colorTableSize[$this->config['analyze_colorTable']][1]592 CStat_root::$colorTableSize[$this->config['analyze_colorTable']][0], 593 CStat_root::$colorTableSize[$this->config['analyze_colorTable']][1] 630 594 ); 631 595 … … 688 652 dirname($this->getFileLocation()).'/admin/cstat_stat_show_iListColors.tpl'); 689 653 690 $generalStats= $this->getGeneralStats();654 $generalStats=CStat_functions::getGeneralStats(); 691 655 692 656 $sql="SELECT color_id, num_images, num_pixels -
extensions/ColorStat/cstat_aip_install.class.inc.php
r6107 r6176 126 126 dirname($this->getFileLocation()).'/admin/cstat_install_page.tpl'); 127 127 128 $smallColorTable=ColorStat::getColorTable( $this->colorTableSize['small'][0],$this->colorTableSize['small'][1]);129 $largeColorTable=ColorStat::getColorTable( $this->colorTableSize['large'][0],$this->colorTableSize['large'][1]);130 $template->assign('smallTableColor', $this->htmlColorTable($smallColorTable, 19, '', 'color0px'));131 $template->assign('largeTableColor', $this->htmlColorTable($largeColorTable, 10, '', 'color0px'));128 $smallColorTable=ColorStat::getColorTable(CStat_root::$colorTableSize['small'][0],CStat_root::$colorTableSize['small'][1]); 129 $largeColorTable=ColorStat::getColorTable(CStat_root::$colorTableSize['large'][0],CStat_root::$colorTableSize['large'][1]); 130 $template->assign('smallTableColor', CStat_functions::htmlColorTable($smallColorTable, 19, '', 'color0px')); 131 $template->assign('largeTableColor', CStat_functions::htmlColorTable($largeColorTable, 10, '', 'color0px')); 132 132 133 133 $template->assign( 134 134 'smallColorList1', 135 $this->htmlColorList(135 CStat_functions::htmlColorList( 136 136 ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample1.png', $smallColorTable, Array('quality' => 8, 'numColors' => 16)), 137 137 16, 18, '', 'colorListSample color0px' … … 142 142 $template->assign( 143 143 'largeColorList1', 144 $this->htmlColorList(144 CStat_functions::htmlColorList( 145 145 ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample1.png', $largeColorTable, Array('quality' => 8, 'numColors' => 16)), 146 146 16, 18, '', 'colorListSample color0px' … … 151 151 $template->assign( 152 152 'smallColorList2', 153 $this->htmlColorList(153 CStat_functions::htmlColorList( 154 154 ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample2.png', $smallColorTable, Array('quality' => 8, 'numColors' => 16)), 155 155 16, 18, '', 'colorListSample color0px' … … 160 160 $template->assign( 161 161 'largeColorList2', 162 $this->htmlColorList(162 CStat_functions::htmlColorList( 163 163 ColorStat::getFileColors(dirname($this->getFileLocation()).'/image/sample2.png', $largeColorTable, Array('quality' => 8, 'numColors' => 16)), 164 164 16, 18, '', 'colorListSample color0px' … … 205 205 $this->saveConfig(); 206 206 207 $colorTable=ColorStat::getColorTable( $this->colorTableSize[$tableSize][0],$this->colorTableSize[$tableSize][1]);208 209 foreach($colorTable as $key => $ val)207 $colorTable=ColorStat::getColorTable(CStat_root::$colorTableSize[$tableSize][0],CStat_root::$colorTableSize[$tableSize][1]); 208 209 foreach($colorTable as $key => $hue) 210 210 { 211 foreach($ val as $key2 => $val2)211 foreach($hue as $key2 => $saturation) 212 212 { 213 $hsv=$val2->get(); 214 $sql.=(($sql=="")?"":", ")."('".$val2->getRGB()->getHexString()."', 215 '".$hsv['H']."', 216 '".$hsv['S']."', 217 '".$hsv['V']."', 218 0, 0)"; 213 foreach($saturation as $key3=>$value) 214 { 215 $hsv=$value->get(); 216 $sql.=(($sql=="")?"":", ")."('".$value->getRGB()->getHexString()."', 217 '".$hsv['H']."', 218 '".$hsv['S']."', 219 '".$hsv['V']."', 220 0, 0)"; 221 } 219 222 } 220 223 } -
extensions/ColorStat/cstat_colorstat.class.inc.php
r6107 r6176 46 46 --------------------------------------------------------------------------- */ 47 47 48 if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 48 if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 49 50 /** 51 * if DEBUG_MODE is set to true, the getFileColors function save a jpg file of 52 * the 'viewed' image : 53 * - resampled file 54 * - color from the color table 55 * 56 * use it only for debug, or if you are curious about what the function really 57 * see 58 */ 59 define('DEBUG_MODE', false); 60 61 49 62 50 63 /** … … 59 72 } 60 73 74 /** 75 * set the R,G and B values 76 * 77 * @param Byte $R : the red value, between [0..255] 78 * @param Byte $G : the green value, between [0..255] 79 * @param Byte $B : the blue value, between [0..255] 80 * @return Array('R'=>$R, 'G'=>$G, 'B'=>$B) 81 */ 61 82 public function set($R, $G, $B) 62 83 { … … 67 88 } 68 89 90 /** 91 * set RGB values from an Integer (0xFFFFFF : white value) 92 * 93 * @param Integer $value : the RGB value 94 * @return Array('R'=>$R, 'G'=>$G, 'B'=>$B) 95 */ 69 96 public function setInt($value) 70 97 { … … 76 103 } 77 104 105 /** 106 * returns the current RGB values as array 107 * 108 * @param Boolean $floatValue : if set to true, values are returned as float 109 * values between [0..1] otherwise values are 110 * returned as integer between [0..255] 111 * @return Array('R'=>$R, 'G'=>$G, 'B'=>$B) 112 */ 78 113 public function get($floatValue=false) 79 114 { … … 94 129 } 95 130 131 132 /** 133 * returns the current RGB values as hex string ('FFFFFF' : white) 134 * 135 * @return String 136 */ 96 137 public function getHexString() 97 138 { … … 99 140 } 100 141 142 /** 143 * returns the current RGB values as integer (0xFFFFFF : white) 144 * 145 * @return Integer 146 */ 101 147 public function getInt() 102 148 { … … 104 150 } 105 151 152 153 /** 154 * returns the current RGB values as a HSV object 155 * 156 * @return HSV 157 */ 106 158 public function getHSV() 107 159 { … … 109 161 } 110 162 163 /** 164 * set the RGB values from a HSV ojbect 165 * 166 * @param HSV $hsv : a HSV object 167 */ 111 168 public function setHSV(HSV $hsv) 112 169 { … … 118 175 } 119 176 177 /** 178 * set the RGB property 179 * 180 * @param String $property : 'R', 'G', 'B' 181 * @param Integer $value : value between [0..255] 182 * @return Integer : value of the property 183 */ 120 184 private function setProperty($property, $value) 121 185 { … … 143 207 } 144 208 209 /** 210 * set the H, S and V values 211 * 212 * @param Integer $H : the hue value, between [0..360] 213 * @param Byte $S : the saturation value, between [0..100] 214 * @param Byte $V : the value value, between [0..100] 215 * @return Array('H'=>$H, 'S'=>$S, 'V'=>$V) 216 */ 145 217 public function set($H, $S, $V) 146 218 { … … 151 223 } 152 224 225 /** 226 * returns the current HSV values as array 227 * 228 * @return Array('H'=>$H, 'S'=>$S, 'V'=>$V) 229 */ 153 230 public function get() 154 231 { … … 156 233 } 157 234 235 /** 236 * returns the current HSV values as a RGB object 237 * 238 * @return RGB 239 */ 158 240 public function getRGB() 159 241 { … … 161 243 } 162 244 245 246 247 /** 248 * set the HSV values from a RGB ojbect 249 * 250 * @param RGB $rgb : a RGB object 251 */ 163 252 public function setRGB(RGB $rgb) 164 253 { … … 170 259 } 171 260 261 /** 262 * set the HSV property 263 * 264 * @param String $property : 'H', 'S', 'V' 265 * @param Integer $value : value between [0..255] 266 * @return Integer : value of the property 267 */ 172 268 private function setProperty($property, $value) 173 269 { … … 203 299 204 300 /** 301 * returns colors of an image file 302 * 303 * return : 304 * 305 * 205 306 * 206 307 * @param String $fileName : the name of picture to scan … … 212 313 * if 'maxTime' and 'pps' are greater than zero, the 213 314 * quality parameter is computed automatically 214 * @return Array : an array of HSV objects 315 * @return : -1 if file doesn't exist 316 * -2 if file is not a PNG, a JPEG or a GIF file 317 * -3 if a fatal error occurs 318 * array of HSV objects if everthing is Ok 215 319 */ 216 320 static function getFileColors($fileName, $colorTable, $options=array()) … … 229 333 $time=microtime(true); 230 334 231 if(preg_match('/.*\.gif$/i', $fileName))335 try 232 336 { 233 $image = imagecreatefromgif($fileName); 337 if(preg_match('/.*\.gif$/i', $fileName)) 338 { 339 $image = imagecreatefromgif($fileName); 340 } 341 elseif(preg_match('/.*\.(jpg|jpeg)$/i', $fileName)) 342 { 343 $image = imagecreatefromjpeg($fileName); 344 } 345 elseif(preg_match('/.*\.png$/i', $fileName)) 346 { 347 $image = imagecreatefrompng($fileName); 348 } 349 else 350 { 351 return(-2); 352 } 353 354 355 $imageWidth=imagesx($image); 356 $imageHeight=imagesy($image); 357 358 if($options['pps']>0 && $options['maxTime']>0) 359 { 360 $quality=round(sqrt($imageWidth*$imageHeight/($options['pps']*$options['maxTime'])), 0); 361 } 362 else 363 { 364 $quality=$options['quality']; 365 } 366 367 $imageWorkWidth=round($imageWidth/$quality,0); 368 $imageWorkHeight=round($imageHeight/$quality,0); 369 $imageWork=imagecreatetruecolor($imageWorkWidth,$imageWorkHeight); 370 imagecopyresampled($imageWork, $image, 0, 0, 0, 0, $imageWorkWidth, $imageWorkHeight, $imageWidth, $imageHeight); 371 //imagecopyresized($imageWork, $image, 0, 0, 0, 0, $imageWorkWidth, $imageWorkHeight, $imageWidth, $imageHeight); 372 imagedestroy($image); 373 374 $returned=Array(); 375 376 $i=0; 377 for($px=0;$px<$imageWorkWidth;$px++) 378 { 379 for($py=0;$py<$imageWorkHeight;$py++) 380 { 381 $i++; 382 $value=imagecolorat($imageWork, $px, $py); 383 384 $rgb=self::IntToRGB($value); 385 //echo sprintf("%06x", $value)." => ".$rgb->getHexString(); 386 387 388 //echo " ($i) ".$color->getHexString()."<br>"; 389 390 if(DEBUG_MODE) 391 { 392 $color=self::getColorFromTable($rgb->getHSV(), $colorTable); 393 $newRGB=$color->get(); 394 $col=imagecolorallocate($imageWork, $newRGB['R'], $newRGB['G'], $newRGB['B']); 395 imagesetpixel($imageWork, $px, $py, $col); 396 imagecolordeallocate($imageWork, $col); 397 $color=$color->getHexString(); 398 unset($newRGB); 399 } 400 else 401 { 402 $color=self::getColorFromTable($rgb->getHSV(), $colorTable)->getHexString(); 403 } 404 405 406 if(array_key_exists($color, $returned)) 407 { 408 $returned[$color]['num']++; 409 } 410 else 411 { 412 $returned[$color]=Array( 413 'hsv' => $rgb->getHSV()->get(), 414 'num' => 1, 415 'pct' => 0, 416 ); 417 } 418 unset($rgb); 419 } 420 } 421 422 423 if(DEBUG_MODE) 424 { 425 $fName="q".$quality."_c".$options['numColors']."_nb".count($returned)."_".$fileName.".png"; 426 imagepng($imageWork, $fName); 427 } 428 429 430 imagedestroy($imageWork); 431 uasort($returned, Array('ColorStat', 'sortTones')); 432 433 if($options['numColors']>0) 434 { 435 foreach($returned as $key=>$val) 436 { 437 $returnedColors[$key]=$val; 438 $options['numColors']--; 439 if($options['numColors']<=0) break; 440 } 441 } 442 else 443 { 444 $returnedColors=$returned; 445 } 446 447 self::$fileColorsStat=Array( 448 'pixels' => $imageWidth*$imageHeight, 449 'analyzed' => $i, 450 'time' => microtime(true)-$time, 451 'colors' => count($returned), 452 'pps' => $i/(microtime(true)-$time), 453 'quality' => $quality, 454 ); 455 456 if(DEBUG_MODE) 457 { 458 self::$fileColorsStat['fileName']=$fName; 459 } 460 461 unset($returned); 462 463 foreach($returnedColors as $key => $val) 464 { 465 $returnedColors[$key]['pct']=round(100*$val['num']/self::$fileColorsStat['analyzed'],2); 466 } 467 468 return($returnedColors); 234 469 } 235 elseif(preg_match('/.*\.(jpg|jpeg)$/i', $fileName))470 catch (Exception $e) 236 471 { 237 $image = imagecreatefromjpeg($fileName); 472 echo "ERROR!<br>".print_r($e, true); 473 return(-3); 238 474 } 239 elseif(preg_match('/.*\.png$/i', $fileName)) 240 { 241 $image = imagecreatefrompng($fileName); 242 } 243 else 244 { 245 return(-2); 246 } 247 248 $imageWidth=imagesx($image); 249 $imageHeight=imagesy($image); 250 251 if($options['pps']>0 && $options['maxTime']>0) 252 { 253 $quality=round(sqrt($imageWidth*$imageHeight/($options['pps']*$options['maxTime'])), 0); 254 } 255 else 256 { 257 $quality=$options['quality']; 258 } 259 260 $imageWorkWidth=round($imageWidth/$quality,0); 261 $imageWorkHeight=round($imageHeight/$quality,0); 262 $imageWork=imagecreatetruecolor($imageWorkWidth,$imageWorkHeight); 263 imagecopyresampled($imageWork, $image, 0, 0, 0, 0, $imageWorkWidth, $imageWorkHeight, $imageWidth, $imageHeight); 264 //imagecopyresized($imageWork, $image, 0, 0, 0, 0, $imageWorkWidth, $imageWorkHeight, $imageWidth, $imageHeight); 265 imagedestroy($image); 266 267 $returned=Array(); 268 269 $i=0; 270 for($px=0;$px<$imageWorkWidth;$px++) 271 { 272 for($py=0;$py<$imageWorkHeight;$py++) 273 { 274 $i++; 275 $value=imagecolorat($imageWork, $px, $py); 276 277 $rgb=self::IntToRGB($value); 278 //echo sprintf("%06x", $value)." => ".$rgb->getHexString(); 279 280 $color=self::getColorFromTable($rgb->getHSV(), $colorTable)->getHexString(); 281 //echo " ($i) $color<br>"; 282 283 if(array_key_exists($color, $returned)) 284 { 285 $returned[$color]['num']=$returned[$color]['num']+1; 286 } 287 else 288 { 289 $returned[$color]=Array( 290 'hsv' => $rgb->getHSV()->get(), 291 'num' => 1, 292 'pct' => 0, 293 ); 294 } 295 unset($rgb); 296 } 297 } 298 299 /* 300 $fName="q".$quality."_c".$options['numColors']."_".$fileName.".png"; 301 imagepng($imageWork, $fName); 302 */ 303 304 imagedestroy($imageWork); 305 uasort($returned, Array('ColorStat', 'sortTones')); 306 307 if($options['numColors']>0) 308 { 309 foreach($returned as $key=>$val) 310 { 311 $returnedColors[$key]=$val; 312 $options['numColors']--; 313 if($options['numColors']<=0) break; 314 } 315 } 316 else 317 { 318 $returnedColors=$returned; 319 } 320 321 self::$fileColorsStat=Array( 322 'pixels' => $imageWidth*$imageHeight, 323 'analyzed' => $i, 324 'time' => microtime(true)-$time, 325 'colors' => count($returned), 326 'pps' => $i/(microtime(true)-$time), 327 'quality' => $quality, 328 //'fileName' => $fName, 329 ); 330 331 unset($returned); 332 333 foreach($returnedColors as $key => $val) 334 { 335 $returnedColors[$key]['pct']=round(100*$val['num']/self::$fileColorsStat['analyzed'],2); 336 } 337 338 return($returnedColors); 475 339 476 } 340 477 else … … 432 569 /** 433 570 * return a color table 434 * $table = Array( 435 * Array(), 436 * Array(), 437 * ... 438 * Array(), 439 * Array(), 440 * ) 441 * $table[n] => Array of all colors for a given hue value 442 * $table[n][m] => HSV object or a color string RRGGBB 443 * 571 * $table[h][s][v] => HSV object or string 'RRGGBB' 444 572 * 445 573 * @param Int $huePrec : degree of precision for hue [1..360] 446 574 * @param Float $prec : precision step for saturation & value [1..100] 447 575 * @param String $returnedType : 'HSV' => return a HSV object 448 * 'color' => return a color string RRGGBB576 * 'color' => return a color string 'RRGGBB' 449 577 * @return Array : the color table 450 578 */ … … 452 580 { 453 581 $returned=Array(); 454 for($hue=0;$hue< =360;$hue+=$huePrec)582 for($hue=0;$hue<360;$hue+=$huePrec) 455 583 { 456 584 $hueValues=Array(); 457 585 458 $saturation=100; 459 for($value=0;$value<100;$value=$value+=$prec) 586 for($saturation=0;$saturation<=100;$saturation+=$prec) 460 587 { 461 $hsv=new HSV($hue, $saturation, $value); 462 if($returnedType=='HSV') 463 { 464 $hueValues[]=$hsv; 465 } 466 else 467 { 468 $hueValues[]=$hsv->getRGB()->getHexString(); 469 } 470 unset($hsv); 588 $saturationValues=Array(); 589 590 for($value=0;$value<=100;$value+=$prec) 591 { 592 $hsv=new HSV($hue, $saturation, $value); 593 if($returnedType=='HSV') 594 { 595 $saturationValues[$value]=$hsv; 596 } 597 else 598 { 599 $saturationValues[$value]=$hsv->getRGB()->getHexString(); 600 } 601 unset($hsv); 602 } 603 604 $hueValues[$saturation]=$saturationValues; 605 unset($saturationValues); 471 606 } 472 473 $value=100; 474 for($saturation=100;$saturation>=0;$saturation-=$prec) 475 { 476 $hsv=new HSV($hue, $saturation, $value); 477 if($returnedType=='HSV') 478 { 479 $hueValues[]=$hsv; 480 } 481 else 482 { 483 $hueValues[]=$hsv->getRGB()->getHexString(); 484 } 485 unset($hsv); 486 } 487 488 489 for($tmp=$prec;$tmp<=100;$tmp+=$prec) 490 { 491 $hsv=new HSV($hue, $tmp, 100-$tmp); 492 if($returnedType=='HSV') 493 { 494 $hueValues[]=$hsv; 495 } 496 else 497 { 498 $hueValues[]=$hsv->getRGB()->getHexString(); 499 } 500 unset($hsv); 501 } 502 for($tmp=$prec;$tmp<=100;$tmp+=$prec) 503 { 504 $hsv=new HSV($hue, $tmp, $tmp); 505 if($returnedType=='HSV') 506 { 507 $hueValues[]=$hsv; 508 } 509 else 510 { 511 $hueValues[]=$hsv->getRGB()->getHexString(); 512 } 513 unset($hsv); 514 } 515 516 $returned[]=$hueValues; 607 $returned[$hue]=$hueValues; 517 608 unset($hueValues); 518 609 } 519 610 520 $hue=0;521 $saturation=0;522 $hueValues=Array();523 //$prec=1/(count($returned[0])-2);524 for($value=0;$value<=100;$value+=$prec/4)525 {526 $hsv=new HSV($hue, $saturation, round($value,0));527 if($returnedType=='HSV')528 {529 $hueValues[]=$hsv;530 }531 else532 {533 $hueValues[]=$hsv->getRGB()->getHexString();534 }535 unset($hsv);536 }537 538 $returned[]=$hueValues;539 unset($hueValues);540 611 541 612 return($returned); … … 621 692 } 622 693 623 static public function getColorFromTable(HSV $hsvObject, $colorTable) 624 { 625 $hue=360/(count($colorTable)-2); 626 $step=count($colorTable[0]); 627 //echo "*hue:$hue<br>"; 628 //echo "*step:$step<br>"; 629 694 /** 695 * for the given color, return the nearest color of the color table 696 * 697 * @param HSV $hsvObject : the color, as HSV object 698 * @param Array $colorTable : the colorTable 699 * @param String $mode : 'HSV' or 'RGB' to define the returned object 700 * @return HSV or RGB : the color 701 */ 702 static public function getColorFromTable(HSV $hsvObject, $colorTable, $mode='RGB') 703 { 630 704 $hsv=$hsvObject->get(); 631 705 //echo "*H:".$hsv['H']." "; 706 //echo "*S:".$hsv['S']." "; 707 //echo "*V:".$hsv['V']."<br>"; 708 709 $hue=360/count($colorTable); 632 710 $hueNumber=round($hsv['H']/$hue,0); 633 //echo "*hueNumber:$hueNumber<br>"; 634 635 //echo "*H:".$hsv['H']."<br>"; 636 //echo "*S:".$hsv['S']."<br>"; 711 $step=100/(count($colorTable[0])-1); 712 //echo "*H_Step:$hue<br>"; 713 //echo "*SV_Step:$step<br>"; 714 715 $hsv['S']=round((100/$step)*$hsv['S']/100,0)*$step; 716 $hsv['V']=round((100/$step)*$hsv['V']/100,0)*$step; 717 $hsv['H']=($hueNumber*$hue)%360; 718 //echo "*H:".$hsv['H']." "; 719 //echo "*S:".$hsv['S']." "; 637 720 //echo "*V:".$hsv['V']."<br>"; 638 721 639 if($hsv['V']==0) 640 { 641 //echo "-black-<br>"; 642 // black 643 return(new RGB(0,0,0)); 644 } 645 elseif($hsv['S']==0 && $hsv['V']==100) 646 { 647 //echo "-white-<br>"; 648 // white 649 return(new RGB(255,255,255)); 650 } 651 elseif($hsv['S']==0 && $hsv['V']<100 && $hsv['V']>0) 652 { 653 //echo "-grey-<br>"; 654 // grey 655 $stepNumber=round($hsv['V']*($step-1)/100,0); 656 return($colorTable[count($colorTable)-1][$stepNumber]->getRGB()); 657 } 658 elseif($hsv['S']==100 && $hsv['V']<100 && $hsv['V']>0) 659 { 660 //echo "-value-<br>"; 661 //color 'value' 662 $stepNumber=round($hsv['V']*$step/400,0); 663 return($colorTable[$hueNumber][$stepNumber]->getRGB()); 664 } 665 elseif($hsv['V']==100 && $hsv['S']<100 && $hsv['S']>0) 666 { 667 //echo "-saturation-<br>"; 668 //color 'saturation' 669 $stepNumber=round(($step/4)+(100-$hsv['S'])*($step/400),0); 670 return($colorTable[$hueNumber][$stepNumber]->getRGB()); 671 } 672 elseif($hsv['V']==100 && $hsv['S']==100) 673 { 674 //echo "-pure-<br>"; 675 //color 'pure' 676 $stepNumber=$step/4; 677 return($colorTable[$hueNumber][$stepNumber]->getRGB()); 678 } 679 elseif( 680 ($hsv['V']<100 && $hsv['V']>50 && $hsv['S']<50 && $hsv['S']>0) || 681 ($hsv['S']<100 && $hsv['S']>50 && $hsv['V']<50 && $hsv['V']>0)) 682 { 683 //echo "-desaturated 1-<br>"; 684 //color 'desaturated' 685 $stepNumber=($step/2)+(100-$hsv['V'])*$step/400; 686 return($colorTable[$hueNumber][$stepNumber]->getRGB()); 687 } 688 elseif($hsv['V']<100 && $hsv['V']>0 && $hsv['S']<100 && $hsv['S']>0) 689 { 690 //echo "-desaturated 2-<br>"; 691 //color 'desaturated' 692 $stepNumber=($step*0.75)+$hsv['V']*$step/400; 693 return($colorTable[$hueNumber][$stepNumber]->getRGB()); 694 } 695 //echo "-none-<br>"; 696 return(new RGB(0,0,0)); 722 if($mode=='RGB') 723 { 724 return($colorTable[$hsv['H']][$hsv['S']][$hsv['V']]->getRGB()); 725 } 726 else 727 { 728 return($colorTable[$hsv['H']][$hsv['S']][$hsv['V']]); 729 } 697 730 } 698 731 -
extensions/ColorStat/cstat_install.class.inc.php
r6107 r6176 125 125 quality=0;"); 126 126 pwg_query("INSERT INTO ".$this->tables['images']." 127 SELECT id, 'n', 0, 0, 0, 0, 0, 0, '' 127 SELECT id, 'n', 0, 0, 0, 0, 0, 0, '', '' 128 128 FROM ".IMAGES_TABLE." 129 129 WHERE id NOT IN (SELECT image_id FROM ".$this->tables['images'].")"); -
extensions/ColorStat/cstat_pip.class.inc.php
r6107 r6176 68 68 global $page, $template; 69 69 70 $colors= $this->getImageColors($page['image_id']);70 $colors=CStat_functions::getImageColors($page['image_id']); 71 71 72 72 … … 85 85 'TITLE' => l10n('cstat_colors'), 86 86 'lines' => Array( 87 l10n('cstat_colors_on_image') => $this->htmlColorList($tmp, 8, 25, "", "color1px", "/"),87 l10n('cstat_colors_on_image') => CStat_functions::htmlColorList($tmp, 8, 25, "", "color1px", "/"), 88 88 ) 89 89 ); -
extensions/ColorStat/cstat_rb_callback.class.inc.php
r6107 r6176 15 15 if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 16 16 17 //include_once('') 17 18 include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); 18 19 … … 119 120 * return HTML code for a given colors list 120 121 * 121 * ==> this is the same function than the CStat_root::htmlColorList() function122 * make a copy here only top optimize performance (don't load the123 * CStat_root file for one function)124 122 * 125 123 * @param Array $colors : list of colors … … 163 161 } 164 162 163 164 /** 165 * this function is called by the request builder to make the search page, and 166 * must return the HTML & JS code of the dialogbox used to select criterion 167 * 168 * Notes : 169 * - the dialogbox is a JS object with a public method 'show' 170 * - when the method show is called, one parameter is given by the request 171 * builder ; the parameter is an object defined as this : 172 * { 173 * cBuilder: an instance of the criteriaBuilder object used in the page, 174 * eventOK : a callback function, called when the OK button is pushed 175 * id: 176 * } 177 * 178 * 179 * 180 * 181 * @param String $mode : can take 'admin' or 'public' values, allowing to 182 * return different interface if needed 183 * @return String : HTML formatted value 184 */ 185 static public function getInterfaceContent($mode='admin') 186 { 187 return(CStat_functions::dialogBoxColor()); 188 } 189 190 /** 191 * this function returns the label displayed in the criterion menu 192 * 193 * @return String : label displayed in the criterions menu 194 */ 195 static public function getInterfaceLabel() 196 { 197 return(l10n('cstat_add_colors')); 198 } 199 200 /** 201 * this function returns the name of the dialog box class 202 * 203 * @return String : name of the dialogbox class 204 */ 205 static public function getInterfaceDBClass() 206 { 207 return('dialogChooseColorBox'); 208 } 209 165 210 } 166 211 -
extensions/ColorStat/cstat_root.class.inc.php
r6107 r6176 24 24 class CStat_root extends CommonPlugin 25 25 { 26 static public $pluginName='ColorStat'; 27 static public $pluginNameFile='cstat'; 28 static public $pluginTables=array('images', 'color_table', 'images_colors'); 29 static public $colorTableSize=Array('small' => Array(30,20), 'large' => Array(10,10)); 30 26 31 protected $css; //the css object 27 protected $colorTableSize=Array('small' => Array(30,20), 'large' => Array(10,10));28 32 29 33 public function __construct($prefixeTable, $filelocation) 30 34 { 31 $this->setPluginName( 'ColorStat');32 $this->setPluginNameFiles( "cstat");35 $this->setPluginName(self::$pluginName); 36 $this->setPluginNameFiles(self::$pluginNameFile); 33 37 parent::__construct($prefixeTable, $filelocation); 34 38 $this->section_name=$this->getPluginNameFiles(); 35 39 36 $this->setTablesList( array('images', 'color_table', 'images_colors'));40 $this->setTablesList(self::$pluginTables); 37 41 38 42 … … 67 71 $this->config=array( 68 72 'newInstall' => 'n', 69 'analyze_maxTime' => 0.1,73 'analyze_maxTime' => 1, 70 74 'analyze_colorTable' => 'small', 71 75 'analyze_pps' => 0, … … 73 77 'display_gallery_showColors' => 'n', 74 78 'display_stat_orderType' => 'img', 75 'stat_minPct' => 3.5, 76 ); 79 'stat_minPct' => 1.5, 80 ); 81 } 82 83 /* --------------------------------------------------------------------------- 84 ajax functions 85 --------------------------------------------------------------------------- */ 86 87 88 } //class 89 90 91 class CStat_functions 92 { 93 static private $tables = Array(); 94 static private $config = Array(); 95 96 /** 97 * initialise the class 98 * 99 * @param String $prefixeTable : the piwigo prefixe used on tables name 100 * @param String $pluginNameFile : the plugin name used for tables name 101 */ 102 static public function init($prefixeTable) 103 { 104 GPCCore::loadConfig(CStat_root::$pluginNameFile, self::$config); 105 $list=CStat_root::$pluginTables; 106 107 for($i=0;$i<count($list);$i++) 108 { 109 self::$tables[$list[$i]]=$prefixeTable.CStat_root::$pluginNameFile.'_'.$list[$i]; 110 } 111 } 112 113 /** 114 * return a color table with stat on color 115 * 116 * @return Array : a color table with statistics on colors 117 */ 118 static public function getColorTableWithStat() 119 { 120 $generalStats=self::getGeneralStats(); 121 122 $colors=Array(); 123 $sql="SELECT color_id, num_images, num_pixels 124 FROM ".self::$tables['color_table']." 125 WHERE num_images > 0 126 ORDER BY color_id "; 127 $result=pwg_query($sql); 128 if($result) 129 { 130 while($row=pwg_db_fetch_assoc($result)) 131 { 132 $colors[$row['color_id']]=Array('num_images' => $row['num_images'], 'num_pixels' => $row['num_pixels']); 133 } 134 } 135 136 $colorTable=ColorStat::getColorTable( 137 CStat_root::$colorTableSize[self::$config['analyze_colorTable']][0], 138 CStat_root::$colorTableSize[self::$config['analyze_colorTable']][1] 139 ); 140 141 foreach($colorTable as $key=>$hue) 142 { 143 foreach($hue as $key2=>$saturation) 144 { 145 foreach($saturation as $key3=>$value) 146 { 147 $rgb=$value->getRGB()->getHexString(); 148 $colorTable[$key][$key2][$key3]=Array( 149 'color' => $rgb, 150 'pct' => '', //(array_key_exists($rgb, $colors))?sprintf("%.2f", round(100*$colors[$rgb]['num_pixels']/$generalStats['pixelsAnalyzedSum'],2)):"", 151 'num' => (array_key_exists($rgb, $colors))?$colors[$rgb]['num_images']:"", 152 ); 153 } 154 } 155 } 156 157 unset($colors); 158 return($colorTable); 77 159 } 78 160 … … 86 168 * @return String : HTML code 87 169 */ 88 public function htmlColorTable($colorTable, $size=5, $id="", $class="")170 static public function htmlColorTable($colorTable, $size=5, $id="", $class="", $br='<br>') 89 171 { 90 172 global $template; 91 173 92 174 $template->set_filename('color_table_page', 93 dirname($this->getFileLocation()).'/templates/cstat_color_table.tpl'); 94 175 dirname(__FILE__).'/templates/cstat_color_table.tpl'); 176 177 switch(count($colorTable)) 178 { 179 case 12; 180 $break=4; 181 $size=10; 182 break; 183 case 15; 184 $break=5; 185 $size=10; 186 break; 187 case 18; 188 $break=6; 189 $size=5; 190 break; 191 case 20; 192 $break=5; 193 $size=10; 194 break; 195 case 24; 196 $break=6; 197 $size=5; 198 break; 199 case 30; 200 $break=6; 201 $size=5; 202 break; 203 case 36; 204 $break=6; 205 $size=5; 206 break; 207 case 45; 208 $break=9; 209 $size=3; 210 break; 211 } 212 213 $colors=Array(); 95 214 $nbHue=count($colorTable); 96 215 $nbStep=count($colorTable[0]); 97 $colors=Array(); 98 for($step=0;$step<$nbStep;$step++) 99 { 100 $row=Array(); 101 for($hue=0;$hue<$nbHue;$hue++) 102 { 103 104 if($colorTable[$hue][$step] instanceof HSV) 216 $col=0; 217 $row=0; 218 foreach($colorTable as $key => $hue) 219 { 220 $lrow=0; 221 foreach($hue as $key2 => $saturation) 222 { 223 $lcol=0; 224 foreach($saturation as $key3 => $value) 105 225 { 106 $row[]=Array('color' => $colorTable[$hue][$step]->getRGB()->getHexString(), 'pct' => "", 'num' => ""); 226 //if(!($col!=0 and $hsv['V']==0) and !($row!=0 and $hsv['S']==0)) 227 $trow=$lcol+$col*$nbStep; 228 $tcol=$lrow+$row*$nbStep; 229 230 if($colorTable[$key][$key2][$key3] instanceof HSV) 231 { 232 $colors[$tcol][$trow]=Array('color' => $colorTable[$key][$key2][$key3]->getRGB()->getHexString(), 'pct' => "", 'num' => ""); 233 } 234 elseif(is_array($colorTable[$key][$key2][$key3])) 235 { 236 $colors[$tcol][$trow]=Array( 237 'color' => (array_key_exists('color', $colorTable[$key][$key2][$key3]))?$colorTable[$key][$key2][$key3]['color']:"", 238 'pct' => (array_key_exists('pct', $colorTable[$key][$key2][$key3]))?$colorTable[$key][$key2][$key3]['pct']:"", 239 'num' => (array_key_exists('num', $colorTable[$key][$key2][$key3]))?$colorTable[$key][$key2][$key3]['num']:"", 240 ); 241 } 242 else 243 { 244 $colors[$tcol][$trow]=Array('color' => $colorTable[$key][$key2][$key3], 'pct' => "", 'num' => ""); 245 } 246 $lcol++; 107 247 } 108 elseif(is_array($colorTable[$hue][$step])) 109 { 110 $row[]=Array( 111 'color' => (array_key_exists('color', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['color']:"", 112 'pct' => (array_key_exists('pct', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['pct']:"", 113 'num' => (array_key_exists('num', $colorTable[$hue][$step]))?$colorTable[$hue][$step]['num']:"", 114 ); 115 } 116 else 117 { 118 $row[]=Array('color' => $colorTable[$hue][$step], 'pct' => "", 'num' => ""); 119 } 120 } 121 $colors[]=$row; 122 unset($row); 123 } 124 125 $data=array( 126 'colorTable' => $colors, 127 'size' => $size, 128 'id' => $id, 129 'class' => $class 130 ); 131 132 $template->assign('data', $data); 133 unset($data); 134 135 return($template->parse('color_table_page', true)); 136 } 137 138 /** 139 * return HTML code for a given colors list 140 * 141 * @param Array $colors : list of colors 142 * @param Int $size : size for colorbox in the HTML table 143 * @return String : HTML code 144 */ 145 public function htmlColorList($colorList, $split=8, $size=5, $id="", $class="", $br='<br>') 146 { 147 global $template; 148 149 $template->set_filename('color_table_page', 150 dirname($this->getFileLocation()).'/templates/cstat_color_table.tpl'); 151 152 $colors=Array(); 153 154 $row=0; 155 $num=0; 156 foreach($colorList as $key => $val) 157 { 158 $colors[$row][]=Array('color' => $key, 'pct' => $val['pct'], 'num' => ""); 159 $num++; 160 if($num==$split) 161 { 162 $num=0; 248 $lrow++; 249 } 250 251 $col++; 252 if($col==$break) 253 { 254 $col=0; 163 255 $row++; 164 256 } … … 180 272 181 273 /** 274 * return HTML code for a given colors list 275 * 276 * @param Array $colors : list of colors 277 * @param Int $size : size for colorbox in the HTML table 278 * @return String : HTML code 279 */ 280 static public function htmlColorList($colorList, $split=8, $size=5, $id="", $class="", $br='<br>') 281 { 282 global $template; 283 284 $template->set_filename('color_table_page', 285 dirname(__FILE__).'/templates/cstat_color_table.tpl'); 286 287 $colors=Array(); 288 289 $row=0; 290 $num=0; 291 foreach($colorList as $key => $val) 292 { 293 $colors[$row][]=Array('color' => $key, 'pct' => $val['pct'], 'num' => ""); 294 $num++; 295 if($num==$split) 296 { 297 $num=0; 298 $row++; 299 } 300 } 301 302 $data=array( 303 'colorTable' => $colors, 304 'size' => $size, 305 'id' => $id, 306 'class' => $class, 307 'br' => $br, 308 ); 309 310 $template->assign('data', $data); 311 unset($data); 312 313 return($template->parse('color_table_page', true)); 314 } 315 316 /** 182 317 * returns an array of colors & colors percent of an image 183 318 * … … 185 320 * @return Array('colors' => Array(), 'colors_pct' => Array()) 186 321 */ 187 public function getImageColors($imageId)322 static public function getImageColors($imageId) 188 323 { 189 324 $returned=Array( … … 193 328 194 329 $sql="SELECT colors, colors_pct 195 FROM ". $this->tables['images']."330 FROM ".self::$tables['images']." 196 331 WHERE image_id='".$imageId."'"; 197 332 $result=pwg_query($sql); … … 208 343 209 344 210 211 345 /** 212 346 * return all HTML&JS code necessary to display a dialogbox to choose 213 347 * colors 214 348 */ 215 protectedfunction dialogBoxColor()349 static public function dialogBoxColor() 216 350 { 217 351 global $template; 218 352 219 353 $template->set_filename('colors_choose', 220 dirname( $this->getFileLocation()).'/templates/cstat_dialog_colors_choose.tpl');221 222 $colorTable= $this->getColorTableWithStat();354 dirname(__FILE__).'/templates/cstat_dialog_colors_choose.tpl'); 355 356 $colorTable=CStat_functions::getColorTableWithStat(); 223 357 224 358 $datas=Array( 225 'colorTable' => $this->htmlColorTable(359 'colorTable' => CStat_functions::htmlColorTable( 226 360 $colorTable, 227 ( $this->config['analyze_colorTable']=='small')?16:8,361 (self::$config['analyze_colorTable']=='small')?16:8, 228 362 "", 229 363 "color0px" … … 240 374 241 375 /** 242 * return a color table with stat on color 243 * 244 * @return Array : a color table with statistics on colors 245 */ 246 protected function getColorTableWithStat() 247 { 248 $generalStats=$this->getGeneralStats(); 249 250 $colors=Array(); 251 $sql="SELECT color_id, num_images, num_pixels 252 FROM ".$this->tables['color_table']." 253 WHERE num_images > 0 254 ORDER BY color_id "; 376 * returns general stats on the analyzed colors process 377 * 378 * @return Array : array with keys 379 * 'nbImages', 'timeMax', 'timeMin', 'timeSum', 380 * 'pixelsAnalyzedMax', 'pixelsAnalyzedMin', 381 * 'pixelsAnalyzedAvg', 'pixelsAnalyzedSum', 'totalPixels', 382 * 'ppsMax', 'ppsMin', 'ppsAvg', 'qualityMax', 383 * 'qualityMin', 'qualityAvg' 384 */ 385 static public function getGeneralStats() 386 { 387 $returned=Array( 388 'nbImages' => 0, 389 'timeMax' => 0, 390 'timeMin' => 0, 391 'timeSum' => 0, 392 'pixelsAnalyzedMax' => 0, 393 'pixelsAnalyzedMin' => 0, 394 'pixelsAnalyzedAvg' => 0, 395 'pixelsAnalyzedSum' => 0, 396 'totalPixels' => 0, 397 'ppsMax' => 0, 398 'ppsMin' => 0, 399 'ppsAvg' => 0, 400 'qualityMax' => 0, 401 'qualityMin' => 0, 402 'qualityAvg' => 0, 403 ); 404 $sql="SELECT COUNT(image_id) AS nbImages, 405 MAX(time) AS timeMax, 406 MIN(time) AS timeMin, 407 SUM(time) AS timeSum, 408 MAX(analyzed_pixels) AS pixelsAnalyzedMax, 409 MIN(analyzed_pixels) AS pixelsAnalyzedMin, 410 AVG(analyzed_pixels) AS pixelsAnalyzedAvg, 411 SUM(analyzed_pixels) AS pixelsAnalyzedSum, 412 SUM(num_pixels) AS totalPixels, 413 MAX(pps) AS ppsMax, 414 MIN(pps) AS ppsMin, 415 AVG(pps) AS ppsAvg, 416 MAX(quality) AS qualityMax, 417 MIN(quality) AS qualityMin, 418 AVG(quality) AS qualityAvg 419 FROM ".self::$tables['images']." 420 WHERE analyzed='y';"; 255 421 $result=pwg_query($sql); 256 422 if($result) … … 258 424 while($row=pwg_db_fetch_assoc($result)) 259 425 { 260 $colors[$row['color_id']]=Array('num_images' => $row['num_images'], 'num_pixels' => $row['num_pixels']); 261 } 262 } 263 264 $colorTable=ColorStat::getColorTable( 265 $this->colorTableSize[$this->config['analyze_colorTable']][0], 266 $this->colorTableSize[$this->config['analyze_colorTable']][1] 267 ); 268 foreach($colorTable as $key=>$val) 269 { 270 foreach($val as $key2=>$val2) 271 { 272 $rgb=$val2->getRGB()->getHexString(); 273 $colorTable[$key][$key2]=Array( 274 'color' => $rgb, 275 'pct' => '', //(array_key_exists($rgb, $colors))?sprintf("%.2f", round(100*$colors[$rgb]['num_pixels']/$generalStats['pixelsAnalyzedSum'],2)):"", 276 'num' => (array_key_exists($rgb, $colors))?$colors[$rgb]['num_images']:"", 277 ); 278 } 279 } 280 281 unset($colors); 282 return($colorTable); 283 } 284 285 286 287 288 289 /* --------------------------------------------------------------------------- 290 ajax functions 291 --------------------------------------------------------------------------- */ 292 293 294 } //class 426 $returned=$row; 427 } 428 } 429 return($returned); 430 } 431 432 } //CStat_functions 295 433 296 434 ?> -
extensions/ColorStat/language/fr_FR/plugin.lang.php
r6107 r6176 23 23 Travailler sur une gamme réduite de couleurs augmente la probabilité de référencer des teintes minoritaires. Ceci a pour avantage de permettre d'effectuer des recherches sur des gammes de couleurs plus larges. 24 24 25 En contrepartie, la variation des nuances étant plus réduite, la pertinence des résultats lors de la recherche sur une couleur p articulière peut s'avérer peu probante.";25 En contrepartie, la variation des nuances étant plus réduite, la pertinence des résultats lors de la recherche sur une couleur peut s'avérer étonnante, notamment sur les images peu saturées."; 26 26 $lang['cstat_help_large_color_table'] = " 27 27 Travailler sur une gamme élargie de couleurs permet de disposer d'un nombre accru de nuances pour une teinte donnée. Ceci a pour avantage de permettre d'affiner les recherches sur une gamme de couleurs plus précise et augmenter ainsi la pertinence des résultats. … … 79 79 $lang['cstat_color_already_choosen']='La couleur est déjà sélectionnée dans la liste'; 80 80 $lang['cstat_add_colors']='Ajouter une sélection de couleurs'; 81 $lang['cstat_clear_colors']='Réinitialiser les critères'; 82 $lang['cstat_do_modify_request']='Modifier la recherche'; 83 $lang['cstat_search_criterion'] = 'Critères de recherche'; 84 $lang['cstat_number_of_item_found']='Nombre d\'images trouvées'; 85 $lang['cstat_result_query']='Résultat de la recherche'; 81 86 82 87 83 $lang['cstat_config']='Configuration'; -
extensions/ColorStat/main.inc.php
r6107 r6176 78 78 //CStat admin interface loaded and active only if in admin page 79 79 include_once("cstat_aim.class.inc.php"); 80 CStat_functions::init($prefixeTable); 80 81 $obj=new CStat_AIM($prefixeTable, __FILE__); 81 82 $obj->initEvents(); -
extensions/ColorStat/templates/cstat_color_table.tpl
r6107 r6176 4 4 {foreach from=$row item=col} 5 5 <td id="cellColor_{$col.color}" style="width:{$data.size}px;height:{$data.size}px;background-color:#{$col.color};{if $col.num!=''}cursor:pointer;{/if}" class="tiptip {if $col.num!=''}csSelectable{/if}" 6 title=" {'cstat_color'|@translate} #{$col.color}{if $col.num!=''} : {$col.num} {'cstat_images'|@translate}{/if}{if $col.pct!=''} {$data.br} {'cstat_surface'|@translate} {$col.pct}%{/if}">6 title="<table><tr style='vertical-align:middle;'><td><div style='display:inline-block;width:18px;height:18px;background-color:#{$col.color};'></div></td><td style='display:inline-block;'>{'cstat_color'|@translate} #{$col.color}{if $col.num!=''} : {$col.num} {'cstat_images'|@translate}{/if}{if $col.pct!=''} {$data.br} {'cstat_surface'|@translate} {$col.pct}%{/if}</td></tr></table>"> 7 7 </td> 8 8 {/foreach} -
extensions/ColorStat/templates/cstat_dialog_colors_choose.tpl
r6107 r6176 300 300 {/literal} 301 301 302 <div id="iDialogColorChoose" >302 <div id="iDialogColorChoose" style='display:none;'> 303 303 <table style="padding-top:8px;"> 304 304 <tr> … … 320 320 </div> 321 321 322 <script type="text/javascript"> 323 var colorBox=new dialogChooseColorBox(); 324 </script> 322
Note: See TracChangeset
for help on using the changeset viewer.