1 #include <string.h>//memset/memcpy
2 #include "utils/DataGenerator.h"
3 #include "utils/BufferedData.h"
4 #include "utils/FileInputStream.h"
5
6 using namespace std;
7
8
YUVPixelDataGenerator(uint8_t * pPointer,int32_t iWidth,int32_t iHeight,int32_t iStride)9 bool YUVPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride) {
10 #define SRC_FRAME_WIDTH (160)
11 #define SRC_FRAME_HEIGHT (96)
12
13 if (SRC_FRAME_WIDTH - iWidth <= 0 || SRC_FRAME_HEIGHT - iHeight <= 0) {
14 return false;
15 }
16
17 const int32_t kiFrameSize = SRC_FRAME_WIDTH * SRC_FRAME_HEIGHT;
18 BufferedData sBuf;
19 sBuf.SetLength (kiFrameSize);
20 if (sBuf.Length() != (size_t)kiFrameSize) { //include memory fail (-1) case
21 return false;
22 }
23
24 FileInputStream fileStream;
25 #if defined(ANDROID_NDK)
26 if (!fileStream.Open ("/sdcard/res/CiscoVT2people_160x96_6fps.yuv")) {
27 #else
28 if (!fileStream.Open ("res/CiscoVT2people_160x96_6fps.yuv")) {
29 #endif
30 return false;
31 }
32 if (fileStream.read (sBuf.data(), kiFrameSize) == kiFrameSize) {
33 int32_t iStartPosX = rand() % (SRC_FRAME_WIDTH - iWidth);
34 int32_t iStartPosY = rand() % (SRC_FRAME_HEIGHT - iHeight);
35 uint8_t* pSrcPointer = sBuf.data() + iStartPosX + iStartPosY * SRC_FRAME_WIDTH;
36 uint8_t* pLocalPointer = pPointer;
37
38 for (int j = 0; j < iHeight; j++) {
39 memcpy (pLocalPointer, pSrcPointer, iWidth * sizeof (uint8_t));
40 pLocalPointer += iStride;
41 pSrcPointer += SRC_FRAME_WIDTH;
42 }
43 return true;
44 }
45 return false;
46 }
47
48 void RandomPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride) {
49 uint8_t* pLocalPointer = pPointer;
50 for (int32_t j = 0; j < iHeight; j++) {
51 for (int32_t i = 0; i < iWidth; i++) {
52 pLocalPointer[i] = rand() % 256;
53 }
54 pLocalPointer += iStride;
55 }
56 }
57
58
59 void RandomResidueDataGenerator (uint16_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride) {
60 }
61
62 void RandomCoeffDataGenerator (uint16_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride) {
63 }
64
65