00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <fvutils/net/fuse_lut_content.h>
00025 #include <fvutils/ipc/shm_lut.h>
00026
00027 #include <core/exceptions/system.h>
00028 #include <core/exceptions/software.h>
00029
00030 #include <cstdlib>
00031 #include <netinet/in.h>
00032 #include <cstring>
00033
00034 namespace firevision {
00035 #if 0
00036 }
00037 #endif
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 FuseLutContent::FuseLutContent(uint32_t type,
00053 void *payload, size_t payload_size)
00054 {
00055 if ( (type != FUSE_MT_LUT) && (type != FUSE_MT_SET_LUT) ) {
00056 throw fawkes::TypeMismatchException("Type %u != FUSE_MT_LUT/FUSE_MT_SET_LUT (%u/%u)",
00057 type, FUSE_MT_LUT, FUSE_MT_SET_LUT);
00058 }
00059
00060 _payload_size = payload_size;
00061 _payload = payload;
00062
00063
00064 __header = (FUSE_lut_message_header_t *)_payload;
00065 __buffer = (unsigned char *)_payload + sizeof(FUSE_lut_message_header_t);
00066
00067 __lut_id = (char *)malloc(LUT_ID_MAX_LENGTH + 1);
00068 __lut_id[LUT_ID_MAX_LENGTH] = 0;
00069 strncpy(__lut_id, __header->lut_id, LUT_ID_MAX_LENGTH);
00070
00071 __buffer_size = ntohl(__header->width) * ntohl(__header->height) *
00072 ntohl(__header->depth) * ntohl(__header->bytes_per_cell);
00073 }
00074
00075
00076
00077
00078
00079 FuseLutContent::FuseLutContent(SharedMemoryLookupTable *b)
00080 {
00081 __buffer_size = b->width() * b->height() * b->depth() * b->bytes_per_cell();
00082 _payload_size = __buffer_size + sizeof(FUSE_lut_message_header_t);
00083
00084 _payload = malloc(_payload_size);
00085 if ( _payload == NULL ) {
00086 throw fawkes::OutOfMemoryException("Cannot allocate FuseLutContent buffer");
00087 }
00088
00089 __header = (FUSE_lut_message_header_t *)_payload;
00090 __buffer = (unsigned char *)_payload + sizeof(FUSE_lut_message_header_t);
00091
00092 strncpy(__header->lut_id, b->lut_id(), LUT_ID_MAX_LENGTH);
00093 __header->width = htonl(b->width());
00094 __header->height = htonl(b->height());
00095 __header->depth = htonl(b->depth());
00096 __header->bytes_per_cell = htonl(b->bytes_per_cell());
00097 __lut_id = strdup(b->lut_id());
00098
00099
00100 memcpy(__buffer, b->buffer(), __buffer_size);
00101
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 FuseLutContent::FuseLutContent(const char *lut_id, void *buffer,
00115 unsigned int width, unsigned int height,
00116 unsigned int depth, unsigned int bpc)
00117 {
00118 __buffer_size = width * height * depth * bpc;
00119 _payload_size = __buffer_size + sizeof(FUSE_lut_message_header_t);
00120
00121 _payload = malloc(_payload_size);
00122 if ( _payload == NULL ) {
00123 throw fawkes::OutOfMemoryException("Cannot allocate FuseLutContent buffer");
00124 }
00125
00126 __header = (FUSE_lut_message_header_t *)_payload;
00127 __buffer = (unsigned char *)_payload + sizeof(FUSE_lut_message_header_t);
00128
00129 strncpy(__header->lut_id, lut_id, LUT_ID_MAX_LENGTH);
00130 __header->width = htonl(width);
00131 __header->height = htonl(height);
00132 __header->depth = htonl(depth);
00133 __header->bytes_per_cell = htonl(bpc);
00134 __lut_id = strdup(lut_id);
00135
00136 memcpy(__buffer, buffer, __buffer_size);
00137 }
00138
00139
00140 FuseLutContent::~FuseLutContent()
00141 {
00142 free(__lut_id);
00143 }
00144
00145
00146
00147
00148
00149 const char *
00150 FuseLutContent::lut_id() const
00151 {
00152 return __lut_id;
00153 }
00154
00155
00156
00157
00158 unsigned char *
00159 FuseLutContent::buffer() const
00160 {
00161 return __buffer;
00162 }
00163
00164
00165
00166
00167
00168 size_t
00169 FuseLutContent::buffer_size() const
00170 {
00171 return __buffer_size;
00172 }
00173
00174
00175
00176
00177
00178 unsigned int
00179 FuseLutContent::width() const
00180 {
00181 return ntohl(__header->width);
00182 }
00183
00184
00185
00186
00187
00188 unsigned int
00189 FuseLutContent::height() const
00190 {
00191 return ntohl(__header->height);
00192 }
00193
00194
00195
00196
00197 unsigned int
00198 FuseLutContent::depth() const
00199 {
00200 return ntohl(__header->depth);
00201 }
00202
00203
00204
00205
00206
00207 unsigned int
00208 FuseLutContent::bytes_per_cell() const
00209 {
00210 return ntohl(__header->bytes_per_cell);
00211 }
00212
00213
00214 void
00215 FuseLutContent::serialize()
00216 {
00217
00218 }
00219
00220 }