/usr/share/octave/site/m/octave-epstk/ebitmap.m is in octave-epstk 2.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | %%NAME
%% ebitmap - transform the current eps-file to bitmap-file
%%
%%SYNOPSIS
%% mapFileName=ebitmap([bitmapType[,resolution[,mapFileName[,epsFileName]]]])
%%
%%PARAMETER(S)
%% bitmapType type of bitmap
%% 0 = PNG-format
%% 1 = JPEG-format
%% 2 = TIFF-format
%% 3 = PPM-format
%% 4 = PCX-format
%% 5 = PDF-format
%% default: 0
%%
%% resolution in dpi,resolution of bitmap-file
%% if scalar then resolution x and y direction are equal
%% default: 200 (dpi)
%% if a [x y] vector then resolution of x and y direction
%% if a [x y q] vector then resolution and qualitiy of JPEG
%% q=100 for no lost of qualitiy
%% q=75 standard compression
%%
%% mapFileName name of bitmap-file
%% default: 'eFileName.typeSuffix'
%% epsFileName name of eps-file
%% default: 'eFileName'
%%
%%GLOBAL PARAMETER(S)
%% eFileName
%% eGhostscript
% written by stefan.mueller@fhr.fraunhofer.de (C) 2010
function mapFileName=ebitmap(bitmapType,resolution,mapFileName,epsFileName)
if nargin>4
eusage('mapFileName=ebitmap([bitmapType[,resolution[,mapFileName[,epsFileName]]]])');
end
eglobpar;
if exist('eFac')
if isempty(eFac)
einit;
end
else
einit;
end
if nargin<1
bitmapType=0;
end
if nargout>0
message=0;
else
message=1;
end
if bitmapType<0
error
end
if bitmapType==0
outputFormat='png16m';
suffix='png';
elseif bitmapType==1
outputFormat='jpeg';
suffix='jpg';
elseif bitmapType==2
outputFormat='tiff24nc';
suffix='tif';
elseif bitmapType==3
outputFormat='ppmraw';
suffix='ppm';
elseif bitmapType==4
outputFormat='pcx24b';
suffix='pcx';
elseif bitmapType==5
outputFormat='pdfwrite';
suffix='pdf';
end
if nargin<2
resolution=200;
end
if nargin<3
pos=findstr(eFileName,'.eps');
if isempty(pos)
mapFileName=[eFileName '.' suffix];
else
mapFileName=[eFileName(1:pos(1)) suffix];
end
end
if nargin<4
epsFileName=eFileName;
end
tmpFileName=[eFileName '.tmp'];
headsize=500;
epsFile=fopen(epsFileName,'rb');
data=fread(epsFile,headsize,'uchar');
fclose(epsFile);
head=char(data');
pos=findstr(head,'epsTk');
if isempty(pos)
pos=findstr(head,'BoundingBox:')+12;
win=sscanf(head(pos(1):pos(1)+40),'%f',4);
win=win/eFac;
xPos=win(1);
yPos=win(2);
width=win(3)-win(1);
height=win(4)-win(2);
esavpar2
eopen(tmpFileName,0,width,height,[0 0]);
einseps(0,0,epsFileName);
eclose(1,0);
erespar2
epsFileName=tmpFileName;
end
epsFile=fopen(epsFileName,'rb');
[data n]=fread(epsFile,inf,'uchar');
fclose(epsFile);
headsize=500;
head=char(data(1:headsize)');
pos=findstr(head,'BoundingBox:')+12;
win=sscanf(head(pos(1):pos(1)+40),'%f',4);
pos=findstr(head,'translate')+9;
tmpFile=fopen(tmpFileName,'wb');
fwrite(tmpFile,data(1:pos(1)),'uchar');
fprintf(tmpFile,'%d %d translate\n',-win(1),-win(2));
fwrite(tmpFile,data(pos(1)+1:n),'uchar');
fclose(tmpFile);
if size(resolution,2)>2
quality=round(resolution(1,3));
else
quality=75;
end
options=sprintf('-q -dNOPAUSE -dSAFER -dBATCH -dJPEGQ=%d',quality);
xResolution=resolution(1,1);
yResolution=resolution(1,1);
if size(resolution,2)>1
yResolution=resolution(1,2);
else
yResolution=resolution(1,1);
end
xPixel=round((win(3)-win(1))/72*xResolution);
yPixel=round((win(4)-win(2))/72*yResolution);
pixelSize=sprintf('-g%dx%d',fix(xPixel),fix(yPixel));
resDpi=sprintf('-r%d',resolution);
device=sprintf('-sDEVICE=%s',outputFormat);
outFileName=sprintf('-sOutputFile=%s',mapFileName);
ghostscript=sprintf('%s %s %s %s %s %s %s',...
eGhostscript,options,pixelSize,resDpi,device,...
outFileName,tmpFileName);
if isempty(eGhostscript)
disp('ebitmap: sorry, no ghostscript installed');
else
if exist('matlabpath')~=5
system(ghostscript);
else
unix(ghostscript);
end
if message
message=sprintf('%s is written',mapFileName);
disp(message);
end
end
delete(tmpFileName);
|