Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
00fcfe34
Commit
00fcfe34
authored
Jun 03, 1992
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added readscaled() function.
parent
053fb78e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
11 deletions
+86
-11
Modules/imgfile.c
Modules/imgfile.c
+86
-11
No files found.
Modules/imgfile.c
View file @
00fcfe34
...
...
@@ -24,7 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* IMGFILE module - Interface to sgi libimg */
/*
X
XXX This modele should be done better at some point. It should return
/*
XXX This modele should be done better at some point. It should return
** an object of image file class, and have routines to manipulate these
** image files in a neater way (so you can get rgb images off a greyscale
** file, for instance, or do a straight display without having to get the
...
...
@@ -54,13 +54,9 @@ static imgfile_error(str)
}
static
imgfile_open
(
args
)
object
*
args
;
{
imgfile_open
(
fname
)
char
*
fname
;
if
(
!
getargs
(
args
,
"s"
,
&
fname
)
)
return
0
;
{
i_seterror
(
imgfile_error
);
error_called
=
0
;
if
(
image
!=
NULL
&&
strcmp
(
fname
,
gfname
)
!=
0
)
{
...
...
@@ -91,7 +87,10 @@ imgfile_read(self, args)
static
short
rs
[
8192
],
gs
[
8192
],
bs
[
8192
];
int
x
,
y
;
if
(
!
imgfile_open
(
args
)
)
if
(
!
getargs
(
args
,
"s"
,
&
fname
)
)
return
0
;
if
(
!
imgfile_open
(
fname
)
)
return
NULL
;
if
(
image
->
colormap
!=
CM_NORMAL
)
{
...
...
@@ -138,6 +137,78 @@ imgfile_read(self, args)
return
rv
;
}
static
object
*
imgfile_readscaled
(
self
,
args
)
object
*
self
;
object
*
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
;
if
(
!
getargs
(
args
,
"(sii)"
,
&
fname
,
&
xwtd
,
&
ywtd
)
)
return
0
;
if
(
!
imgfile_open
(
fname
)
)
return
NULL
;
if
(
image
->
colormap
!=
CM_NORMAL
)
{
err_setstr
(
ImgfileError
,
"Can only handle CM_NORMAL images"
);
return
NULL
;
}
if
(
BPP
(
image
->
type
)
!=
1
)
{
err_setstr
(
ImgfileError
,
"Cannot handle imgfiles with bpp!=1"
);
return
NULL
;
}
xsize
=
image
->
xsize
;
ysize
=
image
->
ysize
;
zsize
=
image
->
zsize
;
if
(
zsize
!=
1
&&
zsize
!=
3
)
{
err_setstr
(
ImgfileError
,
"Can only handle 1 or 3 byte pixels"
);
return
NULL
;
}
if
(
zsize
==
3
)
zsize
=
4
;
rv
=
newsizedstringobject
(
NULL
,
xwtd
*
ywtd
*
zsize
);
xfac
=
(
float
)
xsize
/
(
float
)
xwtd
;
yfac
=
(
float
)
ysize
/
(
float
)
ywtd
;
if
(
rv
==
NULL
)
return
NULL
;
cdatap
=
getstringvalue
(
rv
);
idatap
=
(
long
*
)
cdatap
;
for
(
y
=
0
;
y
<
ywtd
&&
!
error_called
;
y
++
)
{
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
);
}
}
}
if
(
error_called
)
{
DECREF
(
rv
);
return
NULL
;
}
return
rv
;
}
static
object
*
imgfile_getsizes
(
self
,
args
)
object
*
self
;
...
...
@@ -146,7 +217,10 @@ imgfile_getsizes(self, args)
char
*
fname
;
object
*
rv
;
if
(
!
imgfile_open
(
args
)
)
if
(
!
getargs
(
args
,
"s"
,
&
fname
)
)
return
0
;
if
(
!
imgfile_open
(
fname
)
)
return
NULL
;
rv
=
newtupleobject
(
3
);
if
(
rv
==
NULL
)
...
...
@@ -159,8 +233,9 @@ imgfile_getsizes(self, args)
static
struct
methodlist
imgfile_methods
[]
=
{
{
"getsizes"
,
imgfile_getsizes
},
{
"read"
,
imgfile_read
},
{
"getsizes"
,
imgfile_getsizes
},
{
"read"
,
imgfile_read
},
{
"readscaled"
,
imgfile_readscaled
},
{
0
,
0
}
};
...
...
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