00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <memory.h>
00036 #include <stdlib.h>
00037
00038 #include "ink.h"
00039 #include "ScribbleLog.h"
00040
00041
00042
00043 PtrInk construct_ink ()
00044 {
00045 PtrInk ink = NULL;
00046
00047 ink = malloc (sizeof (Ink));
00048 if (ink)
00049 memset (ink, 0, sizeof (Ink));
00050
00051 SB_INKPRINTF("return %p \n", ink);
00052 return ink;
00053 }
00054
00055
00056 void destroy_ink (PtrInk ink)
00057 {
00058 PtrStroke stroke = NULL;
00059 if (ink == NULL)
00060 return;
00061 stroke = ink->firstStroke;
00062 while (stroke)
00063 stroke = destroy_stroke (stroke);
00064
00065 SB_INKPRINTF("return (%p)\n", ink);
00066 free (ink);
00067 }
00068
00069
00070 PtrStroke construct_stroke ()
00071 {
00072 PtrStroke stroke = NULL;
00073
00074 stroke = malloc (sizeof (Stroke));
00075 if (stroke)
00076 memset (stroke, 0, sizeof (Stroke));
00077
00078
00079 stroke->min_x = stroke->min_y = INT_MAX;
00080 stroke->max_x = stroke->max_y = INT_MIN;
00081 SB_INKPRINTF("initial construct %p \n", stroke);
00082 return stroke;
00083 }
00084
00085
00086 PtrStroke destroy_stroke (PtrStroke stroke)
00087 {
00088 PtrInkPoint point = NULL;
00089 PtrStroke nextStroke = NULL;
00090 if (stroke == NULL)
00091 return NULL;
00092 nextStroke = stroke->nextStroke;
00093 point = stroke->firstPoint;
00094 while (point)
00095 point = destroy_point (point);
00096
00097 SB_INKPRINTF("return(%p)\n", stroke);
00098 free (stroke);
00099 return nextStroke;
00100 }
00101
00102
00103 PtrInkPoint construct_point ()
00104 {
00105 PtrInkPoint point = NULL;
00106
00107 point = malloc (sizeof (InkPoint));
00108 if (point)
00109 memset (point, 0, sizeof (InkPoint));
00110
00111 SB_INKPRINTF("return %p \n", point);
00112 return point;
00113 }
00114
00115
00116 PtrInkPoint destroy_point (PtrInkPoint point)
00117 {
00118 PtrInkPoint nextPoint = NULL;
00119 if (point == NULL)
00120 return NULL;
00121 nextPoint = point->nextPoint;
00122
00123 SB_INKPRINTF("return %p \n", point);
00124 free (point);
00125 return nextPoint;
00126 }
00127
00128
00129
00130 unsigned char ink_add_stroke (PtrInk ink, PtrStroke stroke)
00131 {
00132 if (ink == NULL || stroke == NULL)
00133 {
00134 SB_INKERRPRINTF("failed:incorrect arguments\n");
00135 return 0;
00136 }
00137
00138 if (ink->lastStroke == NULL)
00139 {
00140 ink->firstStroke = ink->lastStroke= stroke;
00141 ink->nStrokes = 1;
00142 }
00143 else
00144 {
00145 ink->lastStroke=ink->lastStroke->nextStroke = stroke;
00146 ink->nStrokes += 1;
00147 }
00148 return 1;
00149 }
00150
00151
00152 int get_num_of_strokes (PtrInk ink)
00153 {
00154 if (ink == NULL)
00155 return 0;
00156 return ink->nStrokes;
00157 }
00158
00159
00160
00161 unsigned char ink_add_point(PtrStroke stroke, PtrInkPoint point)
00162 {
00163 if (stroke == NULL || point == NULL)
00164 {
00165 SB_INKERRPRINTF("failed:incorrect arguments\n");
00166 return 0;
00167 }
00168
00169 if (stroke->lastPoint == NULL)
00170 {
00171 stroke->lastPoint=stroke->firstPoint = point;
00172 stroke->nPoints = 1;
00173 }
00174 else
00175 {
00176 stroke->lastPoint=stroke->lastPoint->nextPoint = point;
00177 stroke->nPoints += 1;
00178 }
00179
00180
00181 if( point->x < stroke->min_x) stroke->min_x=point->x;
00182 if( point->x > stroke->max_x) stroke->max_x=point->x;
00183 if( point->y < stroke->min_y) stroke->min_y=point->y;
00184 if( point->y > stroke->max_y) stroke->max_y=point->y;
00185
00186 return 1;
00187 }
00188
00189 int get_num_of_points (PtrStroke stroke)
00190 {
00191 if (stroke == NULL)
00192 return 0;
00193 return stroke->nPoints;
00194 }