Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct image_struct
- {
- // Header
- uint32_t id;
- uint32_t timestamp;
- uint16_t nHeight;
- uint16_t nWidth;
- // Buffer
- float *depth_map;
- uint16_t *amplitude_map;
- uint16_t getWidth(){ return nWidth;};
- uint16_t getHeight(){return nHeight;};
- } IMAGE_STRUCT;
- void atImageEvent( short eventType, int size, short imageFormat, char* sfimageData, int dataLength, std::string& pScannerData )
- {
- std::string image_format;
- switch ( imageFormat )
- {
- case JPEG_FILE_SECTION:
- image_format = ".jpg";
- break;
- case TIFF_FILE_SECTION:
- image_format = ".tiff";
- break;
- case BMP_FILE_SECTION:
- image_format = ".bmp";
- break;
- case RAW_FILE_SELECTION:
- image_format = ".deb";
- break;
- case RAW_PROCESSED_FILE_SELECTION:
- image_format = ".dpf";
- break;
- case DEPTH_FRAME_FILE_SELECTION:
- image_format = ".dpf";
- break;
- default:
- cout << "Different type of image format, but saving as .dpf." << endl;
- image_format = ".dpf";
- break;
- }
- string sFileName;
- stringstream ss;
- ss << "imagedata";
- ss << this->iImageFileNumber++;
- ss << image_format;
- sFileName = ss.str();
- // cast image data into depth frame buffer.
- IMAGE_STRUCT output_image_struct;
- // define lengths for image struct
- int dataIndex=0;
- int idLength = sizeof(uint32_t);
- int tstampLength = sizeof(uint32_t);
- int heightLength = sizeof(uint16_t);
- int widthLength = sizeof(uint16_t);
- uint8_t *id, *timeStamp, *imgHeight, *imgWidth, *depthFrameData, *amplitudeData;
- id = (uint8_t *)malloc(sizeof(uint32_t));
- memset(id, 0x00, idLength);
- dataIndex = idLength;
- memcpy(id, sfimageData, sizeof(uint32_t));
- union
- {
- uint32_t _id;
- uint8_t *_byteArray;
- }uId;
- memcpy(&uId._byteArray, id, sizeof(uint32_t));
- free(id);
- output_image_struct.id = uId._id;
- timeStamp = (uint8_t *)malloc(sizeof(uint32_t));
- memset(timeStamp, 0x00, tstampLength);
- memcpy(timeStamp, sfimageData+dataIndex, sizeof(uint32_t));
- dataIndex += tstampLength;
- union
- {
- uint32_t _timeStamp;
- uint8_t *_byteArray;
- }uTimeStamp;
- memcpy(&uTimeStamp._byteArray, timeStamp, tstampLength);
- free(timeStamp);
- output_image_struct.timestamp = uTimeStamp._timeStamp;
- imgHeight = (uint8_t *)malloc(heightLength);
- memcpy(imgHeight, sfimageData+dataIndex, sizeof(uint16_t));
- dataIndex += heightLength;
- union
- {
- uint16_t _imgHeight;
- uint8_t *_byteArray;
- }uImgHeight;
- memcpy(&uImgHeight._byteArray, imgHeight, heightLength);
- free(imgHeight);
- output_image_struct.nHeight = uImgHeight._imgHeight;
- imgWidth = (uint8_t *)malloc(widthLength);
- memset(imgWidth, 0x00, widthLength);
- memcpy(imgWidth, sfimageData+dataIndex, sizeof(uint16_t));
- dataIndex += widthLength;
- union
- {
- uint32_t _imgWidth;
- uint8_t *_byteArray;
- }uImgWidth;
- memcpy(&uImgWidth._byteArray, imgWidth, widthLength);
- free(imgWidth);
- output_image_struct.nWidth = uImgWidth._imgWidth;
- int depthFrameLength = output_depth_frame.nHeight * output_depth_frame.nWidth * sizeof(float);
- int amplitudeMapLength = output_depth_frame.nHeight * output_depth_frame.nWidth * sizeof(uint16_t);
- depthFrameData = (uint8_t *)malloc(depthFrameLength);
- memset(depthFrameData, 0x00, depthFrameLength);
- memcpy(depthFrameData, sfimageData+dataIndex, depthFrameLength);
- dataIndex += depthFrameLength;
- union
- {
- uint8_t *byteArray;
- float *floatArray;
- } uDepthFrame;
- uDepthFrame.byteArray = depthFrameData;
- output_image_struct.depth_map = uDepthFrame.floatArray;
- amplitudeData = (uint8_t *)malloc(amplitudeMapLength);
- memset(amplitudeData, 0x00, amplitudeMapLength);
- memcpy(amplitudeData, sfimageData + dataIndex, amplitudeMapLength);
- dataIndex += amplitudeMapLength;
- union
- {
- uint8_t *byteArray;
- uint16_t *uint16Array;
- } uAmplitude;
- uAmplitude.byteArray = amplitudeData;
- output_image_struct.amplitude_map = uAmplitude.uint16Array;
- int middleIndex = (output_image_struct.getHeight()+1)*output_image_struct.getWidth()/2;
- // Print output_image_struct (primitive members)
- cout << "-----------------------------------------------------" << endl;
- cout << "ID: " << output_image_struct.id << endl;
- cout << "TimeStamp: " << output_image_struct.timestamp << endl;
- cout << "Img Height: " << output_image_struct.nHeight << endl;
- cout << "Img Width: " << output_image_struct.nWidth << endl;
- cout << "First Index: " << 0 << " value: " << output_image_struct.depth_map[0] << endl;
- cout << "Middle Index: " << middleIndex << " value: " << output_image_struct.depth_map[middleIndex] << endl;
- cout << "last Index: " << (output_image_struct.getHeight() * output_image_struct.getWidth()) - 1 << " value: " << output_image_struct.depth_map[ (output_image_struct.getHeight() * output_image_struct.getWidth()) - 1 ] << endl;
- cout << "-----------------------------------------------------" << endl;
- // print data if interested
- for(int x=0; x<depthFrameLength/sizeof(float); x++)
- {
- cout << " " << output_depth_frame.depth_map[x];
- }
- for(int x=0; x<amplitudeMapLength/sizeof(uint16_t); x++)
- {
- cout << " " << output_image_struct.amplitude_map[x];
- }
- cout << "END ********************" << endl;
- free(depthFrameData);
- free(amplitudeData);
- }
- const char * fileExtensionOfFormat(img_fmt); // JPEG_FILE_SECTION -> ".jpg"
- typedef uint8_t byte;
- IMAGE_STRUCT * decodeImageData(byte * img_data);
- uint16_t read_uint16(byte *);
- uint32_t read_uint32(byte *);
- float read_float(byte *);
- uint16_t read_short(byte * p) {
- return *(uint16_t *)p;
- }
- union
- {
- uint16_t _imgHeight;
- uint8_t *_byteArray;
- }uImgHeight;
- memcpy(&uImgHeight._byteArray, imgHeight, heightLength);
- free(imgHeight);
- output_image_struct.nHeight = uImgHeight._imgHeight;
- id = (uint8_t *)malloc(sizeof(uint32_t)); // #1
- memset(id, 0x00, idLength); // #2
- dataIndex = idLength;
- memcpy(id, sfimageData, sizeof(uint32_t)); // #3
- union
- {
- uint32_t _id;
- uint8_t *_byteArray;
- }uId;
- memcpy(&uId._byteArray, id, sizeof(uint32_t)); // #4
- free(id);
- output_image_struct.id = uId._id; // #5
- #pragma pack(push,1) // structure packing syntax may vary
- struct image_struct_data
- {
- uint32_t id;
- uint32_t timestamp;
- uint16_t nHeight;
- uint16_t nWidth;
- };
- #pragma pack(pop)
- struct image_struct
- {
- image_struct_data data;
- // Buffers
- float *depth_map;
- uint16_t *amplitude_map;
- uint16_t getWidth() {return data.nWidth;};
- uint16_t getHeight() {return data.nHeight;};
- };
- ...
- image_struct_data output_image_struct;
- memcpy(&output_image_struct, sfimageData, sizeof(output_image_struct));
- sfimageData += sizeof(output_image_struct);
- int depthFrameLength = output_image_struct.nHeight * output_image_struct.nWidth * sizeof(float);
- int amplitudeMapLength = output_image_struct.nHeight * output_image_struct.nWidth * sizeof(uint16_t);
- output_image_struct.depth_map = malloc(depthFrameLength);
- memcpy(output_image_struct.depth_map, sfimageData, depthFrameLength);
- sfimageData += depthFrameLength;
- output_image_struct.amplitude_map = malloc(amplitudeMapLength);
- memcpy(output_image_struct.amplitude_map, sfimageData, amplitudeMapLength);
- sfimageData += amplitudeMapLength;
- ...
Add Comment
Please, Sign In to add comment