代写program、代做Python语言编程
Version 1.00
Assignment – PNG Images
Version 1.00
1. Submission Guidelines
Deadline: 9:00 AM on Friday 13 December
Submission procedure: Submit only one file labelled png.py through blackboard (via TurnItIn)
Version requirement: Your code must run using Python 3.11.4 on a PC
Allowable import modules: math and zlib only. No other modules may be imported.
2. Overview
The Portable Network Graphics (PNG) format is a format for storing images. For this assignment, you are
tasked with writing code that can be used to open a PNG file, store its contents in the program, and save
modified PNG image files.
This is a real-world assignment, meaning that you are working on a practical problem that requires that you find
additional information to complete the task. The official PNG documentation is available online.
https://www.w3.org/TR/png/
We expect that all students will use the internet and textbook resources to learn concepts needed for this
assignment. There will be many concepts, in-built functions, and other aspects of Python coding, which have not
been directly taught in labs or lectures. It is up to you to fill in these gaps in knowledge by engaging in both the
course and self-learning.
Keep track of the version number of this assignment and ensure that your code meets the latest
specifications by the deadline. This assignment challenge is very similar to a real-world situation where
specifications evolve with the person writing code for the specifications. We will be updating the assignment
descriptor throughout the week to add clarity, remove ambiguities, and fix descriptor errors. Post on the Ed
Discussion board any clarification requests, ambiguities, or descriptor errors. The Teaching Assistants will then
raise this with the instructor who will then update the version of the assignment and announce it via email.
3. PNG Format
You must adhere to the PNG version specified in the hyperlink above. However, you will only need to
implement only a small subset of the total PNG specifications.
Implement only the following chunks:
• IHDR
• IDAT
• IEND
• Other chunks. There may be other chunks present in the PNG image file. For this assignment, you do
not need to implement those other chunks. However, your programme should run smoothly even if
they are present. In other words, ignore the other chunks if they are present in the image.
You will only need to read and write images that have the following image header (IHDR) specifications:
• A bit depth of 8
• A colour type of 2
• A compression method of 0
• A filter method of 0
• An interlace method of 0
When you read the example image (brainbow.png), you should be able to find these values within the file.
We have uploaded brainbow.png as a sample image for you to open and use. Your code should be able to
handle other PNG files, including images with different widths and heights. We may also test very large images.
We will certainly test other .png files to ensure that your code is not hard coded to produce the sample outputs. Version 1.00
4. Class PNG
Create a class named PNG that will allow users to interact with PNG files.
4.1. Attributes
Objects of type PNG should have the following variable attributes:
data A value of type bytes.
This represents the data bytes from the png file. The default values should be b''
info A value of type str.
This represents information about the png file. The default value should be '' and should
become either the name of the file or 'file not found'.
width A value of type int.
This represents the width of the image in pixels. The default value should be 0.
height A value of type int.
This represents the height of the image in pixels. The default value should be 0.
bit_depth A value of type int.
This represents the bit depth of the image data stored in the png file. The default value
should be 0.
color_type A value of type int.
This represents the color type of the image data stored in the png file. The default value
should be 0.
compress A value of type int.
This represents the compression method of the png file. The default value should be 0.
filter A value of type int.
This represents the filter method of the png file. The default value should be 0.
interlace A value of type int.
This represents the interlacing method of the png file. The default value should be 0.
img A value of type list.
This represents a 3-dimensional array where the 1st
dimension is the image rows, the 2nd
dimension is the image columns, and the 3rd dimension is the red, green, or blue values.
The red, green, and blue values should be of type int and should range between 0 and 255
only.
The default value should be an empty list.

Version 1.00
4.2. Methods
For this assignment, you may assume that all arguments put into each method are of the correct type.

__init__(self)
Return values: None
Arguments: A reference to itself, self.
Implementation: This method should initialise all of the above member attributes to their default values.
10 marks for implementation

