Skip to content

Commit ac5d394

Browse files
committed
blurfilter
0 parents  commit ac5d394

13 files changed

+8393
-0
lines changed

bristolCathedral.pgm

Lines changed: 6142 additions & 0 deletions
Large diffs are not rendered by default.

competition.pgm

Lines changed: 446 additions & 0 deletions
Large diffs are not rendered by default.

cow.pgm

Lines changed: 639 additions & 0 deletions
Large diffs are not rendered by default.

creator.pgm

Lines changed: 380 additions & 0 deletions
Large diffs are not rendered by default.

filter.xc

Lines changed: 415 additions & 0 deletions
Large diffs are not rendered by default.

lol2.pgm

Lines changed: 134 additions & 0 deletions
Large diffs are not rendered by default.

pgmIO.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* derp.xc
3+
*
4+
* Created on: Dec 20, 2011
5+
* Author: jamie
6+
*/
7+
8+
#ifndef PGMIO_H_
9+
#define PGMIO_H_
10+
#include <stdlib.h>
11+
#include <stdio.h>
12+
#include <string.h>
13+
/////////////////////////////////////////////////////////////////////////////////////////////
14+
//
15+
// standard pgm input and output routines
16+
//
17+
// Input is a referenced array of unsigned chars of width and height and a
18+
// referenced char array of the system path to destination, e.g.
19+
// "/home/user/xmos/project/" on Linux or "C:\\user\\xmos\\project\\" on Windows
20+
//
21+
/////////////////////////////////////////////////////////////////////////////////////////////
22+
int _writepgm(unsigned char x[], int height, int width, char fname[]);
23+
int _readpgm(unsigned char x[], int height, int width, char fname[]);
24+
/////////////////////////////////////////////////////////////////////////////////////////////
25+
//
26+
// Line-wise pgm input routines: open file, read a line, close the file
27+
//
28+
/////////////////////////////////////////////////////////////////////////////////////////////
29+
int _openinpgm(char fname[], int width, int height);
30+
int _readinline(unsigned char line[], int width);
31+
int _closeinpgm();
32+
/////////////////////////////////////////////////////////////////////////////////////////////
33+
//
34+
// Line-wise pgm output routines: open file, read a line, close the file
35+
//
36+
/////////////////////////////////////////////////////////////////////////////////////////////
37+
int _openoutpgm(char fname[], int width, int height);
38+
int _writeoutline(unsigned char line[], int width);
39+
int _closeoutpgm();
40+
#endif /*PGMIO_H_*/

