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
171a55bf
Commit
171a55bf
authored
Feb 19, 1993
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Will now generate converters that go thru intermedeate formats
parent
4fada9c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
3 deletions
+81
-3
Demo/sgi/video/imgconv.py
Demo/sgi/video/imgconv.py
+81
-3
No files found.
Demo/sgi/video/imgconv.py
View file @
171a55bf
...
...
@@ -18,8 +18,14 @@ converters = [ \
(
'mono'
,
'grey'
,
mono2grey
,
NOT_LOSSY
),
\
(
'grey2'
,
'grey'
,
imageop
.
grey22grey
,
NOT_LOSSY
),
\
(
'grey4'
,
'grey'
,
imageop
.
grey42grey
,
NOT_LOSSY
),
\
(
'rgb'
,
'rgb8'
,
imageop
.
rgb2rgb8
,
LOSSY
),
\
(
'rgb8'
,
'rgb'
,
imageop
.
rgb82rgb
,
NOT_LOSSY
),
\
(
'rgb'
,
'grey'
,
imageop
.
rgb2grey
,
LOSSY
),
\
(
'grey'
,
'rgb'
,
imageop
.
grey2rgb
,
NOT_LOSSY
)
\
]
built
=
{}
def
addconverter
(
fcs
,
tcs
,
lossy
,
func
):
for
i
in
range
(
len
(
converters
)):
ifcs
,
itcs
,
irtn
,
ilossy
=
converters
[
i
]
...
...
@@ -29,10 +35,82 @@ def addconverter(fcs, tcs, lossy, func):
converters
.
append
((
fcs
,
tcs
,
lossy
,
func
))
def
getconverter
(
fcs
,
tcs
):
#
# If formats are the same return the dummy converter
#
if
fcs
==
tcs
:
return
null
#
# Otherwise, if we have a converter return that one
#
for
ifcs
,
itcs
,
irtn
,
ilossy
in
converters
:
if
(
fcs
,
tcs
)
==
(
ifcs
,
itcs
):
return
irtn
raise
error
,
'Sorry, that conversion is not implemented'
#
# Finally, we try to create a converter
#
if
not
built
.
has_key
(
fcs
):
built
[
fcs
]
=
enumerate_converters
(
fcs
)
if
not
built
[
fcs
].
has_key
(
tcs
):
raise
error
,
'Sorry, conversion from '
+
fcs
+
' to '
+
tcs
+
\
' is not implemented'
if
len
(
built
[
fcs
][
tcs
])
==
3
:
#
# Converter not instantiated yet
#
built
[
fcs
][
tcs
].
append
(
instantiate_converter
(
built
[
fcs
][
tcs
]))
cf
=
built
[
fcs
][
tcs
][
3
]
return
cf
def
enumerate_converters
(
fcs
):
cvs
=
{}
formats
=
[
fcs
]
steps
=
0
while
1
:
workdone
=
0
for
ifcs
,
itcs
,
irtn
,
ilossy
in
converters
:
if
ifcs
==
fcs
:
template
=
[
ilossy
,
1
,
[
irtn
]]
elif
cvs
.
has_key
(
ifcs
):
template
=
cvs
[
ifcs
][:]
template
[
2
]
=
template
[
2
][:]
if
ilossy
:
template
[
0
]
=
ilossy
template
[
1
]
=
template
[
1
]
+
1
template
[
2
].
append
(
irtn
)
else
:
continue
if
not
cvs
.
has_key
(
itcs
):
cvs
[
itcs
]
=
template
workdone
=
1
else
:
previous
=
cvs
[
itcs
]
if
template
<
previous
:
cvs
[
itcs
]
=
template
workdone
=
1
if
not
workdone
:
break
steps
=
steps
+
1
if
steps
>
len
(
converters
):
print
'------------------loop in emunerate_converters--------'
print
'CONVERTERS:'
print
converters
print
'RESULTS:'
print
cvs
raise
error
,
'Internal error - loop'
return
cvs
def
instantiate_converter
(
args
):
list
=
args
[
2
]
cl
=
RtConverters
().
init
(
list
)
args
.
append
(
cl
.
convert
)
return
args
class
RtConverters
():
def
init
(
self
,
list
):
self
.
list
=
list
return
self
def
convert
(
self
,
img
,
w
,
h
):
for
cv
in
self
.
list
:
img
=
cv
(
img
,
w
,
h
)
return
img
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