load_file(self, file_name)
Return values: None
Arguments: A reference to itself (self) and a file name (file_name) of type str.
Implementation: The load_file() method should open the file specified by file_name and store all
of the file’s data into the member attribute data.
If the file is found, then assign file_name into the info member attribute.
If the file is not found and a FileNotFoundError exception is raised when trying to
open the file, then assign 'file not found' into the info member attribute.
10 marks for implementation

valid_png(self)
Return values: True or False
Arguments: A reference to itself, self.
Implementation: Reads the PNG signature and returns whether the correct values were found or not.
Returns True if the PNG signature was correctly specified in the file. Returns False if the
PNG signature was not correctly specified in the file.
10 marks for implementation

read_header(self)
Return values: None
Arguments: A reference to itself, self.
Implementation: Reads the image header chunk (IHDR) and updates the relevant member attributes.
Update the width, height, bit_depth, color_type, compress, filter, and
interlace attributes according to the information stored in the image header chunk.
10 marks for implementation

read_chunks(self)
Return values: None
Arguments: A reference to itself, self.
Implementation: Reads through all the chunks and updates the img attribute.
Read through the remaining chunks following the PNG signature and IHDR chunk. This
includes IDAT and IEND chunk types that include the image data. There may be other Version 1.00
chunk types present in the PNG file, but gracefully ignore those chunk types. Your program
should still run smoothly even if those chunk types are present in the PNG file.
One of the challenges of this method is being able to extract the image data from the IDAT
chunk(s). After extracting the image, store it in the member attribute img. img represents a
3-dimensional array where the 1st
dimension is the image rows, the 2nd dimension is the
image columns, and the 3rd dimension is the red, green, or blue values. The red, green, and
blue values should be of type int and should range between 0 and 255 only.
20 marks for implementation
10 marks for efficiency

save_rgb(self, file_name, rgb_option)
Return values: None
Arguments: A reference to itself, self, a file name (file_name) of type str, and a saving option
(rgb_option) of type int.
Implementation: Saves the red, green, or blue channels of the img attribute into a PNG file named
file_name as determined by the setting of rgb_option.
When rgb_option is set to 1, store the red channel of the image into the PNG file.
When rgb_option is set to 2, store the green channel of the image into the PNG file.
When rgb_option is set to 3, store the blue channel of the image into the PNG file.
We should be able to open your PNG file using a regular image viewing application.
10 marks for implementation
10 marks for efficiency

5. Coding style and commenting
Ensure that your code is readable and well commented. We will be marking according to spacing, naming,
comments, length, and general readability.
10 marks for coding style and commenting
6. Coding rules
Only the PNG class definition and imports to the math and zlib modules should be in the global space of
png.py. There should be no other global variables or definitions. You are free to define methods within the
PNG class, which we will not call. A main() function could be used if you so desire, but it is not required.
Only the math and zlib modules are allowed for this assignment. No other module is allowed.
7. Marking criteria
We will mark your submitted png.py code according to the following categories:
• 70 marks: Implementation and evidence of coding knowledge
• 20 marks: Coding efficiency
• 10 marks: Coding style and commenting
We will import your png module near the top of our script to test your code. We will run several test conditions
against each of your classes, including its attributes and methods. After running each method, we will investigate
what was assigned in your attribute variables. So, the type, length, etc. of your attribute variables must perfectly
match how we defined them in this specification. We will test far more test cases than the single example we
have included in this assignment sheet. V
e
r
s
i
o
n

1
.
0
0

8
.

S
a
m
p
l
e

C
o
d
e

T
h
e

fo
l
l
o
wi
n
g
c
o
d
e


i
m
p
o
r
t

p
n
g

d
e
f

m
a
i
n
(
)
:


p
r
i
n
t
(
'
P
N
G
'
)


p
r
i
n
t
(
)




i
m
a
g
e

=

p
n
g
.
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T
h
i
s