pgmlO.c

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* pgmlO.c
3+
*
4+
* Created on: Dec 20, 2011
5+
* Author: jamie
6+
*/
7+
8+
#include "pgmIO.h"
9+
FILE *_INFP = NULL;
10+
FILE *_OUTFP = NULL;
11+
/////////////////////////////////////////////////////////////////////////////////////////////
12+
//
13+
// Line-wise pgm input routines: open file, read a line, close the file
14+
//
15+
/////////////////////////////////////////////////////////////////////////////////////////////
16+
int _openinpgm(char fname[], int width, int height)
17+
{
18+
char str[ 64 ];
19+
int inwidth, inheight;
20+
_INFP = fopen( fname, "rb" );
21+
if( _INFP == NULL )
22+
{
23+
printf( "Could not open %s.\n", fname );
24+
return -1;
25+
}
26+
//Strip off header
27+
fgets( str, 64, _INFP ); //Version: P5
28+
fgets( str, 64, _INFP ); //width and height
29+
sscanf( str, "%d%d", &inwidth, &inheight );
30+
if( inwidth != width || inheight != height )
31+
{
32+
printf( "Input image size(%dx%d) does not = %dx%d or trouble reading header\n", inwidth,
33+
inheight, width, height );
34+
return -1;
35+
}
36+
fgets( str, 64, _INFP ); //bit depth, must be 255
37+
return 0;
38+
}
39+
40+
int _readinline(unsigned char line[], int width)
41+
{
42+
int nb;
43+
if( _INFP == NULL )
44+
{
45+
return -1;
46+
}
47+
nb = fread( line, 1, width, _INFP );
48+
if( nb != width )
49+
{
50+
//printf( "Error reading line, nb = %d\n", nb );
51+
//Error or end of file
52+
return -1;
53+
}
54+
return 0;
55+
}
56+
int _closeinpgm()
57+
{
58+
int ret = fclose( _INFP );
59+
if( ret == 0 )
60+
{
61+
_INFP = NULL;
62+
}
63+
else
64+
{
65+
printf( "Error closing file _INFP.\n" );
66+
}
67+
return ret; //return zero for succes and EOF for fail
68+
}
69+
70+
/////////////////////////////////////////////////////////////////////////////////////////////
71+
//
72+
// Line-wise pgm output routines: open file, read a line, close the file
73+
//
74+
/////////////////////////////////////////////////////////////////////////////////////////////
75+
int _openoutpgm(char fname[], int width, int height)
76+
{
77+
char hdr[ 64 ];
78+
_OUTFP = fopen( fname, "wb" );
79+
if( _OUTFP == NULL )
80+
{
81+
printf( "Could not open %s.\n", fname );
82+
return -1;
83+
}
84+
sprintf( hdr, "P5\n%d %d\n255\n", width, height );
85+
fprintf( _OUTFP, "%s", hdr );
86+
return 0;
87+
}
88+
89+
int _writeoutline(unsigned char line[], int width)
90+
{
91+
int nb;
92+
if( _OUTFP == NULL )
93+
{
94+
return -1;
95+
}
96+
nb = fwrite( line, 1, width, _OUTFP );
97+
if( nb != width )
98+
{
99+
//printf( "Error writing line, nb = %d\n", nb );
100+
//Error or end of file
101+
return -1;
102+
}
103+
return 0;
104+
}
105+
106+
int _closeoutpgm()
107+
{
108+
int ret = fclose( _OUTFP );
109+
if( ret == 0 )
110+
{
111+
_OUTFP = NULL;
112+
}
113+
else
114+
{
115+
printf( "Error closing file _OUTFP.\n" );
116+
}
117+
return ret; //return zero for succes and EOF for fail
118+
}
119+
120+
/////////////////////////////////////////////////////////////////////////////////////////////
121+
//
122+
// standard pgm input and output routines
123+
//
124+
// Input is a referenced array of unsigned chars of width and height and a
125+
// referenced char array of the system path to destination, e.g.
126+
// "/home/user/xmos/project/" on Linux or "C:\\user\\xmos\\project\\" on Windows
127+
//
128+
/////////////////////////////////////////////////////////////////////////////////////////////
129+
int _writepgm(unsigned char x[], int height, int width, char fname[])
130+
{
131+
FILE *fp;
132+
int hlen;
133+
char hdr[ 64 ];
134+
sprintf( hdr, "P5\n%d %d\n255\n", width, height );
135+
hlen = strlen( hdr );
136+
printf( "In writepgm function, writing: %s\n", fname );
137+
fp = fopen( fname, "wb" );
138+
if( fp == NULL)
139+
{
140+
printf( "Could not open %s for writing.\n", fname );
141+
return -1;
142+
}
143+
fprintf( fp, "%s", hdr );
144+
fwrite( x, width * height, 1, fp );
145+
fclose( fp );
146+
return 0;
147+
}
148+
149+
int _readpgm(unsigned char x[], int height, int width, char fname[])
150+
{
151+
FILE *fp;
152+
unsigned int inwidth, inheight;
153+
char str[ 64 ];
154+
printf( "In readpgm function, reading: %s\n", fname );
155+
fp = fopen( fname, "rb" );
156+
if( fp == NULL)
157+
{
158+
printf( "Could not open %s for reading.\n", fname );
159+
return -1;
160+
}
161+
fgets( str, 64, fp ); //Version: P5
162+
fgets( str, 64, fp ); //width and height
163+
sscanf( str, "%d%d", &inwidth, &inheight );
164+
fgets( str, 64, fp ); //bit depth, must be 255
165+
if( inwidth != width || inheight != height )
166+
{
167+
printf( "Input image size(%dx%d) does not = %dx%d or trouble reading header\n", inwidth,
168+
inheight, width, height );
169+
return -1;
170+
}
171+
fread( x, inwidth * inheight, 1, fp );
172+
fclose( fp );
173+
return 0;
174+
}
175+

test.pgm

273 Bytes
Binary file not shown.

test0.pgm

269 Bytes
Binary file not shown.

test1.pgm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
P5
2+
16 16
3+
255
4+
����������������� ��� ��}��� �j ��� �<��� ���R �I �& ����{�S�t �+  ����� m��� �' } ��� o � � A��������������������^j$ �2 Wf"�� :� �% �J � �� ���q �! �� �x���� � �(���s �� � ~ �9�y��� �� '�� �& Wx ��  �  �����������������

test2.pgm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
P5
2+
64 64
3+
255
4+
���������������������������������������������������������������������������������������������������������������������������������� ,��` ��� ���B �������������� ��������������h ���� ��` ��� ���4 ���9��������r ��������������� ~���� U��� ���/ ���l ��� �������� ��������������| o����� m" 7�e Syo ��� ������� �������������Q ������ ��� ������� -������������#
5+
������� ��� x������ ����������� �������� 
6+
��� ������ f��������} ��������� S6=5\Ћ ��� �����n "�������1 ���������� #� ��s F ��� ����D <������" d����������  �ڶ�� ��� p�� ����� ����������� ������ ��� �K ����Z ������������ ������w � ��� � ���� ������������� �Ŕ�������! �� ��� ���� k������������� ���[|������ ��] ��� ��� �������������� &��� �������O ��@ ��� ��� ��������������� ���� �������� ��� � �����������t���� ���;<���Tz��$ ���
7+
�����������@���� ���3 s ��(+H ��� w���u �u��? U���� ��5 ����� ��� ��� ����� ��l }�8 ����S ���
8+
��� )����� ^- ���
9+
%�����F ��� ��H ?������ s������������ ��� !  Yέ��������� ���ܲ] ���8 ��� k� ������������ 7~ ���� ��� �] ������������� &��� ��� ��
10+
�������������� dk ��� �( X����������������� ��� �� m���������������� W�������? ��� ����ɲ�� \vt���������� #h�������������������������������}& �����������r�����������mzz^�����������lzyd������������R�������������������������i3 %�����Y  Z�������������������� =��������z�+ ��� oy��������s 2���� ��� >���� ��� O����  ��� �� P���� :�4 ��� �  ��/ M���� ���y c; ��� {���� �T�) P���� �����+DC�% ��� ����� �D� N���� ����' n�[ ��� q���}�a ��� 4 N���� +����x������' ��� 9��� ���U P���� N���� ������������� ��� ) v��� ;��7 P���� #�������� ����� ��� ����� ��& N���� �������m ����� ��� �����^ ��2 M���� L�������� L������ ��� {�����ڸ��ہ �� O���� ��������\ ���� ���
11+
�[ �������������V O���� �������5 ��� ��� JM� �������������� O���� ��ڏ��� ��T ��� W� (��������������! O���� ��� : 5 �� ��� h] ���������������! M���� $���� �� ��� kI }  g�����n���� P���� p�S
12+
: �� OM ��� =: a^  ��� M����  N ��� M�C ��� F� �� P���� �� ���� O �� ��� �' ?�� N����  ���h������ ��� K, <� �: N���� �� ��G�� ��� ��% � N���� B 4 ��� / �: N���� ��� ;M �� N���� ��� �� O����   ���   ! I���� "b�������ˢL �������������" /�����H n��������������������������������' ������������������������������������������������������������������������������������������������������������������������������������

testout.pgm

Lines changed: 6 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)