// This script is for Directory Opus 11.5.4 or higher // CoverArtDim column (CoverArt WxH) // Extracts the dimensions directly from blob or file. // Shows dimensions for a folder if it contains defined files. var vAllowedFolderImages=null; function MakeLong(lo,hi){ return (lo|(hi<<16)); } function MakeWord(lo,hi){ return (((lo<<16)>>16)|((hi<<16)>>8)); } function GetByte2(Value,ByteToGet){ return (Value & (0xFF<<(ByteToGet*8)))>>>(ByteToGet*8); } function SwapHiLo(w){ return MakeWord(GetByte2(w,1),GetByte2(w,0)); } // Simplifies using a Blob by making it behave more like a file. var soBeginning=0; var soCurrent=1; var soEnd=2; function BlobStream(blob){ this.blob=blob; this.position=0; this.size=0; if (this.blob){ this.size=this.blob.size; } } BlobStream.prototype.Seek=function(offset,mode){ switch(mode){ case soBeginning: { this.position=offset; return this.position; } case soCurrent: { this.position=this.position+offset; return this.position; } case soEnd:{ this.position=blob.size-offset; return this.position; } default: return -1; } }; BlobStream.prototype.ReadByte=function(){ return this.blob(this.position++); }; BlobStream.prototype.ReadWord=function(){ return MakeWord(this.ReadByte(),this.ReadByte()); }; BlobStream.prototype.ReadLong=function(){ return MakeLong(MakeWord(this.ReadByte(),this.ReadByte()),MakeWord(this.ReadByte(),this.ReadByte())); }; BlobStream.prototype.ReadBytes=function(numbytes){ var retval=[]; for (var i=0;i0){ var x = 3 * (1 << ((GIFHeader.Flags & 7) + 1)); stream.Seek(x,soBeginning); } bFound=false; while(stream.position0)){ var cnt=itm.Metadata.audio.coverart; if(cnt>1){ var enm=[]; var pos=0; var selwidth=0; var selheight=0; var enu = new Enumerator(itm.Metadata.audio.coverart); if (!enu.atEnd()){ while (!enu.atEnd()){ var curitm=enu.item(); stream=new BlobStream(curitm.data); enm[pos++]=ImageSizeStream(stream); enu.moveNext(); } } for (var i=0;i(selheight*selwidth))){ selwidth=enm[i].width; selheight=enm[i].height; } } return {width:selwidth,height:selheight,all:enm}; } else { var ca=itm.Metadata.audio.coverart(0); stream=new BlobStream(ca.data); return ImageSizeStream(stream); } } else{ var blob; if ((".gif;.jpg;.png;.bmp".indexOf(itm.ext.toLowerCase())>=0)){ var file=DOpus.FSUtil.OpenFile(itm.realpath); if (file){ //Contrary to the documentation, Read don't seem to work unless you specify a size. //iow, blob=file.Read() does nothing. blob=file.Read(file.size); if (blob){ stream=new BlobStream(blob); return ImageSizeStream(stream); } } } } } return null; } // Called by Directory Opus to initialize the script function OnInit(initData){ initData.name = "ColCoverArtDimensions"; initData.desc = "Add a column to show the dimensions of coverart or image"; initData.copyright = "myarmor"; initData.min_version="11"; initData.version = "1.03"; initData.default_enable = false; var col; col = initData.AddColumn(); col.name = "CoverArtDim"; col.method = "OnCoverArtDim"; col.label = "CoverArt WxH"; col.autogroup = true; col.autorefresh=true; col.justify = "right"; initData.config.allowedFolderImages=DOpus.NewVector('cover.jpg','folder.jpg'); return false; } function AllowItem(item){ if (!vAllowedFolderImages) return false; var len; len=vAllowedFolderImages.count; if (len==0) return false; for (var i=0;i