start adding security vulnerabilities (packet class)
This commit is contained in:
38
packets/ImagePacket.cpp
Normal file
38
packets/ImagePacket.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "ImagePacket.h"
|
||||
|
||||
/*
|
||||
* Construct a packet from an OpenCV Mat, and a beginning index. It will take PACKET_SIZE bytes from the start and add
|
||||
* it to its slice
|
||||
*/
|
||||
ImagePacket::ImagePacket(const cv::Mat *image, const int begin) {
|
||||
const uchar *target = &image->data[begin];
|
||||
// TODO: handle out of index cases, pad with zeroes. probably also instantiate our byte array with zeroes
|
||||
for (int i = 0; i < PACKET_SIZE; i++) {
|
||||
slice[i] = target[begin + i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct a packet from a raw array of unsigned chars, and a beginning index. It will take PACKET_SIZE bytes from the
|
||||
* start and add it to its slice. This will be more useful for embedded scenarios where OpenCV will likely not be used.
|
||||
*/
|
||||
ImagePacket::ImagePacket(const uchar *image, const int begin) {
|
||||
const uchar *target = &image[begin];
|
||||
// TODO: handle out of index cases, pad with zeroes. probably also instantiate our byte array with zeroes
|
||||
for (int i = 0; i < PACKET_SIZE; i++) {
|
||||
slice[i] = target[begin + i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Apply the packet to an OpenCV Mat.
|
||||
*/
|
||||
int ImagePacket::apply(const cv::Mat *image) const {
|
||||
uchar *target = &image->data[begin];
|
||||
// TODO: handle out of index cases
|
||||
for (int i = 0; i < PACKET_SIZE; i++) {
|
||||
target[begin + i] = slice[i];
|
||||
}
|
||||
// TODO: return the actual written size of the packet
|
||||
return PACKET_SIZE;
|
||||
}
|
18
packets/ImagePacket.h
Normal file
18
packets/ImagePacket.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef IMAGEPACKET_H
|
||||
#define IMAGEPACKET_H
|
||||
#include <opencv2/core/mat.hpp>
|
||||
|
||||
#define PACKET_SIZE 768
|
||||
|
||||
class ImagePacket {
|
||||
public:
|
||||
ImagePacket(const cv::Mat *image, int begin);
|
||||
ImagePacket(const uchar *image, int begin);
|
||||
int apply(const cv::Mat *image) const;
|
||||
|
||||
private:
|
||||
int begin;
|
||||
uchar slice[PACKET_SIZE];
|
||||
};
|
||||
|
||||
#endif //IMAGEPACKET_H
|
Reference in New Issue
Block a user