Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/awt/splashscreen/splashscreen_jpeg.c
38918 views
1
/*
2
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#include "splashscreen_impl.h"
27
28
#include "jinclude.h"
29
#include "jpeglib.h"
30
#include "jerror.h"
31
32
#include <setjmp.h>
33
34
#ifdef __APPLE__
35
/* use setjmp/longjmp versions that do not save/restore the signal mask */
36
#define setjmp _setjmp
37
#define longjmp _longjmp
38
#endif
39
40
/* stream input handling */
41
42
typedef struct
43
{
44
struct jpeg_source_mgr pub; /* public fields */
45
SplashStream * stream; /* source stream */
46
JOCTET *buffer; /* start of buffer */
47
boolean start_of_file; /* have we gotten any data yet? */
48
} stream_source_mgr;
49
50
typedef stream_source_mgr *stream_src_ptr;
51
52
#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
53
54
METHODDEF(void)
55
stream_init_source(j_decompress_ptr cinfo)
56
{
57
stream_src_ptr src = (stream_src_ptr) cinfo->src;
58
59
src->start_of_file = TRUE;
60
}
61
62
METHODDEF(boolean)
63
stream_fill_input_buffer(j_decompress_ptr cinfo)
64
{
65
stream_src_ptr src = (stream_src_ptr) cinfo->src;
66
size_t nbytes;
67
68
69
nbytes = src->stream->read(src->stream, src->buffer, INPUT_BUF_SIZE);
70
71
if (nbytes <= 0) {
72
if (src->start_of_file) /* Treat empty input file as fatal error */
73
ERREXIT(cinfo, JERR_INPUT_EMPTY);
74
WARNMS(cinfo, JWRN_JPEG_EOF);
75
/* Insert a fake EOI marker */
76
src->buffer[0] = (JOCTET) 0xFF;
77
src->buffer[1] = (JOCTET) JPEG_EOI;
78
nbytes = 2;
79
}
80
81
src->pub.next_input_byte = src->buffer;
82
src->pub.bytes_in_buffer = nbytes;
83
src->start_of_file = FALSE;
84
85
return TRUE;
86
}
87
88
METHODDEF(void)
89
stream_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
90
{
91
stream_src_ptr src = (stream_src_ptr) cinfo->src;
92
93
if (num_bytes > 0) {
94
while (num_bytes > (long) src->pub.bytes_in_buffer) {
95
num_bytes -= (long) src->pub.bytes_in_buffer;
96
(void) stream_fill_input_buffer(cinfo);
97
}
98
src->pub.next_input_byte += (size_t) num_bytes;
99
src->pub.bytes_in_buffer -= (size_t) num_bytes;
100
}
101
}
102
103
METHODDEF(void)
104
stream_term_source(j_decompress_ptr cinfo)
105
{
106
}
107
108
static void
109
set_stream_src(j_decompress_ptr cinfo, SplashStream * stream)
110
{
111
stream_src_ptr src;
112
113
if (cinfo->src == NULL) { /* first time for this JPEG object? */
114
cinfo->src = (struct jpeg_source_mgr *)
115
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
116
JPOOL_PERMANENT, SIZEOF(stream_source_mgr));
117
src = (stream_src_ptr) cinfo->src;
118
src->buffer = (JOCTET *)
119
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
120
JPOOL_PERMANENT, INPUT_BUF_SIZE * SIZEOF(JOCTET));
121
}
122
123
src = (stream_src_ptr) cinfo->src;
124
src->pub.init_source = stream_init_source;
125
src->pub.fill_input_buffer = stream_fill_input_buffer;
126
src->pub.skip_input_data = stream_skip_input_data;
127
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
128
src->pub.term_source = stream_term_source;
129
src->stream = stream;
130
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
131
src->pub.next_input_byte = NULL; /* until buffer loaded */
132
}
133
134
int
135
SplashDecodeJpeg(Splash * splash, struct jpeg_decompress_struct *cinfo)
136
{
137
int rowStride, stride;
138
JSAMPARRAY buffer;
139
ImageFormat srcFormat;
140
141
jpeg_read_header(cinfo, TRUE);
142
143
// SplashScreen jpeg converter expects data in RGB format only
144
cinfo->out_color_space = JCS_RGB;
145
146
jpeg_start_decompress(cinfo);
147
148
SplashCleanup(splash);
149
150
splash->width = cinfo->output_width;
151
splash->height = cinfo->output_height;
152
153
if (!SAFE_TO_ALLOC(splash->imageFormat.depthBytes, splash->width)) {
154
return 0;
155
}
156
stride = splash->width * splash->imageFormat.depthBytes;
157
158
if (!SAFE_TO_ALLOC(stride, splash->height)) {
159
return 0;
160
}
161
if (!SAFE_TO_ALLOC(cinfo->output_width, cinfo->output_components)) {
162
return 0;
163
}
164
165
splash->frameCount = 1;
166
splash->frames = (SplashImage *) malloc(sizeof(SplashImage) *
167
splash->frameCount);
168
if (splash->frames == NULL) {
169
return 0;
170
}
171
memset(splash->frames, 0, sizeof(SplashImage) *
172
splash->frameCount);
173
174
splash->loopCount = 1;
175
splash->frames[0].delay = 0;
176
splash->frames[0].bitmapBits = malloc(stride * splash->height);
177
if (splash->frames[0].bitmapBits == NULL) {
178
free(splash->frames);
179
return 0;
180
}
181
182
rowStride = cinfo->output_width * cinfo->output_components;
183
184
buffer = (*cinfo->mem->alloc_sarray)
185
((j_common_ptr) cinfo, JPOOL_IMAGE, rowStride, 1);
186
if (buffer == NULL) {
187
free(splash->frames[0].bitmapBits);
188
free(splash->frames);
189
return 0;
190
}
191
192
initFormat(&srcFormat, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000);
193
srcFormat.byteOrder = BYTE_ORDER_LSBFIRST;
194
srcFormat.depthBytes = 3;
195
srcFormat.fixedBits = 0xFF000000;
196
197
splash->maskRequired = 0; // reset maskRequired as JPEG can't be transparent
198
199
while (cinfo->output_scanline < cinfo->output_height) {
200
rgbquad_t *out =
201
(rgbquad_t *) ((byte_t *) splash->frames[0].bitmapBits +
202
cinfo->output_scanline * stride);
203
204
jpeg_read_scanlines(cinfo, buffer, 1);
205
convertLine(buffer[0], sizeof(JSAMPLE) * 3, out,
206
splash->imageFormat.depthBytes, cinfo->output_width, &srcFormat,
207
&splash->imageFormat, CVT_COPY, NULL, 0, NULL,
208
cinfo->output_scanline, 0);
209
}
210
jpeg_finish_decompress(cinfo);
211
212
return 1;
213
}
214
215
struct my_error_mgr
216
{
217
struct jpeg_error_mgr pub; /* "public" fields */
218
jmp_buf setjmp_buffer; /* for return to caller */
219
};
220
221
typedef struct my_error_mgr *my_error_ptr;
222
223
static void
224
my_error_exit(j_common_ptr cinfo)
225
{
226
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
227
my_error_ptr myerr = (my_error_ptr) cinfo->err;
228
229
/* Always display the message. */
230
/* We could postpone this until after returning, if we chose. */
231
(*cinfo->err->output_message) (cinfo);
232
233
/* Return control to the setjmp point */
234
longjmp(myerr->setjmp_buffer, 1);
235
}
236
237
int
238
SplashDecodeJpegStream(Splash * splash, SplashStream * stream)
239
{
240
struct jpeg_decompress_struct cinfo;
241
int success = 0;
242
struct my_error_mgr jerr;
243
244
cinfo.err = jpeg_std_error(&jerr.pub);
245
jerr.pub.error_exit = my_error_exit;
246
247
if (setjmp(jerr.setjmp_buffer)) {
248
goto done;
249
}
250
jpeg_create_decompress(&cinfo);
251
set_stream_src(&cinfo, stream);
252
success = SplashDecodeJpeg(splash, &cinfo);
253
254
done:
255
jpeg_destroy_decompress(&cinfo);
256
return success;
257
}
258
259