i
s

a

P
N
G

f
i
l
e
'
)


e
l
s
e
:



p
r
i
n
t
(
'
T
h
i
s

i
s

n
o
t

a

P
N
G

f
i
l
e
'
)


p
r
i
n
t
(
)


i
m
a
g
e
.
r
e
a
d
_
h
e
a
d
e
r
(
)


p
r
i
n
t
(
'
i
n
f
o
:







'
,

i
m
a
g
e
.
i
n
f
o
)


p
r
i
n
t
(
'
w
i
d
t
h
:






'
,

i
m
a
g
e
.
w
i
d
t
h
)


p
r
i
n
t
(
'
h
e
i
g
h
t
:





'
,

i
m
a
g
e
.
h
e
i
g
h
t
)


p
r
i
n
t
(
'
b
i
t
_
d
e
p
t
h
:


'
,

i
m
a
g
e
.
b
i
t
_
d
e
p
t
h
)


p
r
i
n
t
(
'
c
o
l
o
r
_
t
y
p
e
:

'
,

i
m
a
g
e
.
c
o
l
o
r
_
t
y
p
e
)


p
r
i
n
t
(
'
c
o
m
p
r
e
s
s
:



'
,

i
m
a
g
e
.
c
o
m
p
r
e
s
s
)


p
r
i
n
t
(
'
f
i
l
t
e
r
:





'
,

i
m
a
g
e
.
f
i
l
t
e
r
)


p
r
i
n
t
(
'
i
n
t
e
r
l
a
c
e
:


'
,

i
m
a
g
e
.
i
n
t
e
r
l
a
c
e
)


p
r
i
n
t
(
'
i
m
g
:








'
,

i
m
a
g
e
.
i
m
g
)


p
r
i
n
t
(
)


i
m
a
g
e
.
r
e
a
d
_
c
h
u
n
k
s
(
)


f
o
r

i

i
n

r
a
n
g
e
(
5
)
:



f
o
r

j

i
n

r
a
n
g
e
(
6
)
:




p
r
i
n
t
(
i
m
a
g
e
.
i
m
g
[
i
]
[
j
]
,

e
n
d
=
'

'
)



p
r
i
n
t
(
)


i
m
a
g
e
.
s
a
v
e
_
r
g
b
(
'
b
r
a
i
n
b
o
w
_
r
.
p
n
g
'
,

1
)

i
f

_
_
n
a
m
e
_
_

=
=

'
_
_
m
a
i
n
_
_
'
:


m
a
i
n
(
)

Version 1.00
Should produce the following output:
PNG

data: b''
info:
width: 0
height: 0
bit_depth: 0
color_type: 0
compress: 0
filter: 0
interlace: 0
img: []

89504e470d0a1a0a0000000d4948445200000492000002e108020000008be9191d000000097048597300000b1300000b1301
009a9c18000000206348524d00007a25000080830000f9ff000080e9000075300000ea6000003a980000176f925fc5460027

2588130
brainbow.png

12

This is a PNG file

info: brainbow.png
width: 1170
height: 737
bit_depth: 8
color_type: 2
compress: 0
filter: 0
interlace: 0
img: []

[25, 0, 4] [21, 0, 0] [3, 0, 0] [0, 6, 0] [0, 11, 3] [0, 10, 2]
[21, 0, 0] [21, 0, 0] [4, 0, 0] [0, 9, 0] [0, 12, 4] [0, 10, 2]
[0, 0, 2] [1, 1, 3] [3, 4, 0] [5, 1, 0] [5, 0, 0] [6, 1, 0]
[1, 1, 3] [3, 3, 5] [1, 2, 0] [3, 0, 0] [4, 0, 0] [8, 3, 0]
[0, 5, 5] [0, 5, 5] [1, 0, 0] [7, 0, 0] [13, 0, 0] [15, 0, 0]

The original brainbow.png image:

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图