-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathSkImageEncoder_libtijpeg.h
136 lines (121 loc) · 4.41 KB
/
SkImageEncoder_libtijpeg.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright (C) Texas Instruments - http://www.ti.com/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* ==============================================================================
* Texas Instruments OMAP (TM) Platform Software
* (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
*
* Use of this software is controlled by the terms and conditions found
* in the license agreement under which this software has been supplied.
* ============================================================================ */
#ifndef SKIAHW_ENCODER_H
#define SKIAHW_ENCODER_H
#include <string.h>
#include <time.h>
#include "SkBitmap.h"
#include "SkStream.h"
#include "SkImageEncoder.h"
#include "SkImageUtility.h"
#include <stdio.h>
#include <semaphore.h>
#include <utils/threads.h>
extern "C" {
#include "OMX_Component.h"
#include "OMX_IVCommon.h"
}
#define OPTIMIZE 1
#define WVGA_RESOLUTION (854*480)
class SkJPEGImageEncoder : public SkImageEncoder {
protected:
virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality);
};
class SkTIJPEGImageEncoder
{
public:
enum JPEGENC_State
{
STATE_LOADED,
STATE_IDLE,
STATE_EXECUTING,
STATE_FILL_BUFFER_DONE_CALLED,
STATE_EMPTY_BUFFER_DONE_CALLED,
STATE_ERROR,
STATE_EXIT
};
typedef struct JpegEncoderParams
{
//nWidth;
//nHeight;
//nQuality;
//nComment;
//nThumbnailWidth;
//nThumbnailHeight;
//APP0
//APP1
//APP13
//CustomQuantizationTable
//CustomHuffmanTable
//nCropWidth
//nCropHeight
} JpegEncoderParams;
sem_t *semaphore;
JPEGENC_State iState;
JPEGENC_State iLastState;
int jpegSize;
SkTIJPEGImageEncoder();
void _SkTIJPEGImageEncoder();
~SkTIJPEGImageEncoder();
bool onEncode(SkImageEncoder* enc_impl, SkWStream* stream, const SkBitmap& bm, int quality);
bool encodeImage(int outBuffSize, void *inputBuffer, int inBuffSize, int width, int height, int quality, SkBitmap::Config config);
bool SetJpegEncodeParameters(JpegEncoderParams * jep) { memcpy(&jpegEncParams, jep, sizeof(JpegEncoderParams)); return true; }
void Run();
void PrintState();
void FillBufferDone(OMX_U8* pBuffer, OMX_U32 size);
void EventHandler(OMX_HANDLETYPE hComponent,
OMX_EVENTTYPE eEvent,
OMX_U32 nData1,
OMX_U32 nData2,
OMX_PTR pEventData);
int GetLoad(){ return mLoad; }
void IncDeleteAttempts() { mDeleteAttempts++; }
void ResetDeleteAttempts() { mDeleteAttempts = 0; }
int GetDeleteAttempts() { return mDeleteAttempts; }
private:
OMX_HANDLETYPE pOMXHandle;
OMX_BUFFERHEADERTYPE *pInBuffHead;
OMX_BUFFERHEADERTYPE *pOutBuffHead;
OMX_PARAM_PORTDEFINITIONTYPE InPortDef;
OMX_PARAM_PORTDEFINITIONTYPE OutPortDef;
JpegEncoderParams jpegEncParams;
OMX_U8* pEncodedOutputBuffer;
OMX_U32 nEncodedOutputFilledLen;
android::Mutex gTIJpegEncMutex;
int mLoad;
int mDeleteAttempts;
bool onEncodeSW(SkWStream* stream, const SkBitmap& bm, int quality);
};
OMX_ERRORTYPE OMX_JPEGE_FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffHead);
OMX_ERRORTYPE OMX_JPEGE_EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer);
OMX_ERRORTYPE OMX_JPEGE_EventHandler(OMX_HANDLETYPE hComponent,
OMX_PTR pAppData,
OMX_EVENTTYPE eEvent,
OMX_U32 nData1,
OMX_U32 nData2,
OMX_PTR pEventData);
#endif