Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7f33e403
Kaydet (Commit)
7f33e403
authored
Ara 20, 1996
tarafından
Roger E. Masse
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Renamed.
üst
c3573256
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
406 additions
and
380 deletions
+406
-380
imgfile.c
Modules/imgfile.c
+406
-380
No files found.
Modules/imgfile.c
Dosyayı görüntüle @
7f33e403
...
...
@@ -40,11 +40,9 @@ PERFORMANCE OF THIS SOFTWARE.
** Warning: this module is very non-reentrant (esp. the readscaled stuff)
*/
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include <gl/image.h>
#include <errno.h>
#include "/usr/people/4Dgifts/iristools/include/izoom.h"
...
...
@@ -55,7 +53,7 @@ extern void filterzoom();
extern
void
putrow
();
extern
void
getrow
();
static
o
bject
*
ImgfileError
;
/* Exception we raise for various trouble */
static
PyO
bject
*
ImgfileError
;
/* Exception we raise for various trouble */
static
int
top_to_bottom
;
/* True if we want top-to-bottom images */
...
...
@@ -70,11 +68,11 @@ static int error_called;
static
void
imgfile_error
(
str
)
char
*
str
;
char
*
str
;
{
err_setstr
(
ImgfileError
,
str
);
error_called
=
1
;
return
;
/* To imglib, which will return a failure indicator */
PyErr_SetString
(
ImgfileError
,
str
);
error_called
=
1
;
return
;
/* To imglib, which will return a failure indicator */
}
...
...
@@ -83,124 +81,129 @@ imgfile_error(str)
static
IMAGE
*
imgfile_open
(
fname
)
char
*
fname
;
char
*
fname
;
{
IMAGE
*
image
;
i_seterror
(
imgfile_error
);
error_called
=
0
;
errno
=
0
;
if
(
(
image
=
iopen
(
fname
,
"r"
))
==
NULL
)
{
/* Error may already be set by imgfile_error */
if
(
!
error_called
)
{
if
(
errno
)
err_errno
(
ImgfileError
);
else
err_setstr
(
ImgfileError
,
"Can't open image file"
);
}
return
NULL
;
}
return
image
;
IMAGE
*
image
;
i_seterror
(
imgfile_error
);
error_called
=
0
;
errno
=
0
;
if
(
(
image
=
iopen
(
fname
,
"r"
))
==
NULL
)
{
/* Error may already be set by imgfile_error */
if
(
!
error_called
)
{
if
(
errno
)
PyErr_SetFromErrno
(
ImgfileError
);
else
PyErr_SetString
(
ImgfileError
,
"Can't open image file"
);
}
return
NULL
;
}
return
image
;
}
static
o
bject
*
static
PyO
bject
*
imgfile_ttob
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
newval
;
o
bject
*
rv
;
int
newval
;
PyO
bject
*
rv
;
if
(
!
getargs
(
args
,
"i"
,
&
newval
))
return
NULL
;
rv
=
newintobject
(
top_to_bottom
);
top_to_bottom
=
newval
;
return
rv
;
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
newval
))
return
NULL
;
rv
=
PyInt_FromLong
(
top_to_bottom
);
top_to_bottom
=
newval
;
return
rv
;
}
static
o
bject
*
static
PyO
bject
*
imgfile_read
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
char
*
fname
;
o
bject
*
rv
;
int
xsize
,
ysize
,
zsize
;
char
*
cdatap
;
long
*
idatap
;
static
short
rs
[
8192
],
gs
[
8192
],
bs
[
8192
];
int
x
,
y
;
IMAGE
*
image
;
int
yfirst
,
ylast
,
ystep
;
if
(
!
getargs
(
args
,
"s"
,
&
fname
)
)
return
NULL
;
char
*
fname
;
PyO
bject
*
rv
;
int
xsize
,
ysize
,
zsize
;
char
*
cdatap
;
long
*
idatap
;
static
short
rs
[
8192
],
gs
[
8192
],
bs
[
8192
];
int
x
,
y
;
IMAGE
*
image
;
int
yfirst
,
ylast
,
ystep
;
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
fname
)
)
return
NULL
;
if
(
(
image
=
imgfile_open
(
fname
))
==
NULL
)
return
NULL
;
if
(
(
image
=
imgfile_open
(
fname
))
==
NULL
)
return
NULL
;
if
(
image
->
colormap
!=
CM_NORMAL
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can only handle CM_NORMAL images"
);
return
NULL
;
}
if
(
BPP
(
image
->
type
)
!=
1
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can't handle imgfiles with bpp!=1"
);
return
NULL
;
}
xsize
=
image
->
xsize
;
ysize
=
image
->
ysize
;
zsize
=
image
->
zsize
;
if
(
zsize
!=
1
&&
zsize
!=
3
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can only handle 1 or 3 byte pixels"
);
return
NULL
;
}
if
(
xsize
>
8192
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can't handle image with > 8192 columns"
);
return
NULL
;
}
if
(
zsize
==
3
)
zsize
=
4
;
rv
=
newsizedstringobject
((
char
*
)
NULL
,
xsize
*
ysize
*
zsize
);
if
(
rv
==
NULL
)
{
iclose
(
image
);
return
NULL
;
}
cdatap
=
getstringvalue
(
rv
);
idatap
=
(
long
*
)
cdatap
;
if
(
top_to_bottom
)
{
yfirst
=
ysize
-
1
;
ylast
=
-
1
;
ystep
=
-
1
;
}
else
{
yfirst
=
0
;
ylast
=
ysize
;
ystep
=
1
;
}
for
(
y
=
yfirst
;
y
!=
ylast
&&
!
error_called
;
y
+=
ystep
)
{
if
(
zsize
==
1
)
{
getrow
(
image
,
rs
,
y
,
0
);
for
(
x
=
0
;
x
<
xsize
;
x
++
)
*
cdatap
++
=
rs
[
x
];
if
(
image
->
colormap
!=
CM_NORMAL
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can only handle CM_NORMAL images"
);
return
NULL
;
}
if
(
BPP
(
image
->
type
)
!=
1
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can't handle imgfiles with bpp!=1"
);
return
NULL
;
}
xsize
=
image
->
xsize
;
ysize
=
image
->
ysize
;
zsize
=
image
->
zsize
;
if
(
zsize
!=
1
&&
zsize
!=
3
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can only handle 1 or 3 byte pixels"
);
return
NULL
;
}
if
(
xsize
>
8192
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can't handle image with > 8192 columns"
);
return
NULL
;
}
if
(
zsize
==
3
)
zsize
=
4
;
rv
=
PyString_FromStringAndSize
((
char
*
)
NULL
,
xsize
*
ysize
*
zsize
);
if
(
rv
==
NULL
)
{
iclose
(
image
);
return
NULL
;
}
cdatap
=
PyString_AsString
(
rv
);
idatap
=
(
long
*
)
cdatap
;
if
(
top_to_bottom
)
{
yfirst
=
ysize
-
1
;
ylast
=
-
1
;
ystep
=
-
1
;
}
else
{
getrow
(
image
,
rs
,
y
,
0
);
getrow
(
image
,
gs
,
y
,
1
);
getrow
(
image
,
bs
,
y
,
2
);
for
(
x
=
0
;
x
<
xsize
;
x
++
)
*
idatap
++
=
(
rs
[
x
]
&
0xff
)
|
((
gs
[
x
]
&
0xff
)
<<
8
)
|
((
bs
[
x
]
&
0xff
)
<<
16
);
yfirst
=
0
;
ylast
=
ysize
;
ystep
=
1
;
}
for
(
y
=
yfirst
;
y
!=
ylast
&&
!
error_called
;
y
+=
ystep
)
{
if
(
zsize
==
1
)
{
getrow
(
image
,
rs
,
y
,
0
);
for
(
x
=
0
;
x
<
xsize
;
x
++
)
*
cdatap
++
=
rs
[
x
];
}
else
{
getrow
(
image
,
rs
,
y
,
0
);
getrow
(
image
,
gs
,
y
,
1
);
getrow
(
image
,
bs
,
y
,
2
);
for
(
x
=
0
;
x
<
xsize
;
x
++
)
*
idatap
++
=
(
rs
[
x
]
&
0xff
)
|
((
gs
[
x
]
&
0xff
)
<<
8
)
|
((
bs
[
x
]
&
0xff
)
<<
16
);
}
}
}
iclose
(
image
);
if
(
error_called
)
{
DECREF
(
rv
);
return
NULL
;
}
return
rv
;
iclose
(
image
);
if
(
error_called
)
{
Py_DECREF
(
rv
);
return
NULL
;
}
return
rv
;
}
static
IMAGE
*
glob_image
;
...
...
@@ -209,334 +212,357 @@ static int glob_width, glob_z, glob_ysize;
static
void
xs_get
(
buf
,
y
)
short
*
buf
;
int
y
;
short
*
buf
;
int
y
;
{
if
(
top_to_bottom
)
getrow
(
glob_image
,
buf
,
(
glob_ysize
-
1
-
y
),
glob_z
);
else
getrow
(
glob_image
,
buf
,
y
,
glob_z
);
if
(
top_to_bottom
)
getrow
(
glob_image
,
buf
,
(
glob_ysize
-
1
-
y
),
glob_z
);
else
getrow
(
glob_image
,
buf
,
y
,
glob_z
);
}
static
void
xs_put_c
(
buf
,
y
)
short
*
buf
;
int
y
;
short
*
buf
;
int
y
;
{
char
*
datap
=
(
char
*
)
glob_datap
+
y
*
glob_width
;
int
width
=
glob_width
;
char
*
datap
=
(
char
*
)
glob_datap
+
y
*
glob_width
;
int
width
=
glob_width
;
while
(
width
--
)
*
datap
++
=
(
*
buf
++
)
&
0xff
;
while
(
width
--
)
*
datap
++
=
(
*
buf
++
)
&
0xff
;
}
static
void
xs_put_0
(
buf
,
y
)
short
*
buf
;
int
y
;
short
*
buf
;
int
y
;
{
long
*
datap
=
glob_datap
+
y
*
glob_width
;
int
width
=
glob_width
;
long
*
datap
=
glob_datap
+
y
*
glob_width
;
int
width
=
glob_width
;
while
(
width
--
)
*
datap
++
=
(
*
buf
++
)
&
0xff
;
while
(
width
--
)
*
datap
++
=
(
*
buf
++
)
&
0xff
;
}
static
void
xs_put_12
(
buf
,
y
)
short
*
buf
;
int
y
;
short
*
buf
;
int
y
;
{
long
*
datap
=
glob_datap
+
y
*
glob_width
;
int
width
=
glob_width
;
long
*
datap
=
glob_datap
+
y
*
glob_width
;
int
width
=
glob_width
;
while
(
width
--
)
*
datap
++
|=
((
*
buf
++
)
&
0xff
)
<<
(
glob_z
*
8
);
while
(
width
--
)
*
datap
++
|=
((
*
buf
++
)
&
0xff
)
<<
(
glob_z
*
8
);
}
static
void
xscale
(
image
,
xsize
,
ysize
,
zsize
,
datap
,
xnew
,
ynew
,
fmode
,
blur
)
IMAGE
*
image
;
int
xsize
,
ysize
,
zsize
;
long
*
datap
;
int
xnew
,
ynew
;
int
fmode
;
double
blur
;
IMAGE
*
image
;
int
xsize
,
ysize
,
zsize
;
long
*
datap
;
int
xnew
,
ynew
;
int
fmode
;
double
blur
;
{
glob_image
=
image
;
glob_datap
=
datap
;
glob_width
=
xnew
;
glob_ysize
=
ysize
;
if
(
zsize
==
1
)
{
glob_z
=
0
;
filterzoom
(
xs_get
,
xs_put_c
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
}
else
{
glob_z
=
0
;
filterzoom
(
xs_get
,
xs_put_0
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
glob_z
=
1
;
filterzoom
(
xs_get
,
xs_put_12
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
glob_z
=
2
;
filterzoom
(
xs_get
,
xs_put_12
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
}
glob_image
=
image
;
glob_datap
=
datap
;
glob_width
=
xnew
;
glob_ysize
=
ysize
;
if
(
zsize
==
1
)
{
glob_z
=
0
;
filterzoom
(
xs_get
,
xs_put_c
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
}
else
{
glob_z
=
0
;
filterzoom
(
xs_get
,
xs_put_0
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
glob_z
=
1
;
filterzoom
(
xs_get
,
xs_put_12
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
glob_z
=
2
;
filterzoom
(
xs_get
,
xs_put_12
,
xsize
,
ysize
,
xnew
,
ynew
,
fmode
,
blur
);
}
}
static
o
bject
*
static
PyO
bject
*
imgfile_readscaled
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
char
*
fname
;
object
*
rv
;
int
xsize
,
ysize
,
zsize
;
char
*
cdatap
;
long
*
idatap
;
static
short
rs
[
8192
],
gs
[
8192
],
bs
[
8192
];
int
x
,
y
;
int
xwtd
,
ywtd
,
xorig
,
yorig
;
float
xfac
,
yfac
;
int
cnt
;
IMAGE
*
image
;
char
*
filter
;
double
blur
;
int
extended
;
int
fmode
=
0
;
int
yfirst
,
ylast
,
ystep
;
/*
** Parse args. Funny, since arg 4 and 5 are optional
** (filter name and blur factor). Also, 4 or 5 arguments indicates
** extended scale algorithm in stead of simple-minded pixel drop/dup.
*/
extended
=
0
;
cnt
=
gettuplesize
(
args
);
if
(
cnt
==
5
)
{
extended
=
1
;
if
(
!
getargs
(
args
,
"(siisd)"
,
&
fname
,
&
xwtd
,
&
ywtd
,
&
filter
,
&
blur
)
)
return
NULL
;
}
else
if
(
cnt
==
4
)
{
extended
=
1
;
if
(
!
getargs
(
args
,
"(siis)"
,
&
fname
,
&
xwtd
,
&
ywtd
,
&
filter
)
)
return
NULL
;
blur
=
1
.
0
;
}
else
if
(
!
getargs
(
args
,
"(sii)"
,
&
fname
,
&
xwtd
,
&
ywtd
)
)
return
NULL
;
/*
** Check parameters, open file and check type, rows, etc.
*/
if
(
extended
)
{
if
(
strcmp
(
filter
,
"impulse"
)
==
0
)
fmode
=
IMPULSE
;
else
if
(
strcmp
(
filter
,
"box"
)
==
0
)
fmode
=
BOX
;
else
if
(
strcmp
(
filter
,
"triangle"
)
==
0
)
fmode
=
TRIANGLE
;
else
if
(
strcmp
(
filter
,
"quadratic"
)
==
0
)
fmode
=
QUADRATIC
;
else
if
(
strcmp
(
filter
,
"gaussian"
)
==
0
)
fmode
=
GAUSSIAN
;
else
{
err_setstr
(
ImgfileError
,
"Unknown filter type"
);
return
NULL
;
char
*
fname
;
PyObject
*
rv
;
int
xsize
,
ysize
,
zsize
;
char
*
cdatap
;
long
*
idatap
;
static
short
rs
[
8192
],
gs
[
8192
],
bs
[
8192
];
int
x
,
y
;
int
xwtd
,
ywtd
,
xorig
,
yorig
;
float
xfac
,
yfac
;
int
cnt
;
IMAGE
*
image
;
char
*
filter
;
double
blur
;
int
extended
;
int
fmode
=
0
;
int
yfirst
,
ylast
,
ystep
;
/*
** Parse args. Funny, since arg 4 and 5 are optional
** (filter name and blur factor). Also, 4 or 5 arguments indicates
** extended scale algorithm in stead of simple-minded pixel drop/dup.
*/
extended
=
0
;
cnt
=
PyTuple_Size
(
args
);
if
(
cnt
==
5
)
{
extended
=
1
;
if
(
!
PyArg_Parse
(
args
,
"(siisd)"
,
&
fname
,
&
xwtd
,
&
ywtd
,
&
filter
,
&
blur
)
)
return
NULL
;
}
else
if
(
cnt
==
4
)
{
extended
=
1
;
if
(
!
PyArg_Parse
(
args
,
"(siis)"
,
&
fname
,
&
xwtd
,
&
ywtd
,
&
filter
)
)
return
NULL
;
blur
=
1
.
0
;
}
else
if
(
!
PyArg_Parse
(
args
,
"(sii)"
,
&
fname
,
&
xwtd
,
&
ywtd
)
)
return
NULL
;
/*
** Check parameters, open file and check type, rows, etc.
*/
if
(
extended
)
{
if
(
strcmp
(
filter
,
"impulse"
)
==
0
)
fmode
=
IMPULSE
;
else
if
(
strcmp
(
filter
,
"box"
)
==
0
)
fmode
=
BOX
;
else
if
(
strcmp
(
filter
,
"triangle"
)
==
0
)
fmode
=
TRIANGLE
;
else
if
(
strcmp
(
filter
,
"quadratic"
)
==
0
)
fmode
=
QUADRATIC
;
else
if
(
strcmp
(
filter
,
"gaussian"
)
==
0
)
fmode
=
GAUSSIAN
;
else
{
PyErr_SetString
(
ImgfileError
,
"Unknown filter type"
);
return
NULL
;
}
}
}
if
(
(
image
=
imgfile_open
(
fname
))
==
NULL
)
return
NULL
;
if
(
(
image
=
imgfile_open
(
fname
))
==
NULL
)
return
NULL
;
if
(
image
->
colormap
!=
CM_NORMAL
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can only handle CM_NORMAL images"
);
return
NULL
;
}
if
(
BPP
(
image
->
type
)
!=
1
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can't handle imgfiles with bpp!=1"
);
return
NULL
;
}
xsize
=
image
->
xsize
;
ysize
=
image
->
ysize
;
zsize
=
image
->
zsize
;
if
(
zsize
!=
1
&&
zsize
!=
3
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can only handle 1 or 3 byte pixels"
);
return
NULL
;
}
if
(
xsize
>
8192
)
{
iclose
(
image
);
err_setstr
(
ImgfileError
,
"Can't handle image with > 8192 columns"
);
return
NULL
;
}
if
(
image
->
colormap
!=
CM_NORMAL
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can only handle CM_NORMAL images"
);
return
NULL
;
}
if
(
BPP
(
image
->
type
)
!=
1
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can't handle imgfiles with bpp!=1"
);
return
NULL
;
}
xsize
=
image
->
xsize
;
ysize
=
image
->
ysize
;
zsize
=
image
->
zsize
;
if
(
zsize
!=
1
&&
zsize
!=
3
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can only handle 1 or 3 byte pixels"
);
return
NULL
;
}
if
(
xsize
>
8192
)
{
iclose
(
image
);
PyErr_SetString
(
ImgfileError
,
"Can't handle image with > 8192 columns"
);
return
NULL
;
}
if
(
zsize
==
3
)
zsize
=
4
;
rv
=
newsizedstringobject
(
NULL
,
xwtd
*
ywtd
*
zsize
);
if
(
rv
==
NULL
)
{
iclose
(
image
);
return
NULL
;
}
xfac
=
(
float
)
xsize
/
(
float
)
xwtd
;
yfac
=
(
float
)
ysize
/
(
float
)
ywtd
;
cdatap
=
getstringvalue
(
rv
);
idatap
=
(
long
*
)
cdatap
;
if
(
extended
)
{
xscale
(
image
,
xsize
,
ysize
,
zsize
,
idatap
,
xwtd
,
ywtd
,
fmode
,
blur
);
}
else
{
if
(
top_to_bottom
)
{
yfirst
=
ywtd
-
1
;
ylast
=
-
1
;
ystep
=
-
1
;
}
else
{
yfirst
=
0
;
ylast
=
ywtd
;
ystep
=
1
;
if
(
zsize
==
3
)
zsize
=
4
;
rv
=
PyString_FromStringAndSize
(
NULL
,
xwtd
*
ywtd
*
zsize
);
if
(
rv
==
NULL
)
{
iclose
(
image
);
return
NULL
;
}
for
(
y
=
yfirst
;
y
!=
ylast
&&
!
error_called
;
y
+=
ystep
)
{
yorig
=
(
int
)(
y
*
yfac
);
if
(
zsize
==
1
)
{
getrow
(
image
,
rs
,
yorig
,
0
);
for
(
x
=
0
;
x
<
xwtd
;
x
++
)
{
*
cdatap
++
=
rs
[(
int
)(
x
*
xfac
)];
xfac
=
(
float
)
xsize
/
(
float
)
xwtd
;
yfac
=
(
float
)
ysize
/
(
float
)
ywtd
;
cdatap
=
PyString_AsString
(
rv
);
idatap
=
(
long
*
)
cdatap
;
if
(
extended
)
{
xscale
(
image
,
xsize
,
ysize
,
zsize
,
idatap
,
xwtd
,
ywtd
,
fmode
,
blur
);
}
else
{
if
(
top_to_bottom
)
{
yfirst
=
ywtd
-
1
;
ylast
=
-
1
;
ystep
=
-
1
;
}
else
{
yfirst
=
0
;
ylast
=
ywtd
;
ystep
=
1
;
}
}
else
{
getrow
(
image
,
rs
,
yorig
,
0
);
getrow
(
image
,
gs
,
yorig
,
1
);
getrow
(
image
,
bs
,
yorig
,
2
);
for
(
x
=
0
;
x
<
xwtd
;
x
++
)
{
xorig
=
(
int
)(
x
*
xfac
);
*
idatap
++
=
(
rs
[
xorig
]
&
0xff
)
|
((
gs
[
xorig
]
&
0xff
)
<<
8
)
|
((
bs
[
xorig
]
&
0xff
)
<<
16
);
for
(
y
=
yfirst
;
y
!=
ylast
&&
!
error_called
;
y
+=
ystep
)
{
yorig
=
(
int
)(
y
*
yfac
);
if
(
zsize
==
1
)
{
getrow
(
image
,
rs
,
yorig
,
0
);
for
(
x
=
0
;
x
<
xwtd
;
x
++
)
{
*
cdatap
++
=
rs
[(
int
)(
x
*
xfac
)];
}
}
else
{
getrow
(
image
,
rs
,
yorig
,
0
);
getrow
(
image
,
gs
,
yorig
,
1
);
getrow
(
image
,
bs
,
yorig
,
2
);
for
(
x
=
0
;
x
<
xwtd
;
x
++
)
{
xorig
=
(
int
)(
x
*
xfac
);
*
idatap
++
=
(
rs
[
xorig
]
&
0xff
)
|
((
gs
[
xorig
]
&
0xff
)
<<
8
)
|
((
bs
[
xorig
]
&
0xff
)
<<
16
);
}
}
}
}
}
}
iclose
(
image
);
if
(
error_called
)
{
DECREF
(
rv
);
return
NULL
;
}
return
rv
;
iclose
(
image
);
if
(
error_called
)
{
Py_DECREF
(
rv
);
return
NULL
;
}
return
rv
;
}
static
o
bject
*
static
PyO
bject
*
imgfile_getsizes
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
char
*
fname
;
o
bject
*
rv
;
IMAGE
*
image
;
char
*
fname
;
PyO
bject
*
rv
;
IMAGE
*
image
;
if
(
!
getargs
(
args
,
"s"
,
&
fname
)
)
return
NULL
;
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
fname
)
)
return
NULL
;
if
(
(
image
=
imgfile_open
(
fname
))
==
NULL
)
return
NULL
;
rv
=
mkv
alue
(
"(iii)"
,
image
->
xsize
,
image
->
ysize
,
image
->
zsize
);
iclose
(
image
);
return
rv
;
if
(
(
image
=
imgfile_open
(
fname
))
==
NULL
)
return
NULL
;
rv
=
Py_BuildV
alue
(
"(iii)"
,
image
->
xsize
,
image
->
ysize
,
image
->
zsize
);
iclose
(
image
);
return
rv
;
}
static
o
bject
*
static
PyO
bject
*
imgfile_write
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
IMAGE
*
image
;
char
*
fname
;
int
xsize
,
ysize
,
zsize
,
len
;
char
*
cdatap
;
long
*
idatap
;
short
rs
[
8192
],
gs
[
8192
],
bs
[
8192
];
short
r
,
g
,
b
;
long
rgb
;
int
x
,
y
;
int
yfirst
,
ylast
,
ystep
;
if
(
!
getargs
(
args
,
"(ss#iii)"
,
&
fname
,
&
cdatap
,
&
len
,
&
xsize
,
&
ysize
,
&
zsize
)
)
return
NULL
;
IMAGE
*
image
;
char
*
fname
;
int
xsize
,
ysize
,
zsize
,
len
;
char
*
cdatap
;
long
*
idatap
;
short
rs
[
8192
],
gs
[
8192
],
bs
[
8192
];
short
r
,
g
,
b
;
long
rgb
;
int
x
,
y
;
int
yfirst
,
ylast
,
ystep
;
if
(
!
PyArg_Parse
(
args
,
"(ss#iii)"
,
&
fname
,
&
cdatap
,
&
len
,
&
xsize
,
&
ysize
,
&
zsize
)
)
return
NULL
;
if
(
zsize
!=
1
&&
zsize
!=
3
)
{
err_setstr
(
ImgfileError
,
"Can only handle 1 or 3 byte pixels"
);
return
NULL
;
}
if
(
len
!=
xsize
*
ysize
*
(
zsize
==
1
?
1
:
4
)
)
{
err_setstr
(
ImgfileError
,
"Data does not match sizes"
);
return
NULL
;
}
if
(
xsize
>
8192
)
{
err_setstr
(
ImgfileError
,
"Can't handle image with > 8192 columns"
);
return
NULL
;
}
error_called
=
0
;
errno
=
0
;
image
=
iopen
(
fname
,
"w"
,
RLE
(
1
),
3
,
xsize
,
ysize
,
zsize
);
if
(
image
==
0
)
{
if
(
!
error_called
)
{
if
(
errno
)
err_errno
(
ImgfileError
);
else
err_setstr
(
ImgfileError
,
"Can't create image file"
);
if
(
zsize
!=
1
&&
zsize
!=
3
)
{
PyErr_SetString
(
ImgfileError
,
"Can only handle 1 or 3 byte pixels"
);
return
NULL
;
}
if
(
len
!=
xsize
*
ysize
*
(
zsize
==
1
?
1
:
4
)
)
{
PyErr_SetString
(
ImgfileError
,
"Data does not match sizes"
);
return
NULL
;
}
if
(
xsize
>
8192
)
{
PyErr_SetString
(
ImgfileError
,
"Can't handle image with > 8192 columns"
);
return
NULL
;
}
error_called
=
0
;
errno
=
0
;
image
=
iopen
(
fname
,
"w"
,
RLE
(
1
),
3
,
xsize
,
ysize
,
zsize
);
if
(
image
==
0
)
{
if
(
!
error_called
)
{
if
(
errno
)
PyErr_SetFromErrno
(
ImgfileError
);
else
PyErr_SetString
(
ImgfileError
,
"Can't create image file"
);
}
return
NULL
;
}
return
NULL
;
}
idatap
=
(
long
*
)
cdatap
;
idatap
=
(
long
*
)
cdatap
;
if
(
top_to_bottom
)
{
yfirst
=
ysize
-
1
;
ylast
=
-
1
;
ystep
=
-
1
;
}
else
{
yfirst
=
0
;
ylast
=
ysize
;
ystep
=
1
;
}
for
(
y
=
yfirst
;
y
!=
ylast
&&
!
error_called
;
y
+=
ystep
)
{
if
(
zsize
==
1
)
{
for
(
x
=
0
;
x
<
xsize
;
x
++
)
rs
[
x
]
=
*
cdatap
++
;
putrow
(
image
,
rs
,
y
,
0
);
if
(
top_to_bottom
)
{
yfirst
=
ysize
-
1
;
ylast
=
-
1
;
ystep
=
-
1
;
}
else
{
for
(
x
=
0
;
x
<
xsize
;
x
++
)
{
rgb
=
*
idatap
++
;
r
=
rgb
&
0xff
;
g
=
(
rgb
>>
8
)
&
0xff
;
b
=
(
rgb
>>
16
)
&
0xff
;
rs
[
x
]
=
r
;
gs
[
x
]
=
g
;
bs
[
x
]
=
b
;
}
putrow
(
image
,
rs
,
y
,
0
);
putrow
(
image
,
gs
,
y
,
1
);
putrow
(
image
,
bs
,
y
,
2
);
yfirst
=
0
;
ylast
=
ysize
;
ystep
=
1
;
}
}
iclose
(
image
);
if
(
error_called
)
return
NULL
;
INCREF
(
None
);
return
None
;
for
(
y
=
yfirst
;
y
!=
ylast
&&
!
error_called
;
y
+=
ystep
)
{
if
(
zsize
==
1
)
{
for
(
x
=
0
;
x
<
xsize
;
x
++
)
rs
[
x
]
=
*
cdatap
++
;
putrow
(
image
,
rs
,
y
,
0
);
}
else
{
for
(
x
=
0
;
x
<
xsize
;
x
++
)
{
rgb
=
*
idatap
++
;
r
=
rgb
&
0xff
;
g
=
(
rgb
>>
8
)
&
0xff
;
b
=
(
rgb
>>
16
)
&
0xff
;
rs
[
x
]
=
r
;
gs
[
x
]
=
g
;
bs
[
x
]
=
b
;
}
putrow
(
image
,
rs
,
y
,
0
);
putrow
(
image
,
gs
,
y
,
1
);
putrow
(
image
,
bs
,
y
,
2
);
}
}
iclose
(
image
);
if
(
error_called
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
struct
methodlist
imgfile_methods
[]
=
{
{
"getsizes"
,
imgfile_getsizes
},
{
"read"
,
imgfile_read
},
{
"readscaled"
,
imgfile_readscaled
,
1
},
{
"write"
,
imgfile_write
},
{
"ttob"
,
imgfile_ttob
},
{
NULL
,
NULL
}
/* Sentinel */
static
PyMethodDef
imgfile_methods
[]
=
{
{
"getsizes"
,
imgfile_getsizes
},
{
"read"
,
imgfile_read
},
{
"readscaled"
,
imgfile_readscaled
,
1
},
{
"write"
,
imgfile_write
},
{
"ttob"
,
imgfile_ttob
},
{
NULL
,
NULL
}
/* Sentinel */
};
void
initimgfile
()
{
object
*
m
,
*
d
;
m
=
initmodule
(
"imgfile"
,
imgfile_methods
);
d
=
getmoduledict
(
m
);
ImgfileError
=
newstringobject
(
"imgfile.error"
);
if
(
ImgfileError
==
NULL
||
dictinsert
(
d
,
"error"
,
ImgfileError
)
)
fatal
(
"can't define imgfile.error"
);
PyObject
*
m
,
*
d
;
m
=
Py_InitModule
(
"imgfile"
,
imgfile_methods
);
d
=
PyModule_GetDict
(
m
);
ImgfileError
=
PyString_FromString
(
"imgfile.error"
);
if
(
ImgfileError
==
NULL
||
PyDict_SetItemString
(
d
,
"error"
,
ImgfileError
)
)
Py_FatalError
(
"can't define imgfile.error"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment