-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImage.h
More file actions
105 lines (88 loc) · 1.87 KB
/
Copy pathImage.h
File metadata and controls
105 lines (88 loc) · 1.87 KB
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
#ifndef __IMAGE_SL
#define __IMAGE_SL
/***************************************************************************
*
* Project libmjpeg
*
* Copyright (C) 2014-2015, Changer, <dingjinchengyx@163.com>.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "slconfig.h"
#include <stdio.h>
#include "stringc.h"
enum IMAGE_TYPE {
IMAGE_UNKNOW = 0,
IMAGE_JPEG,
IMAGE_BMP,
IMAGE_RGB,
IMAGE_ARGB,
IMAGE_YUV422
};
class Image {
public:
Image() {
buf = NULL;
image_length = 0;
type = IMAGE_UNKNOW;
width = 0;
height = 0;
}
virtual ~Image() {
if(buf)
delete[] buf;
}
void fillImage(u8* data,int len,IMAGE_TYPE t) {
if(buf != 0)
delete buf;
buf = new u8[len];
memcpy(buf,data,len);
image_length = len;
type = t;
}
void writeToFile(const char* path,const char* name) {
stringc location = path;
stringc filename;
if(path == NULL)
return;
if(name == NULL) {
formatRandomString(filename);
} else {
filename = name;
}
location.append("/");
location.append(filename);
switch(type) {
case IMAGE_JPEG:
{
if(name == NULL) {
location.append(".jpg");
FILE* pic = fopen(location.c_str(),"wb");
fwrite(buf,image_length,1,pic);
fflush(pic);
fclose(pic);
}
break;
}
default:
break;
}
}
public:
u8* buf;
int image_length;
IMAGE_TYPE type;
int width;
int height;
int depth;
};
#endif