forked from Paul-Riggott/PS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quick JPEGS.jsx
51 lines (50 loc) · 1.61 KB
/
Quick JPEGS.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#target bridge
//start of file FFD8 step 1
//var startJpg=tempFile1.search(/\xFF\xD8\xFF/);
// start of stream DAFF step 2
//var stream =tempFile1.search(/\xDA\xFF/);
//end of file FFD9 step 3
//var endJpg = tempFile1.search(/\xFF\xD9/);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if( BridgeTalk.appName == "bridge" ) {
quickJPGS = MenuElement.create("command", "Create Quick JPGS", "at the end of Thumbnail");
}
quickJPGS.onSelect = function () {
mainQuickJPGS();
}
function mainQuickJPGS(){
var items = app.document.selections;
for (var a =0; a<items.length;a++){
if(items[a].type == "file" && items[a].name.match((/\.(crw|cr2|tiff|raw|rw2|dng|nef|orf|erf|mos|dcr|raf|srf|pef|pcx|x3f)$/i))){
var JPEG = new File(items[a].path.substr(0,items[a].path.lastIndexOf ('.'))+"-quick.jpg");
//var tempFile = new File(items[a]);
tempFile=new File(items[a].path);
var fileString='';
tempFile.open('r');
tempFile.encoding = 'BINARY';
fileString=tempFile.read();
tempFile.close();
for(var w =0;w<6;w++){
var startJpg=fileString.search(/\xFF\xD8\xFF/);
if(startJpg != -1){
if(testJPG()){
var endJpg = fileString.search(/\xFF\xD9/);
fileString = fileString.substr(0,endJpg+2);
JPEG.open('w');
JPEG.encoding = 'BINARY';
JPEG.write(fileString);
JPEG.close();
break;
}else{
fileString = fileString.substr(20);
continue;
}}}}
function testJPG(){
var result=false;
fileString = fileString.substr(startJpg);
var endTest = fileString.search(/\xFF\xD9/);
if(endTest > 204800 ? result= true : result= false);
return result;
}
}
}