File: storage.cc

package info (click to toggle)
gri 2.4.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,540 kB
  • ctags: 1,966
  • sloc: cpp: 32,542; lisp: 3,243; perl: 806; makefile: 548; sh: 253
file content (121 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download
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
//#define DEBUG_STORAGE		// Debug

#include        <stdio.h>
#include	"gr.hh"
#include	"extern.hh"
#include	"image_ex.hh"
#include	"private.hh"
extern char     _grTempString[];

/*
 * Allocate storage.
 */
#define CHARLEN	50
bool
create_arrays()
{
    GET_STORAGE(_dstack, double, _num_dstackMAX);
    GET_STORAGE(_errorMsg, char, LineLength);
    GET_STORAGE(_cmdLine, char, LineLength);
    GET_STORAGE(_cmdLineCOPY, char, LineLength);
    GET_STORAGE(_imageTransform, unsigned char, 3 * 256);
    GET_STORAGE(_imageHist, double, 256);
    return true;
}

bool
allocate_image_storage(int nx, int ny)
{
    if (nx < 0 || ny < 0)
	return false;
    if (image_exists())
	delete [] _image.image;
    _image.ras_magic = RAS_MAGIC;
    _image.ras_width = nx;
    _image.ras_height = ny;
    _image.ras_depth = 8;
    _image.ras_length = _image.ras_width * _image.ras_height;
    _image.ras_type = RT_STANDARD;
    _image.ras_maptype = RMT_NONE;
    _image.ras_maplength = 0;
    _image.image = new unsigned char[_image.ras_length];
    if (!_image.image) OUT_OF_MEMORY;
    _imageHist_exists = false;
    return true;
}

bool
allocate_imageMask_storage(int nx, int ny)
{
    if (nx < 0 || ny < 0)
	return false;
    if (imageMask_exists())
	delete [] _imageMask.image;
    _imageMask.ras_magic = RAS_MAGIC;
    _imageMask.ras_width = nx;
    _imageMask.ras_height = ny;
    _imageMask.ras_depth = 8;
    _imageMask.ras_length = _imageMask.ras_width * _imageMask.ras_height;
    _imageMask.ras_type = RT_STANDARD;
    _imageMask.ras_maptype = RMT_NONE;
    _imageMask.ras_maplength = 0;
    _imageMask.image = new unsigned char[_imageMask.ras_length];
    if (!_imageMask.image) OUT_OF_MEMORY;
    for (unsigned int i = 0; i < _imageMask.ras_length; i++)
	*(_imageMask.image + i) = 0;
    _imageHist_exists = false;
    return true;
}

bool
allocate_grid_storage(int nx, int ny)
{
    if (nx < 0 || ny < 0)
	return false;
    _num_xmatrix_data = nx;
    _num_ymatrix_data = ny;
    _f_xy.set_size(_num_xmatrix_data, _num_ymatrix_data);
    _f_xy.set_value(0.0);
    _legit_xy.set_size(_num_xmatrix_data, _num_ymatrix_data);
    _legit_xy.set_value(true);
    _grid_exists = true;
    return true;
}

bool
allocate_xmatrix_storage(int cols)
{
    if (_xgrid_exists == true) {
#if defined(DEBUG_STORAGE)
	printf("allocate_xmatrix_storage(%d) deleting at %x\n", cols,_xmatrix);
#endif
	delete [] _xmatrix;
    }
    _num_xmatrix_data = cols;
    _xmatrix = new double [_num_xmatrix_data];
    if (!_xmatrix) OUT_OF_MEMORY;
#if defined(DEBUG_STORAGE)
    printf("allocate_xmatrix_storage(%d) allocating at %x\n", cols,_xmatrix);
#endif
    _xgrid_exists = true;
    return true;
}

bool
allocate_ymatrix_storage(int rows)
{
    if (_ygrid_exists == true) {
#if defined(DEBUG_STORAGE)
	printf("allocate_ymatrix_storage(%d) deleting at %x\n", rows,_ymatrix);
#endif
	delete [] _ymatrix;
    }
    _num_ymatrix_data = rows;
    _ymatrix = new double [_num_ymatrix_data];
    if (!_ymatrix) OUT_OF_MEMORY;
#if defined(DEBUG_STORAGE)
    printf("allocate_ymatrix_storage(%d) allocating at %x\n", rows,_ymatrix);
#endif
    _ygrid_exists = true;
    return true;
}