Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lab3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CC = gcc
CFLAGS = -Wall -std=gnu99 -g # "curl-config --cflags" output is empty
LD = gcc
LDFLAGS = -std=gnu99 -g
LDLIBS = -lz -lcurl -pthread # "curl-config --libs" output

SRCS = paster2.c zutil.c crc.c
OBJS = paster2.o zutil.o crc.o
TARGETS= paster2

all: ${TARGETS}

paster2: $(OBJS)
$(LD) -o $@ $^ $(LDLIBS) $(LDFLAGS)

%.o: %.c
$(CC) $(CFLAGS) -c $<

%.d: %.c
gcc -MM -MF $@ $<

-include $(SRCS:.c=.d)

.PHONY: clean
clean:
rm -f *~ *.d *.o *~ $(TARGETS) *.png
~
54 changes: 54 additions & 0 deletions lab3/crc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/********************************************************************
* @file: crc.c
* @brief: PNG crc calculation
* Reference: https://www.w3.org/TR/PNG-CRCAppendix.html
*/

/* Table of CRCs of all 8-bit messages. */
unsigned long crc_table[256];

/* Flag: has the table been computed? Initially false. */
int crc_table_computed = 0;

/* Make the table for a fast CRC. */
void make_crc_table(void)
{
unsigned long c;
int n, k;

for (n = 0; n < 256; n++) {
c = (unsigned long) n;
for (k = 0; k < 8; k++) {
if (c & 1)
c = 0xedb88320L ^ (c >> 1);
else
c = c >> 1;
}
crc_table[n] = c;
}
crc_table_computed = 1;
}

/* Update a running CRC with the bytes buf[0..len-1]--the CRC
should be initialized to all 1's, and the transmitted value
is the 1's complement of the final running CRC (see the
crc() routine below)). */

unsigned long update_crc(unsigned long crc, unsigned char *buf, int len)
{
unsigned long c = crc;
int n;

if (!crc_table_computed)
make_crc_table();
for (n = 0; n < len; n++) {
c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
}
return c;
}

/* Return the CRC of the bytes buf[0..len-1]. */
unsigned long crc(unsigned char *buf, int len)
{
return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
}
10 changes: 10 additions & 0 deletions lab3/crc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @file: crc.h
* @brief: crc calculation functions for PNG file
*/

#pragma once

void make_crc_table(void);
unsigned long update_crc(unsigned long crc, unsigned char *buf, int len);
unsigned long crc(unsigned char *buf, int len);
40 changes: 40 additions & 0 deletions lab3/lab3_eceubuntu1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
B,P,C,X,N,Time
5,1,1,0,1,11.031589
5,1,5,0,1,16.740917
5,5,1,0,1,2.379882
5,5,5,0,1,3.559238
10,1,1,0,1,10.849649
10,1,5,0,1,14.668302
10,1,10,0,1,18.287099
10,5,1,0,1,2.185177
10,5,5,0,1,3.189513
10,5,10,0,1,4.437578
10,10,1,0,1,1.179276
10,10,5,0,1,1.513533
10,10,10,0,1,1.901437
5,1,1,200,1,10.478608
5,1,5,200,1,10.845563
5,5,1,200,1,
5,5,5,200,1,2.95628
10,1,1,200,1,10.488353
10,1,5,200,1,10.824044
10,1,10,200,1,10.901582
10,5,1,200,1,
10,5,5,200,1,2.508308
10,5,10,200,1,2.5136
10,10,1,200,1,
10,10,5,200,1,
10,10,10,200,1,1.720996
5,1,1,400,1,20.07438
5,1,5,400,1,10.747398
5,5,1,400,1,
5,5,5,400,1,4.502687
10,1,1,400,1,20.104304
10,1,5,400,1,10.760721
10,1,10,400,1,10.815564
10,5,1,400,1,
10,5,5,400,1,4.515022
10,5,10,400,1,2.949063
10,10,1,400,1,
10,10,5,400,1,
10,10,10,400,1,2.562455
Loading