Commit 8957a60a authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

abs path for get-image.php

parent f86fa0bd
/** /**
* @file jquery-jp4.js * @file jquery-jp4.js
* @brief a jquery plugin to convert jp4/jp46 into human viewable format * @brief a jquery plugin to convert jp4/jp46 into human viewable format
* @copyright Copyright (C) 2016 Elphel Inc. * @copyright Copyright (C) 2016 Elphel Inc.
* @author Oleg Dzhimiev <oleg@elphel.com> * @author Oleg Dzhimiev <oleg@elphel.com>
* *
* @licstart The following is the entire license notice for the * @licstart The following is the entire license notice for the
* JavaScript code in this page. * JavaScript code in this page.
* *
* The JavaScript code in this page is free software: you can * The JavaScript code in this page is free software: you can
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
*/ */
(function ( $ ) { (function ( $ ) {
//https://gist.github.com/leolux/c794fc63d9c362013448 //https://gist.github.com/leolux/c794fc63d9c362013448
var JP4 = function(element,options){ var JP4 = function(element,options){
var elem = $(element); var elem = $(element);
var obj = this; var obj = this;
var settings = $.extend({ var settings = $.extend({
ip: "", ip: "",
port: "", port: "",
...@@ -57,11 +57,11 @@ ...@@ -57,11 +57,11 @@
},options); },options);
var DEBUG = settings.debug; var DEBUG = settings.debug;
// working time // working time
var T0; var T0;
var TX; var TX;
var BAYER = settings.mosaic; var BAYER = settings.mosaic;
var FLIPV = 0; var FLIPV = 0;
var FLIPH = 0; var FLIPH = 0;
...@@ -69,15 +69,15 @@ ...@@ -69,15 +69,15 @@
var SATURATION = [0,0,0,0]; var SATURATION = [0,0,0,0];
var PIXELS = []; var PIXELS = [];
// only valid values are allowed otherwise - disable // only valid values are allowed otherwise - disable
if ((settings.lowres!=0)&&(settings.lowres!=1)&&(settings.lowres!=2)&&(settings.lowres!=4)&&(settings.lowres!=8)){ if ((settings.lowres!=0)&&(settings.lowres!=1)&&(settings.lowres!=2)&&(settings.lowres!=4)&&(settings.lowres!=8)){
settings.lowres = 0; settings.lowres = 0;
} }
var cnv_working = $("<canvas>",{id:"working"}); var cnv_working = $("<canvas>",{id:"working"});
var cnv_display = $("<canvas>",{id:"display"}); var cnv_display = $("<canvas>",{id:"display"});
// hide working canvas // hide working canvas
cnv_working.css({display:"none"}); cnv_working.css({display:"none"});
/* /*
...@@ -87,19 +87,19 @@ ...@@ -87,19 +87,19 @@
left: "500px" left: "500px"
}); });
*/ */
elem.append(cnv_working); elem.append(cnv_working);
elem.append(cnv_display); elem.append(cnv_display);
if (DEBUG){ if (DEBUG){
TX = Date.now(); TX = Date.now();
T0 = Date.now(); T0 = Date.now();
} }
if (settings.fromhtmlinput){ if (settings.fromhtmlinput){
/* /*
* if image is being loaded from <input type='file'> * if image is being loaded from <input type='file'>
* make sure the image data starts with: "data:image/jpeg;base64," * make sure the image data starts with: "data:image/jpeg;base64,"
* EXIF.js does not like empty data type: "data:;base64," * EXIF.js does not like empty data type: "data:;base64,"
*/ */
process_image(settings.image); process_image(settings.image);
...@@ -107,15 +107,15 @@ ...@@ -107,15 +107,15 @@
send_request(); send_request();
} }
//end //end
function send_request(){ function send_request(){
var rq = ""; var rq = "";
var http = new XMLHttpRequest(); var http = new XMLHttpRequest();
if (settings.port!=""&&settings.ip!=""){ if (settings.port!=""&&settings.ip!=""){
rq = "get-image.php?ip="+settings.ip+"&port="+settings.port+"&rel=bimg&ts="+Date.now(); rq = "/get-image.php?ip="+settings.ip+"&port="+settings.port+"&rel=bimg&ts="+Date.now();
//rq = "get-image.php?ip="+settings.ip+"&port="+settings.port+"&rel=img&ts="+Date.now(); //rq = "get-image.php?ip="+settings.ip+"&port="+settings.port+"&rel=img&ts="+Date.now();
//settings.refresh = true; //settings.refresh = true;
}else{ }else{
...@@ -136,56 +136,56 @@ ...@@ -136,56 +136,56 @@
process_image(imgdata); process_image(imgdata);
} }
}; };
http.send(); http.send();
} }
this.refresh = function(){ this.refresh = function(){
send_request(); send_request();
} }
this.resize = function(w){ this.resize = function(w){
settings.width = w; settings.width = w;
send_request(); send_request();
} }
this.setAddr = function(url,port){ this.setAddr = function(url,port){
settings.port = port; settings.port = port;
settings.ip = url; settings.ip = url;
return 0; return 0;
} }
this.getFormat = function(){ this.getFormat = function(){
return this.format; return this.format;
} }
this.getAddr = function(){ this.getAddr = function(){
return Array(settings.ip,settings.port); return Array(settings.ip,settings.port);
} }
function process_image(imagedata){ function process_image(imagedata){
var canvas = cnv_working; var canvas = cnv_working;
//reset format //reset format
IMAGE_FORMAT = "JPEG"; IMAGE_FORMAT = "JPEG";
var heavyImage = new Image(); var heavyImage = new Image();
heavyImage.onload = function(){ heavyImage.onload = function(){
EXIF.getData(this, function() { EXIF.getData(this, function() {
var cnv_w; var cnv_w;
var cnv_h; var cnv_h;
if (settings.lowres!=0){ if (settings.lowres!=0){
cnv_w = this.width/settings.lowres; cnv_w = this.width/settings.lowres;
cnv_h = this.height/settings.lowres; cnv_h = this.height/settings.lowres;
...@@ -193,13 +193,13 @@ ...@@ -193,13 +193,13 @@
cnv_w = this.width; cnv_w = this.width;
cnv_h = this.height; cnv_h = this.height;
} }
//update canvas size //update canvas size
canvas.attr("width",cnv_w); canvas.attr("width",cnv_w);
canvas.attr("height",cnv_h); canvas.attr("height",cnv_h);
parseEXIFMakerNote(this); parseEXIFMakerNote(this);
canvas.drawImage({ canvas.drawImage({
x:0, y:0, x:0, y:0,
source: this, source: this,
...@@ -218,33 +218,33 @@ ...@@ -218,33 +218,33 @@
}; };
heavyImage.src = imagedata; heavyImage.src = imagedata;
} }
function redraw(){ function redraw(){
//for debugging //for debugging
//IMAGE_FORMAT="JPEG"; //IMAGE_FORMAT="JPEG";
$(this).draw({ $(this).draw({
fn: function(ctx){ fn: function(ctx){
if (DEBUG){ if (DEBUG){
console.log("#"+elem.attr("id")+", raw image drawn time: "+(Date.now()-TX)/1000+" s"); console.log("#"+elem.attr("id")+", raw image drawn time: "+(Date.now()-TX)/1000+" s");
TX = Date.now(); TX = Date.now();
} }
if (IMAGE_FORMAT=="JPEG"){ if (IMAGE_FORMAT=="JPEG"){
// if JP4/JP46 it will work through webworker and exit later on workers message // if JP4/JP46 it will work through webworker and exit later on workers message
Elphel.Canvas.drawScaled(cnv_working,cnv_display,settings.width); Elphel.Canvas.drawScaled(cnv_working,cnv_display,settings.width);
if (DEBUG){ if (DEBUG){
console.log("#"+elem.attr("id")+", Total time: "+(Date.now()-T0)/1000+" s"); console.log("#"+elem.attr("id")+", Total time: "+(Date.now()-T0)/1000+" s");
} }
$(this).trigger("canvas_ready"); $(this).trigger("canvas_ready");
if (settings.refresh) { if (settings.refresh) {
if (DEBUG){ if (DEBUG){
TX = Date.now(); TX = Date.now();
...@@ -252,14 +252,14 @@ ...@@ -252,14 +252,14 @@
} }
send_request(); send_request();
} }
}else if ((IMAGE_FORMAT=="JP4")||(IMAGE_FORMAT=="JP46")){ }else if ((IMAGE_FORMAT=="JP4")||(IMAGE_FORMAT=="JP46")){
if (settings.fast){ if (settings.fast){
quickestPreview(ctx); quickestPreview(ctx);
}/*else{ }/*else{
Elphel.reorderJP4Blocks(ctx,"JP4"); Elphel.reorderJP4Blocks(ctx,"JP4");
if (settings.precise){ if (settings.precise){
PIXELS = Elphel.pixelsToArrayLinear(ctx); PIXELS = Elphel.pixelsToArrayLinear(ctx);
Elphel.demosaicBilinear(ctx,PIXELS,settings.mosaic,true); Elphel.demosaicBilinear(ctx,PIXELS,settings.mosaic,true);
...@@ -292,17 +292,17 @@ ...@@ -292,17 +292,17 @@
// Taking SATURATION[0] = 1/GAMMA[0] (green pixel of GR-line) // Taking SATURATION[0] = 1/GAMMA[0] (green pixel of GR-line)
//saturation(ctx,SATURATION[0]); //saturation(ctx,SATURATION[0]);
} }
// too early // too early
//console.log("#"+elem.attr("id")+", time: "+(Date.now()-t0)/1000+" s"); //console.log("#"+elem.attr("id")+", time: "+(Date.now()-t0)/1000+" s");
} }
}); });
} }
function quickestPreview(ctx){ function quickestPreview(ctx){
var worker = new Worker(settings.webworker_path+'/webworker.js'); var worker = new Worker(settings.webworker_path+'/webworker.js');
if (DEBUG){ if (DEBUG){
TX = Date.now(); TX = Date.now();
} }
...@@ -311,17 +311,17 @@ ...@@ -311,17 +311,17 @@
//ctx.canvas.height = ctx.canvas.height/2; //ctx.canvas.height = ctx.canvas.height/2;
//ctx.canvas.style.width = ctx.canvas.style.width/4; //ctx.canvas.style.width = ctx.canvas.style.width/4;
//ctx.canvas.style.height = ctx.canvas.style.height/4; //ctx.canvas.style.height = ctx.canvas.style.height/4;
var width = ctx.canvas.width; var width = ctx.canvas.width;
var height = ctx.canvas.height; var height = ctx.canvas.height;
var image = ctx.getImageData(0,0,width,height); var image = ctx.getImageData(0,0,width,height);
var pixels = image.data; var pixels = image.data;
if (DEBUG){ if (DEBUG){
console.log("#"+elem.attr("id")+", data from canvas for webworker time: "+(Date.now()-TX)/1000+" s"); console.log("#"+elem.attr("id")+", data from canvas for webworker time: "+(Date.now()-TX)/1000+" s");
TX = Date.now(); TX = Date.now();
} }
worker.postMessage({ worker.postMessage({
mosaic: settings.mosaic, mosaic: settings.mosaic,
format: IMAGE_FORMAT, format: IMAGE_FORMAT,
...@@ -336,31 +336,31 @@ ...@@ -336,31 +336,31 @@
lowres: settings.lowres lowres: settings.lowres
}, },
},[pixels.buffer]); },[pixels.buffer]);
worker.onmessage = function(e){ worker.onmessage = function(e){
var pixels = new Uint8Array(e.data.pixels); var pixels = new Uint8Array(e.data.pixels);
var working_context = cnv_working[0].getContext('2d'); var working_context = cnv_working[0].getContext('2d');
var width = e.data.width; var width = e.data.width;
var height = e.data.height; var height = e.data.height;
if (DEBUG){ if (DEBUG){
console.log("#"+elem.attr("id")+", worker time: "+(Date.now()-TX)/1000+" s"); console.log("#"+elem.attr("id")+", worker time: "+(Date.now()-TX)/1000+" s");
TX = Date.now(); TX = Date.now();
} }
Elphel.Canvas.putImageData(working_context,pixels,width,height); Elphel.Canvas.putImageData(working_context,pixels,width,height);
Elphel.Canvas.drawScaled(cnv_working,cnv_display,settings.width); Elphel.Canvas.drawScaled(cnv_working,cnv_display,settings.width);
if (DEBUG){ if (DEBUG){
// report time // report time
console.log("#"+elem.attr("id")+", Total time: "+(Date.now()-T0)/1000+" s"); console.log("#"+elem.attr("id")+", Total time: "+(Date.now()-T0)/1000+" s");
} }
//trigger here //trigger here
cnv_working.trigger("canvas_ready"); cnv_working.trigger("canvas_ready");
if (settings.refresh) { if (settings.refresh) {
if (DEBUG){ if (DEBUG){
TX = Date.now(); TX = Date.now();
...@@ -369,7 +369,7 @@ ...@@ -369,7 +369,7 @@
send_request(); send_request();
} }
} }
} }
/** /**
...@@ -381,21 +381,21 @@ ...@@ -381,21 +381,21 @@
* @SATURATION[i] - not used * @SATURATION[i] - not used
*/ */
function parseEXIFMakerNote(src){ function parseEXIFMakerNote(src){
var exif_orientation = EXIF.getTag(src,"Orientation"); var exif_orientation = EXIF.getTag(src,"Orientation");
//console.log("Exif:Orientation: "+exif_orientation); //console.log("Exif:Orientation: "+exif_orientation);
var MakerNote = EXIF.getTag(src,"MakerNote"); var MakerNote = EXIF.getTag(src,"MakerNote");
//FLIPH & FLIPV //FLIPH & FLIPV
if (typeof MakerNote !== 'undefined'){ if (typeof MakerNote !== 'undefined'){
FLIPH = (MakerNote[10] )&0x1; FLIPH = (MakerNote[10] )&0x1;
FLIPV = (MakerNote[10]>>1)&0x1; FLIPV = (MakerNote[10]>>1)&0x1;
var tmpBAYER = Array(); var tmpBAYER = Array();
for (var i=0;i<BAYER.length;i++){tmpBAYER[i] = BAYER[i].slice();} for (var i=0;i<BAYER.length;i++){tmpBAYER[i] = BAYER[i].slice();}
if (FLIPV==1){ if (FLIPV==1){
for(i=0;i<4;i++){BAYER[(i>>1)][(i%2)] = tmpBAYER[1-(i>>1)][(i%2)];} for(i=0;i<4;i++){BAYER[(i>>1)][(i%2)] = tmpBAYER[1-(i>>1)][(i%2)];}
for(i=0;i<BAYER.length;i++){tmpBAYER[i] = BAYER[i].slice();} for(i=0;i<BAYER.length;i++){tmpBAYER[i] = BAYER[i].slice();}
...@@ -404,29 +404,29 @@ ...@@ -404,29 +404,29 @@
for(i=0;i<4;i++){BAYER[(i>>1)][(i%2)] = tmpBAYER[(i>>1)][1-(i%2)];} for(i=0;i<4;i++){BAYER[(i>>1)][(i%2)] = tmpBAYER[(i>>1)][1-(i%2)];}
} }
} }
//console.log("MakerNote: Flips: V:"+FLIPV+" H:"+FLIPH); //console.log("MakerNote: Flips: V:"+FLIPV+" H:"+FLIPH);
//COLOR_MODE ---------------------------------------------------------------- //COLOR_MODE ----------------------------------------------------------------
var color_mode = 0; var color_mode = 0;
if (typeof MakerNote !== 'undefined') color_mode=(MakerNote[10]>>4)&0x0f; if (typeof MakerNote !== 'undefined') color_mode=(MakerNote[10]>>4)&0x0f;
switch(color_mode){ switch(color_mode){
case 2: IMAGE_FORMAT = "JP46"; break; case 2: IMAGE_FORMAT = "JP46"; break;
case 5: IMAGE_FORMAT = "JP4"; break; case 5: IMAGE_FORMAT = "JP4"; break;
//default: //default:
} }
obj.format = IMAGE_FORMAT; obj.format = IMAGE_FORMAT;
//var gains = Array(); //var gains = Array();
//var blacks = Array(); //var blacks = Array();
var gammas = Array(); var gammas = Array();
//var gamma_scales = Array(); //var gamma_scales = Array();
//var blacks256 = Array(); //var blacks256 = Array();
//var rgammas = Array(); //var rgammas = Array();
//SATURATION ---------------------------------------------------------------- //SATURATION ----------------------------------------------------------------
if (typeof MakerNote !== 'undefined'){ if (typeof MakerNote !== 'undefined'){
for(i=0;i<4;i++){ for(i=0;i<4;i++){
...@@ -437,7 +437,7 @@ ...@@ -437,7 +437,7 @@
} }
/* /*
for (i=0;i<4;i++) { for (i=0;i<4;i++) {
rgammas[i]=elphel_gamma_calc(gammas[i], blacks[i], gamma_scales[i]); rgammas[i]=elphel_gamma_calc(gammas[i], blacks[i], gamma_scales[i]);
} }
console.log(rgammas); console.log(rgammas);
//adjusting gains to have the result picture in the range 0..256 //adjusting gains to have the result picture in the range 0..256
...@@ -455,7 +455,7 @@ ...@@ -455,7 +455,7 @@
} }
//console.log("MakerNote: Saturations: "+SATURATION[0]+" "+SATURATION[1]+" "+SATURATION[2]+" "+SATURATION[3]); //console.log("MakerNote: Saturations: "+SATURATION[0]+" "+SATURATION[1]+" "+SATURATION[2]+" "+SATURATION[3]);
} }
} }
/* /*
...@@ -468,7 +468,7 @@ ...@@ -468,7 +468,7 @@
k=1.0/(256.0-black256); k=1.0/(256.0-black256);
if (gamma < 0.13) gamma=0.13; if (gamma < 0.13) gamma=0.13;
if (gamma >10.0) gamma=10.0; if (gamma >10.0) gamma=10.0;
for (var i=0;i<257;i++) { for (var i=0;i<257;i++) {
x=k*(i-black256); x=k*(i-black256);
if (x<0.0) x=0.0; if (x<0.0) x=0.0;
...@@ -484,30 +484,30 @@ ...@@ -484,30 +484,30 @@
outValue=128+(i<<8); outValue=128+(i<<8);
while ((gtable[indx+1]<outValue) && (indx<256)) indx++; while ((gtable[indx+1]<outValue) && (indx<256)) indx++;
if (indx>=256) rgtable[i]=65535.0/256; if (indx>=256) rgtable[i]=65535.0/256;
else if (gtable[indx+1]==gtable[indx]) else if (gtable[indx+1]==gtable[indx])
rgtable[i]=i; rgtable[i]=i;
else else
rgtable[i]=indx+(1.0*(outValue-gtable[indx]))/(gtable[indx+1] - gtable[indx]); rgtable[i]=indx+(1.0*(outValue-gtable[indx]))/(gtable[indx+1] - gtable[indx]);
} }
return rgtable; return rgtable;
} }
*/ */
}; };
$.fn.jp4 = function(options){ $.fn.jp4 = function(options){
var element = $(this); var element = $(this);
// Return early if this element already has a plugin instance // Return early if this element already has a plugin instance
if (element.data('jp4')) return element.data('jp4'); if (element.data('jp4')) return element.data('jp4');
var jp4 = new JP4(this,options); var jp4 = new JP4(this,options);
element.data('jp4',jp4); element.data('jp4',jp4);
var res = new Object(); var res = new Object();
res.cnv = element; res.cnv = element;
res.data = jp4; res.data = jp4;
return res; return res;
}; };
}(jQuery)); }(jQuery));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment