-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgmUtility.h
More file actions
129 lines (112 loc) · 6.42 KB
/
pgmUtility.h
File metadata and controls
129 lines (112 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// pgmUtility.h
//
// Created by Tony Tian on 11/2/13.
// Copyright (c) 2013 Tony Tian. All rights reserved.
//
#ifndef cscd439pgm_pgmUtility_h
#define cscd439pgm_pgmUtility_h
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sys/time.h>
#define rowsInHeader 4 // number of rows in image header
#define maxSizeHeadRow 200 // maximal number characters in one row in the header
/**
* Function Name:
* pgmRead()
* pgmRead() reads in a pgm image using file I/O, you have to follow the file format. All code in this function are exectured on CPU.
*
* @param[in,out] header holds the header of the pgm file in a 2D character array
* After we process the pixels in the input image, we write the origianl
* header (or potentially modified) back to a new image file.
* @param[in,out] numRows describes how many rows of pixels in the image.
* @param[in,out] numCols describe how many pixels in one row in the image.
* @param[in] in FILE pointer, points to an opened image file that we like to read in.
* @return If successful, return all pixels in the pgm image, which is an int *, equivalent to
* a 1D array that stores a 2D image in a linearized fashion. Otherwise null.
*
*/
int * pgmRead( char **header, int *numRows, int *numCols, FILE *in );
/**
* Function Name:
* pgmDrawCircle()
* pgmDrawCircle() draw a circle on the image by setting relavant pixels to Zero.
* In this function, you have to invoke a CUDA kernel to perform all image processing on GPU.
*
* @param[in,out] pixels holds all pixels in the pgm image, which a 1D integer array. The array
* are modified after the drawing.
* @param[in] numRows describes how many rows of pixels in the image.
* @param[in] numCols describes how many columns of pixels in one row in the image.
* @param[in] centerCol specifies at which column you like to center your circle.
* @param[in] centerRow specifies at which row you like to center your circle.
* centerCol and centerRow defines the center of the circle.
* @param[in] radius specifies what the radius of the circle would be, in number of pixels.
* @param[in,out] header returns the new header after draw.
* the circle draw might change the maximum intensity value in the image, so we
* have to change maximum intensity value in the header accordingly.
* @return return 1 if max intensity is changed, otherwise return 0;
*/
int pgmDrawCircle( int *pixels, int numRows, int numCols, int centerRow,
int centerCol, int radius, char **header );
/**
* Function Name:
* pgmDrawEdge()
* pgmDrawEdge() draws a black edge frame around the image by setting relavant pixels to Zero.
* In this function, you have to invoke a CUDA kernel to perform all image processing on GPU.
*
* @param[in,out] pixels holds all pixels in the pgm image, which a 1D integer array. The array
* are modified after the drawing.
* @param[in] numRows describes how many rows of pixels in the image.
* @param[in] numCols describes how many columns of pixels in one row in the image.
* @param[in] edgeWidth specifies how wide the edge frame would be, in number of pixels.
* @param[in,out] header returns the new header after draw.
* the function might change the maximum intensity value in the image, so we
* have to change the maximum intensity value in the header accordingly.
*
* @return return 1 if max intensity is changed by the drawing, otherwise return 0;
*/
int pgmDrawEdge( int *pixels, int numRows, int numCols, int edgeWidth, char **header );
/**
* Function Name:
* pgmDrawLine()
* pgmDrawLine() draws a straight line in the image by setting relavant pixels to Zero.
* In this function, you have to invoke a CUDA kernel to perform all image processing on GPU.
*
* @param[in,out] pixels holds all pixels in the pgm image, which a 1D integer array. The array
* are modified after the drawing.
* @param[in] numRows describes how many rows of pixels in the image.
* @param[in] numCols describes how many columns of pixels in one row in the image.
* @param[in] p1row specifies the row number of the start point of the line segment.
* @param[in] p1col specifies the column number of the start point of the line segment.
* @param[in] p2row specifies the row number of the end point of the line segment.
* @param[in] p2col specifies the column number of the end point of the line segment.
* @param[in,out] header returns the new header after draw.
* the function might change the maximum intensity value in the image, so we
* have to change the maximum intensity value in the header accordingly.
*
* @return return 1 if max intensity is changed by the drawing, otherwise return 0;
*/
int pgmDrawLine( int *pixels, int numRows, int numCols, char **header, int p1row, int p1col, int p2row, int p2col );
/**
* Function Name:
* pgmWrite()
* pgmWrite() writes headers and pixels into a pgm image using file I/O.
* writing back image has to strictly follow the image format. All code in this function are exectured on CPU.
*
* @param[in] header holds the header of the pgm file in a 2D character array
* we write the header back to a new image file on disk.
* @param[in] pixels holds all pixels in the pgm image, which a 1D integer array that stores a 2D image in a linearized fashion.
* @param[in] numRows describes how many rows of pixels in the image.
* @param[in] numCols describe how many columns of pixels in one row in the image.
* @param[in] out FILE pointer, points to an opened text file that we like to write into.
* @return return 0 if the function successfully writes the header and pixels into file.
* else return -1;
*/
int pgmWrite(char **header, const int *pixels, int numRows, int numCols, FILE *out );
// added functions
int recalculateIntensity(int * pixels, char ** header, int numCols, int numRows);
void printSpeedup(double time, double ptime, char * name);
double currentTime();
#endif