| 1 |
/* |
| 2 |
* Copyright 2009 Pierre Ossman <[email protected]> for Cendio AB |
| 3 |
* Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
* Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2022, 2024-2025, |
| 5 |
* D. R. Commander. |
| 6 |
* Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois. |
| 7 |
* Copyright (C) 2019, Google LLC. |
| 8 |
* Copyright (C) 2020, Arm Limited. |
| 9 |
* |
| 10 |
* Based on the x86 SIMD extension for IJG JPEG library, |
| 11 |
* Copyright (C) 1999-2006, MIYASAKA Masaru. |
| 12 |
* For conditions of distribution and use, see copyright notice in jsimdext.inc |
| 13 |
* |
| 14 |
* This file contains the interface between the "normal" portions |
| 15 |
* of the library and the SIMD implementations when running on a |
| 16 |
* 32-bit Arm architecture. |
| 17 |
*/ |
| 18 |
|
| 19 |
#define JPEG_INTERNALS |
| 20 |
#include "../../../src/jinclude.h" |
| 21 |
#include "../../../src/jpeglib.h" |
| 22 |
#include "../../../src/jsimd.h" |
| 23 |
#include "../../../src/jdct.h" |
| 24 |
#include "../../../src/jsimddct.h" |
| 25 |
#include "../../jsimd.h" |
| 26 |
|
| 27 |
#include <ctype.h> |
| 28 |
|
| 29 |
static THREAD_LOCAL unsigned int simd_support = ~0; |
| 30 |
static THREAD_LOCAL unsigned int simd_huffman = 1; |
| 31 |
|
| 32 |
#if !defined(__ARM_NEON__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)) |
| 33 |
|
| 34 |
#define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024) |
| 35 |
|
| 36 |
LOCAL(int) |
| 37 |
check_feature(char *buffer, char *feature) |
| 38 |
{ |
| 39 |
char *p; |
| 40 |
|
| 41 |
if (*feature == 0) |
| 42 |
return 0; |
| 43 |
if (strncmp(buffer, "Features", 8) != 0) |
| 44 |
return 0; |
| 45 |
buffer += 8; |
| 46 |
while (isspace(*buffer)) |
| 47 |
buffer++; |
| 48 |
|
| 49 |
/* Check if 'feature' is present in the buffer as a separate word */ |
| 50 |
while ((p = strstr(buffer, feature))) { |
| 51 |
if (p > buffer && !isspace(*(p - 1))) { |
| 52 |
buffer++; |
| 53 |
continue; |
| 54 |
} |
| 55 |
p += strlen(feature); |
| 56 |
if (*p != 0 && !isspace(*p)) { |
| 57 |
buffer++; |
| 58 |
continue; |
| 59 |
} |
| 60 |
return 1; |
| 61 |
} |
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
LOCAL(int) |
| 66 |
parse_proc_cpuinfo(int bufsize) |
| 67 |
{ |
| 68 |
char *buffer = (char *)malloc(bufsize); |
| 69 |
FILE *fd; |
| 70 |
|
| 71 |
simd_support = 0; |
| 72 |
|
| 73 |
if (!buffer) |
| 74 |
return 0; |
| 75 |
|
| 76 |
fd = fopen("/proc/cpuinfo", "r"); |
| 77 |
if (fd) { |
| 78 |
while (fgets(buffer, bufsize, fd)) { |
| 79 |
if (!strchr(buffer, '\n') && !feof(fd)) { |
| 80 |
/* "impossible" happened - insufficient size of the buffer! */ |
| 81 |
fclose(fd); |
| 82 |
free(buffer); |
| 83 |
return 0; |
| 84 |
} |
| 85 |
if (check_feature(buffer, "neon")) |
| 86 |
simd_support |= JSIMD_NEON; |
| 87 |
} |
| 88 |
fclose(fd); |
| 89 |
} |
| 90 |
free(buffer); |
| 91 |
return 1; |
| 92 |
} |
| 93 |
|
| 94 |
#endif |
| 95 |
|
| 96 |
/* |
| 97 |
* Check what SIMD accelerations are supported. |
| 98 |
*/ |
| 99 |
LOCAL(void) |
| 100 |
init_simd(void) |
| 101 |
{ |
| 102 |
#ifndef NO_GETENV |
| 103 |
char env[2] = { 0 }; |
| 104 |
#endif |
| 105 |
#if !defined(__ARM_NEON__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)) |
| 106 |
int bufsize = 1024; /* an initial guess for the line buffer size limit */ |
| 107 |
#endif |
| 108 |
|
| 109 |
if (simd_support != ~0U) |
| 110 |
return; |
| 111 |
|
| 112 |
simd_support = 0; |
| 113 |
|
| 114 |
#if defined(__ARM_NEON__) |
| 115 |
simd_support |= JSIMD_NEON; |
| 116 |
#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) |
| 117 |
/* We still have a chance to use Neon regardless of globally used |
| 118 |
* -mcpu/-mfpu options passed to gcc by performing runtime detection via |
| 119 |
* /proc/cpuinfo parsing on linux/android */ |
| 120 |
while (!parse_proc_cpuinfo(bufsize)) { |
| 121 |
bufsize *= 2; |
| 122 |
if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT) |
| 123 |
break; |
| 124 |
} |
| 125 |
#endif |
| 126 |
|
| 127 |
#ifndef NO_GETENV |
| 128 |
/* Force different settings through environment variables */ |
| 129 |
if (!GETENV_S(env, 2, "JSIMD_FORCENEON") && !strcmp(env, "1")) |
| 130 |
simd_support = JSIMD_NEON; |
| 131 |
if (!GETENV_S(env, 2, "JSIMD_FORCENONE") && !strcmp(env, "1")) |
| 132 |
simd_support = 0; |
| 133 |
if (!GETENV_S(env, 2, "JSIMD_NOHUFFENC") && !strcmp(env, "1")) |
| 134 |
simd_huffman = 0; |
| 135 |
#endif |
| 136 |
} |
| 137 |
|
| 138 |
GLOBAL(int) |
| 139 |
jsimd_can_rgb_ycc(void) |
| 140 |
{ |
| 141 |
init_simd(); |
| 142 |
|
| 143 |
/* The code is optimised for these values only */ |
| 144 |
if (BITS_IN_JSAMPLE != 8) |
| 145 |
return 0; |
| 146 |
if (sizeof(JDIMENSION) != 4) |
| 147 |
return 0; |
| 148 |
if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) |
| 149 |
return 0; |
| 150 |
|
| 151 |
if (simd_support & JSIMD_NEON) |
| 152 |
return 1; |
| 153 |
|
| 154 |
return 0; |
| 155 |
} |
| 156 |
|
| 157 |
GLOBAL(int) |
| 158 |
jsimd_can_rgb_gray(void) |
| 159 |
{ |
| 160 |
init_simd(); |
| 161 |
|
| 162 |
/* The code is optimised for these values only */ |
| 163 |
if (BITS_IN_JSAMPLE != 8) |
| 164 |
return 0; |
| 165 |
if (sizeof(JDIMENSION) != 4) |
| 166 |
return 0; |
| 167 |
if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) |
| 168 |
return 0; |
| 169 |
|
| 170 |
if (simd_support & JSIMD_NEON) |
| 171 |
return 1; |
| 172 |
|
| 173 |
return 0; |
| 174 |
} |
| 175 |
|
| 176 |
GLOBAL(int) |
| 177 |
jsimd_can_ycc_rgb(void) |
| 178 |
{ |
| 179 |
init_simd(); |
| 180 |
|
| 181 |
/* The code is optimised for these values only */ |
| 182 |
if (BITS_IN_JSAMPLE != 8) |
| 183 |
return 0; |
| 184 |
if (sizeof(JDIMENSION) != 4) |
| 185 |
return 0; |
| 186 |
if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) |
| 187 |
return 0; |
| 188 |
|
| 189 |
if (simd_support & JSIMD_NEON) |
| 190 |
return 1; |
| 191 |
|
| 192 |
return 0; |
| 193 |
} |
| 194 |
|
| 195 |
GLOBAL(int) |
| 196 |
jsimd_can_ycc_rgb565(void) |
| 197 |
{ |
| 198 |
init_simd(); |
| 199 |
|
| 200 |
/* The code is optimised for these values only */ |
| 201 |
if (BITS_IN_JSAMPLE != 8) |
| 202 |
return 0; |
| 203 |
if (sizeof(JDIMENSION) != 4) |
| 204 |
return 0; |
| 205 |
|
| 206 |
if (simd_support & JSIMD_NEON) |
| 207 |
return 1; |
| 208 |
|
| 209 |
return 0; |
| 210 |
} |
| 211 |
|
| 212 |
GLOBAL(void) |
| 213 |
jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, |
| 214 |
JSAMPIMAGE output_buf, JDIMENSION output_row, |
| 215 |
int num_rows) |
| 216 |
{ |
| 217 |
void (*neonfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); |
| 218 |
|
| 219 |
switch (cinfo->in_color_space) { |
| 220 |
case JCS_EXT_RGB: |
| 221 |
neonfct = jsimd_extrgb_ycc_convert_neon; |
| 222 |
break; |
| 223 |
case JCS_EXT_RGBX: |
| 224 |
case JCS_EXT_RGBA: |
| 225 |
neonfct = jsimd_extrgbx_ycc_convert_neon; |
| 226 |
break; |
| 227 |
case JCS_EXT_BGR: |
| 228 |
neonfct = jsimd_extbgr_ycc_convert_neon; |
| 229 |
break; |
| 230 |
case JCS_EXT_BGRX: |
| 231 |
case JCS_EXT_BGRA: |
| 232 |
neonfct = jsimd_extbgrx_ycc_convert_neon; |
| 233 |
break; |
| 234 |
case JCS_EXT_XBGR: |
| 235 |
case JCS_EXT_ABGR: |
| 236 |
neonfct = jsimd_extxbgr_ycc_convert_neon; |
| 237 |
break; |
| 238 |
case JCS_EXT_XRGB: |
| 239 |
case JCS_EXT_ARGB: |
| 240 |
neonfct = jsimd_extxrgb_ycc_convert_neon; |
| 241 |
break; |
| 242 |
default: |
| 243 |
neonfct = jsimd_extrgb_ycc_convert_neon; |
| 244 |
break; |
| 245 |
} |
| 246 |
|
| 247 |
neonfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows); |
| 248 |
} |
| 249 |
|
| 250 |
GLOBAL(void) |
| 251 |
jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, |
| 252 |
JSAMPIMAGE output_buf, JDIMENSION output_row, |
| 253 |
int num_rows) |
| 254 |
{ |
| 255 |
void (*neonfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); |
| 256 |
|
| 257 |
switch (cinfo->in_color_space) { |
| 258 |
case JCS_EXT_RGB: |
| 259 |
neonfct = jsimd_extrgb_gray_convert_neon; |
| 260 |
break; |
| 261 |
case JCS_EXT_RGBX: |
| 262 |
case JCS_EXT_RGBA: |
| 263 |
neonfct = jsimd_extrgbx_gray_convert_neon; |
| 264 |
break; |
| 265 |
case JCS_EXT_BGR: |
| 266 |
neonfct = jsimd_extbgr_gray_convert_neon; |
| 267 |
break; |
| 268 |
case JCS_EXT_BGRX: |
| 269 |
case JCS_EXT_BGRA: |
| 270 |
neonfct = jsimd_extbgrx_gray_convert_neon; |
| 271 |
break; |
| 272 |
case JCS_EXT_XBGR: |
| 273 |
case JCS_EXT_ABGR: |
| 274 |
neonfct = jsimd_extxbgr_gray_convert_neon; |
| 275 |
break; |
| 276 |
case JCS_EXT_XRGB: |
| 277 |
case JCS_EXT_ARGB: |
| 278 |
neonfct = jsimd_extxrgb_gray_convert_neon; |
| 279 |
break; |
| 280 |
default: |
| 281 |
neonfct = jsimd_extrgb_gray_convert_neon; |
| 282 |
break; |
| 283 |
} |
| 284 |
|
| 285 |
neonfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows); |
| 286 |
} |
| 287 |
|
| 288 |
GLOBAL(void) |
| 289 |
jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, |
| 290 |
JDIMENSION input_row, JSAMPARRAY output_buf, |
| 291 |
int num_rows) |
| 292 |
{ |
| 293 |
void (*neonfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int); |
| 294 |
|
| 295 |
switch (cinfo->out_color_space) { |
| 296 |
case JCS_EXT_RGB: |
| 297 |
neonfct = jsimd_ycc_extrgb_convert_neon; |
| 298 |
break; |
| 299 |
case JCS_EXT_RGBX: |
| 300 |
case JCS_EXT_RGBA: |
| 301 |
neonfct = jsimd_ycc_extrgbx_convert_neon; |
| 302 |
break; |
| 303 |
case JCS_EXT_BGR: |
| 304 |
neonfct = jsimd_ycc_extbgr_convert_neon; |
| 305 |
break; |
| 306 |
case JCS_EXT_BGRX: |
| 307 |
case JCS_EXT_BGRA: |
| 308 |
neonfct = jsimd_ycc_extbgrx_convert_neon; |
| 309 |
break; |
| 310 |
case JCS_EXT_XBGR: |
| 311 |
case JCS_EXT_ABGR: |
| 312 |
neonfct = jsimd_ycc_extxbgr_convert_neon; |
| 313 |
break; |
| 314 |
case JCS_EXT_XRGB: |
| 315 |
case JCS_EXT_ARGB: |
| 316 |
neonfct = jsimd_ycc_extxrgb_convert_neon; |
| 317 |
break; |
| 318 |
default: |
| 319 |
neonfct = jsimd_ycc_extrgb_convert_neon; |
| 320 |
break; |
| 321 |
} |
| 322 |
|
| 323 |
neonfct(cinfo->output_width, input_buf, input_row, output_buf, num_rows); |
| 324 |
} |
| 325 |
|
| 326 |
GLOBAL(void) |
| 327 |
jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, |
| 328 |
JDIMENSION input_row, JSAMPARRAY output_buf, |
| 329 |
int num_rows) |
| 330 |
{ |
| 331 |
jsimd_ycc_rgb565_convert_neon(cinfo->output_width, input_buf, input_row, |
| 332 |
output_buf, num_rows); |
| 333 |
} |
| 334 |
|
| 335 |
GLOBAL(int) |
| 336 |
jsimd_can_h2v2_downsample(void) |
| 337 |
{ |
| 338 |
init_simd(); |
| 339 |
|
| 340 |
/* The code is optimised for these values only */ |
| 341 |
if (BITS_IN_JSAMPLE != 8) |
| 342 |
return 0; |
| 343 |
if (DCTSIZE != 8) |
| 344 |
return 0; |
| 345 |
if (sizeof(JDIMENSION) != 4) |
| 346 |
return 0; |
| 347 |
|
| 348 |
if (simd_support & JSIMD_NEON) |
| 349 |
return 1; |
| 350 |
|
| 351 |
return 0; |
| 352 |
} |
| 353 |
|
| 354 |
GLOBAL(int) |
| 355 |
jsimd_can_h2v1_downsample(void) |
| 356 |
{ |
| 357 |
init_simd(); |
| 358 |
|
| 359 |
/* The code is optimised for these values only */ |
| 360 |
if (BITS_IN_JSAMPLE != 8) |
| 361 |
return 0; |
| 362 |
if (DCTSIZE != 8) |
| 363 |
return 0; |
| 364 |
if (sizeof(JDIMENSION) != 4) |
| 365 |
return 0; |
| 366 |
|
| 367 |
if (simd_support & JSIMD_NEON) |
| 368 |
return 1; |
| 369 |
|
| 370 |
return 0; |
| 371 |
} |
| 372 |
|
| 373 |
GLOBAL(void) |
| 374 |
jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
| 375 |
JSAMPARRAY input_data, JSAMPARRAY output_data) |
| 376 |
{ |
| 377 |
jsimd_h2v2_downsample_neon(cinfo->image_width, cinfo->max_v_samp_factor, |
| 378 |
compptr->v_samp_factor, compptr->width_in_blocks, |
| 379 |
input_data, output_data); |
| 380 |
} |
| 381 |
|
| 382 |
GLOBAL(void) |
| 383 |
jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
| 384 |
JSAMPARRAY input_data, JSAMPARRAY output_data) |
| 385 |
{ |
| 386 |
jsimd_h2v1_downsample_neon(cinfo->image_width, cinfo->max_v_samp_factor, |
| 387 |
compptr->v_samp_factor, compptr->width_in_blocks, |
| 388 |
input_data, output_data); |
| 389 |
} |
| 390 |
|
| 391 |
GLOBAL(int) |
| 392 |
jsimd_can_h2v2_upsample(void) |
| 393 |
{ |
| 394 |
init_simd(); |
| 395 |
|
| 396 |
/* The code is optimised for these values only */ |
| 397 |
if (BITS_IN_JSAMPLE != 8) |
| 398 |
return 0; |
| 399 |
if (sizeof(JDIMENSION) != 4) |
| 400 |
return 0; |
| 401 |
|
| 402 |
if (simd_support & JSIMD_NEON) |
| 403 |
return 1; |
| 404 |
|
| 405 |
return 0; |
| 406 |
} |
| 407 |
|
| 408 |
GLOBAL(int) |
| 409 |
jsimd_can_h2v1_upsample(void) |
| 410 |
{ |
| 411 |
init_simd(); |
| 412 |
|
| 413 |
/* The code is optimised for these values only */ |
| 414 |
if (BITS_IN_JSAMPLE != 8) |
| 415 |
return 0; |
| 416 |
if (sizeof(JDIMENSION) != 4) |
| 417 |
return 0; |
| 418 |
if (simd_support & JSIMD_NEON) |
| 419 |
return 1; |
| 420 |
|
| 421 |
return 0; |
| 422 |
} |
| 423 |
|
| 424 |
GLOBAL(void) |
| 425 |
jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 426 |
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) |
| 427 |
{ |
| 428 |
jsimd_h2v2_upsample_neon(cinfo->max_v_samp_factor, cinfo->output_width, |
| 429 |
input_data, output_data_ptr); |
| 430 |
} |
| 431 |
|
| 432 |
GLOBAL(void) |
| 433 |
jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 434 |
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) |
| 435 |
{ |
| 436 |
jsimd_h2v1_upsample_neon(cinfo->max_v_samp_factor, cinfo->output_width, |
| 437 |
input_data, output_data_ptr); |
| 438 |
} |
| 439 |
|
| 440 |
GLOBAL(int) |
| 441 |
jsimd_can_h2v2_fancy_upsample(void) |
| 442 |
{ |
| 443 |
init_simd(); |
| 444 |
|
| 445 |
/* The code is optimised for these values only */ |
| 446 |
if (BITS_IN_JSAMPLE != 8) |
| 447 |
return 0; |
| 448 |
if (sizeof(JDIMENSION) != 4) |
| 449 |
return 0; |
| 450 |
|
| 451 |
if (simd_support & JSIMD_NEON) |
| 452 |
return 1; |
| 453 |
|
| 454 |
return 0; |
| 455 |
} |
| 456 |
|
| 457 |
GLOBAL(int) |
| 458 |
jsimd_can_h2v1_fancy_upsample(void) |
| 459 |
{ |
| 460 |
init_simd(); |
| 461 |
|
| 462 |
/* The code is optimised for these values only */ |
| 463 |
if (BITS_IN_JSAMPLE != 8) |
| 464 |
return 0; |
| 465 |
if (sizeof(JDIMENSION) != 4) |
| 466 |
return 0; |
| 467 |
|
| 468 |
if (simd_support & JSIMD_NEON) |
| 469 |
return 1; |
| 470 |
|
| 471 |
return 0; |
| 472 |
} |
| 473 |
|
| 474 |
GLOBAL(int) |
| 475 |
jsimd_can_h1v2_fancy_upsample(void) |
| 476 |
{ |
| 477 |
init_simd(); |
| 478 |
|
| 479 |
/* The code is optimised for these values only */ |
| 480 |
if (BITS_IN_JSAMPLE != 8) |
| 481 |
return 0; |
| 482 |
if (sizeof(JDIMENSION) != 4) |
| 483 |
return 0; |
| 484 |
|
| 485 |
if (simd_support & JSIMD_NEON) |
| 486 |
return 1; |
| 487 |
|
| 488 |
return 0; |
| 489 |
} |
| 490 |
|
| 491 |
GLOBAL(void) |
| 492 |
jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 493 |
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) |
| 494 |
{ |
| 495 |
jsimd_h2v2_fancy_upsample_neon(cinfo->max_v_samp_factor, |
| 496 |
compptr->downsampled_width, input_data, |
| 497 |
output_data_ptr); |
| 498 |
} |
| 499 |
|
| 500 |
GLOBAL(void) |
| 501 |
jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 502 |
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) |
| 503 |
{ |
| 504 |
jsimd_h2v1_fancy_upsample_neon(cinfo->max_v_samp_factor, |
| 505 |
compptr->downsampled_width, input_data, |
| 506 |
output_data_ptr); |
| 507 |
} |
| 508 |
|
| 509 |
GLOBAL(void) |
| 510 |
jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 511 |
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) |
| 512 |
{ |
| 513 |
jsimd_h1v2_fancy_upsample_neon(cinfo->max_v_samp_factor, |
| 514 |
compptr->downsampled_width, input_data, |
| 515 |
output_data_ptr); |
| 516 |
} |
| 517 |
|
| 518 |
GLOBAL(int) |
| 519 |
jsimd_can_h2v2_merged_upsample(void) |
| 520 |
{ |
| 521 |
init_simd(); |
| 522 |
|
| 523 |
/* The code is optimised for these values only */ |
| 524 |
if (BITS_IN_JSAMPLE != 8) |
| 525 |
return 0; |
| 526 |
if (sizeof(JDIMENSION) != 4) |
| 527 |
return 0; |
| 528 |
|
| 529 |
if (simd_support & JSIMD_NEON) |
| 530 |
return 1; |
| 531 |
|
| 532 |
return 0; |
| 533 |
} |
| 534 |
|
| 535 |
GLOBAL(int) |
| 536 |
jsimd_can_h2v1_merged_upsample(void) |
| 537 |
{ |
| 538 |
init_simd(); |
| 539 |
|
| 540 |
/* The code is optimised for these values only */ |
| 541 |
if (BITS_IN_JSAMPLE != 8) |
| 542 |
return 0; |
| 543 |
if (sizeof(JDIMENSION) != 4) |
| 544 |
return 0; |
| 545 |
|
| 546 |
if (simd_support & JSIMD_NEON) |
| 547 |
return 1; |
| 548 |
|
| 549 |
return 0; |
| 550 |
} |
| 551 |
|
| 552 |
GLOBAL(void) |
| 553 |
jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, |
| 554 |
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf) |
| 555 |
{ |
| 556 |
void (*neonfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); |
| 557 |
|
| 558 |
switch (cinfo->out_color_space) { |
| 559 |
case JCS_EXT_RGB: |
| 560 |
neonfct = jsimd_h2v2_extrgb_merged_upsample_neon; |
| 561 |
break; |
| 562 |
case JCS_EXT_RGBX: |
| 563 |
case JCS_EXT_RGBA: |
| 564 |
neonfct = jsimd_h2v2_extrgbx_merged_upsample_neon; |
| 565 |
break; |
| 566 |
case JCS_EXT_BGR: |
| 567 |
neonfct = jsimd_h2v2_extbgr_merged_upsample_neon; |
| 568 |
break; |
| 569 |
case JCS_EXT_BGRX: |
| 570 |
case JCS_EXT_BGRA: |
| 571 |
neonfct = jsimd_h2v2_extbgrx_merged_upsample_neon; |
| 572 |
break; |
| 573 |
case JCS_EXT_XBGR: |
| 574 |
case JCS_EXT_ABGR: |
| 575 |
neonfct = jsimd_h2v2_extxbgr_merged_upsample_neon; |
| 576 |
break; |
| 577 |
case JCS_EXT_XRGB: |
| 578 |
case JCS_EXT_ARGB: |
| 579 |
neonfct = jsimd_h2v2_extxrgb_merged_upsample_neon; |
| 580 |
break; |
| 581 |
default: |
| 582 |
neonfct = jsimd_h2v2_extrgb_merged_upsample_neon; |
| 583 |
break; |
| 584 |
} |
| 585 |
|
| 586 |
neonfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf); |
| 587 |
} |
| 588 |
|
| 589 |
GLOBAL(void) |
| 590 |
jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, |
| 591 |
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf) |
| 592 |
{ |
| 593 |
void (*neonfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); |
| 594 |
|
| 595 |
switch (cinfo->out_color_space) { |
| 596 |
case JCS_EXT_RGB: |
| 597 |
neonfct = jsimd_h2v1_extrgb_merged_upsample_neon; |
| 598 |
break; |
| 599 |
case JCS_EXT_RGBX: |
| 600 |
case JCS_EXT_RGBA: |
| 601 |
neonfct = jsimd_h2v1_extrgbx_merged_upsample_neon; |
| 602 |
break; |
| 603 |
case JCS_EXT_BGR: |
| 604 |
neonfct = jsimd_h2v1_extbgr_merged_upsample_neon; |
| 605 |
break; |
| 606 |
case JCS_EXT_BGRX: |
| 607 |
case JCS_EXT_BGRA: |
| 608 |
neonfct = jsimd_h2v1_extbgrx_merged_upsample_neon; |
| 609 |
break; |
| 610 |
case JCS_EXT_XBGR: |
| 611 |
case JCS_EXT_ABGR: |
| 612 |
neonfct = jsimd_h2v1_extxbgr_merged_upsample_neon; |
| 613 |
break; |
| 614 |
case JCS_EXT_XRGB: |
| 615 |
case JCS_EXT_ARGB: |
| 616 |
neonfct = jsimd_h2v1_extxrgb_merged_upsample_neon; |
| 617 |
break; |
| 618 |
default: |
| 619 |
neonfct = jsimd_h2v1_extrgb_merged_upsample_neon; |
| 620 |
break; |
| 621 |
} |
| 622 |
|
| 623 |
neonfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf); |
| 624 |
} |
| 625 |
|
| 626 |
GLOBAL(int) |
| 627 |
jsimd_can_convsamp(void) |
| 628 |
{ |
| 629 |
init_simd(); |
| 630 |
|
| 631 |
/* The code is optimised for these values only */ |
| 632 |
if (DCTSIZE != 8) |
| 633 |
return 0; |
| 634 |
if (BITS_IN_JSAMPLE != 8) |
| 635 |
return 0; |
| 636 |
if (sizeof(JDIMENSION) != 4) |
| 637 |
return 0; |
| 638 |
if (sizeof(DCTELEM) != 2) |
| 639 |
return 0; |
| 640 |
|
| 641 |
if (simd_support & JSIMD_NEON) |
| 642 |
return 1; |
| 643 |
|
| 644 |
return 0; |
| 645 |
} |
| 646 |
|
| 647 |
GLOBAL(int) |
| 648 |
jsimd_can_convsamp_float(void) |
| 649 |
{ |
| 650 |
return 0; |
| 651 |
} |
| 652 |
|
| 653 |
GLOBAL(void) |
| 654 |
jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col, |
| 655 |
DCTELEM *workspace) |
| 656 |
{ |
| 657 |
jsimd_convsamp_neon(sample_data, start_col, workspace); |
| 658 |
} |
| 659 |
|
| 660 |
GLOBAL(void) |
| 661 |
jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col, |
| 662 |
FAST_FLOAT *workspace) |
| 663 |
{ |
| 664 |
} |
| 665 |
|
| 666 |
GLOBAL(int) |
| 667 |
jsimd_can_fdct_islow(void) |
| 668 |
{ |
| 669 |
init_simd(); |
| 670 |
|
| 671 |
/* The code is optimised for these values only */ |
| 672 |
if (DCTSIZE != 8) |
| 673 |
return 0; |
| 674 |
if (sizeof(DCTELEM) != 2) |
| 675 |
return 0; |
| 676 |
|
| 677 |
if (simd_support & JSIMD_NEON) |
| 678 |
return 1; |
| 679 |
|
| 680 |
return 0; |
| 681 |
} |
| 682 |
|
| 683 |
GLOBAL(int) |
| 684 |
jsimd_can_fdct_ifast(void) |
| 685 |
{ |
| 686 |
init_simd(); |
| 687 |
|
| 688 |
/* The code is optimised for these values only */ |
| 689 |
if (DCTSIZE != 8) |
| 690 |
return 0; |
| 691 |
if (sizeof(DCTELEM) != 2) |
| 692 |
return 0; |
| 693 |
|
| 694 |
if (simd_support & JSIMD_NEON) |
| 695 |
return 1; |
| 696 |
|
| 697 |
return 0; |
| 698 |
} |
| 699 |
|
| 700 |
GLOBAL(int) |
| 701 |
jsimd_can_fdct_float(void) |
| 702 |
{ |
| 703 |
return 0; |
| 704 |
} |
| 705 |
|
| 706 |
GLOBAL(void) |
| 707 |
jsimd_fdct_islow(DCTELEM *data) |
| 708 |
{ |
| 709 |
jsimd_fdct_islow_neon(data); |
| 710 |
} |
| 711 |
|
| 712 |
GLOBAL(void) |
| 713 |
jsimd_fdct_ifast(DCTELEM *data) |
| 714 |
{ |
| 715 |
jsimd_fdct_ifast_neon(data); |
| 716 |
} |
| 717 |
|
| 718 |
GLOBAL(void) |
| 719 |
jsimd_fdct_float(FAST_FLOAT *data) |
| 720 |
{ |
| 721 |
} |
| 722 |
|
| 723 |
GLOBAL(int) |
| 724 |
jsimd_can_quantize(void) |
| 725 |
{ |
| 726 |
init_simd(); |
| 727 |
|
| 728 |
/* The code is optimised for these values only */ |
| 729 |
if (DCTSIZE != 8) |
| 730 |
return 0; |
| 731 |
if (sizeof(JCOEF) != 2) |
| 732 |
return 0; |
| 733 |
if (sizeof(DCTELEM) != 2) |
| 734 |
return 0; |
| 735 |
|
| 736 |
if (simd_support & JSIMD_NEON) |
| 737 |
return 1; |
| 738 |
|
| 739 |
return 0; |
| 740 |
} |
| 741 |
|
| 742 |
GLOBAL(int) |
| 743 |
jsimd_can_quantize_float(void) |
| 744 |
{ |
| 745 |
return 0; |
| 746 |
} |
| 747 |
|
| 748 |
GLOBAL(void) |
| 749 |
jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace) |
| 750 |
{ |
| 751 |
jsimd_quantize_neon(coef_block, divisors, workspace); |
| 752 |
} |
| 753 |
|
| 754 |
GLOBAL(void) |
| 755 |
jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors, |
| 756 |
FAST_FLOAT *workspace) |
| 757 |
{ |
| 758 |
} |
| 759 |
|
| 760 |
GLOBAL(int) |
| 761 |
jsimd_can_idct_2x2(void) |
| 762 |
{ |
| 763 |
init_simd(); |
| 764 |
|
| 765 |
/* The code is optimised for these values only */ |
| 766 |
if (DCTSIZE != 8) |
| 767 |
return 0; |
| 768 |
if (sizeof(JCOEF) != 2) |
| 769 |
return 0; |
| 770 |
if (BITS_IN_JSAMPLE != 8) |
| 771 |
return 0; |
| 772 |
if (sizeof(JDIMENSION) != 4) |
| 773 |
return 0; |
| 774 |
if (sizeof(ISLOW_MULT_TYPE) != 2) |
| 775 |
return 0; |
| 776 |
|
| 777 |
if (simd_support & JSIMD_NEON) |
| 778 |
return 1; |
| 779 |
|
| 780 |
return 0; |
| 781 |
} |
| 782 |
|
| 783 |
GLOBAL(int) |
| 784 |
jsimd_can_idct_4x4(void) |
| 785 |
{ |
| 786 |
init_simd(); |
| 787 |
|
| 788 |
/* The code is optimised for these values only */ |
| 789 |
if (DCTSIZE != 8) |
| 790 |
return 0; |
| 791 |
if (sizeof(JCOEF) != 2) |
| 792 |
return 0; |
| 793 |
if (BITS_IN_JSAMPLE != 8) |
| 794 |
return 0; |
| 795 |
if (sizeof(JDIMENSION) != 4) |
| 796 |
return 0; |
| 797 |
if (sizeof(ISLOW_MULT_TYPE) != 2) |
| 798 |
return 0; |
| 799 |
|
| 800 |
if (simd_support & JSIMD_NEON) |
| 801 |
return 1; |
| 802 |
|
| 803 |
return 0; |
| 804 |
} |
| 805 |
|
| 806 |
GLOBAL(void) |
| 807 |
jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 808 |
JCOEFPTR coef_block, JSAMPARRAY output_buf, |
| 809 |
JDIMENSION output_col) |
| 810 |
{ |
| 811 |
jsimd_idct_2x2_neon(compptr->dct_table, coef_block, output_buf, output_col); |
| 812 |
} |
| 813 |
|
| 814 |
GLOBAL(void) |
| 815 |
jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 816 |
JCOEFPTR coef_block, JSAMPARRAY output_buf, |
| 817 |
JDIMENSION output_col) |
| 818 |
{ |
| 819 |
jsimd_idct_4x4_neon(compptr->dct_table, coef_block, output_buf, output_col); |
| 820 |
} |
| 821 |
|
| 822 |
GLOBAL(int) |
| 823 |
jsimd_can_idct_islow(void) |
| 824 |
{ |
| 825 |
init_simd(); |
| 826 |
|
| 827 |
/* The code is optimised for these values only */ |
| 828 |
if (DCTSIZE != 8) |
| 829 |
return 0; |
| 830 |
if (sizeof(JCOEF) != 2) |
| 831 |
return 0; |
| 832 |
if (BITS_IN_JSAMPLE != 8) |
| 833 |
return 0; |
| 834 |
if (sizeof(JDIMENSION) != 4) |
| 835 |
return 0; |
| 836 |
if (sizeof(ISLOW_MULT_TYPE) != 2) |
| 837 |
return 0; |
| 838 |
|
| 839 |
if (simd_support & JSIMD_NEON) |
| 840 |
return 1; |
| 841 |
|
| 842 |
return 0; |
| 843 |
} |
| 844 |
|
| 845 |
GLOBAL(int) |
| 846 |
jsimd_can_idct_ifast(void) |
| 847 |
{ |
| 848 |
init_simd(); |
| 849 |
|
| 850 |
/* The code is optimised for these values only */ |
| 851 |
if (DCTSIZE != 8) |
| 852 |
return 0; |
| 853 |
if (sizeof(JCOEF) != 2) |
| 854 |
return 0; |
| 855 |
if (BITS_IN_JSAMPLE != 8) |
| 856 |
return 0; |
| 857 |
if (sizeof(JDIMENSION) != 4) |
| 858 |
return 0; |
| 859 |
if (sizeof(IFAST_MULT_TYPE) != 2) |
| 860 |
return 0; |
| 861 |
if (IFAST_SCALE_BITS != 2) |
| 862 |
return 0; |
| 863 |
|
| 864 |
if (simd_support & JSIMD_NEON) |
| 865 |
return 1; |
| 866 |
|
| 867 |
return 0; |
| 868 |
} |
| 869 |
|
| 870 |
GLOBAL(int) |
| 871 |
jsimd_can_idct_float(void) |
| 872 |
{ |
| 873 |
return 0; |
| 874 |
} |
| 875 |
|
| 876 |
GLOBAL(void) |
| 877 |
jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 878 |
JCOEFPTR coef_block, JSAMPARRAY output_buf, |
| 879 |
JDIMENSION output_col) |
| 880 |
{ |
| 881 |
jsimd_idct_islow_neon(compptr->dct_table, coef_block, output_buf, |
| 882 |
output_col); |
| 883 |
} |
| 884 |
|
| 885 |
GLOBAL(void) |
| 886 |
jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 887 |
JCOEFPTR coef_block, JSAMPARRAY output_buf, |
| 888 |
JDIMENSION output_col) |
| 889 |
{ |
| 890 |
jsimd_idct_ifast_neon(compptr->dct_table, coef_block, output_buf, |
| 891 |
output_col); |
| 892 |
} |
| 893 |
|
| 894 |
GLOBAL(void) |
| 895 |
jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
| 896 |
JCOEFPTR coef_block, JSAMPARRAY output_buf, |
| 897 |
JDIMENSION output_col) |
| 898 |
{ |
| 899 |
} |
| 900 |
|
| 901 |
GLOBAL(int) |
| 902 |
jsimd_can_huff_encode_one_block(void) |
| 903 |
{ |
| 904 |
init_simd(); |
| 905 |
|
| 906 |
if (DCTSIZE != 8) |
| 907 |
return 0; |
| 908 |
if (sizeof(JCOEF) != 2) |
| 909 |
return 0; |
| 910 |
|
| 911 |
if ((simd_support & JSIMD_NEON) && simd_huffman) |
| 912 |
return 1; |
| 913 |
|
| 914 |
return 0; |
| 915 |
} |
| 916 |
|
| 917 |
GLOBAL(JOCTET *) |
| 918 |
jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block, |
| 919 |
int last_dc_val, c_derived_tbl *dctbl, |
| 920 |
c_derived_tbl *actbl) |
| 921 |
{ |
| 922 |
return jsimd_huff_encode_one_block_neon(state, buffer, block, last_dc_val, |
| 923 |
dctbl, actbl); |
| 924 |
} |
| 925 |
|
| 926 |
GLOBAL(int) |
| 927 |
jsimd_can_encode_mcu_AC_first_prepare(void) |
| 928 |
{ |
| 929 |
init_simd(); |
| 930 |
|
| 931 |
if (DCTSIZE != 8) |
| 932 |
return 0; |
| 933 |
if (sizeof(JCOEF) != 2) |
| 934 |
return 0; |
| 935 |
|
| 936 |
if ((simd_support & JSIMD_NEON) && simd_huffman) |
| 937 |
return 1; |
| 938 |
|
| 939 |
return 0; |
| 940 |
} |
| 941 |
|
| 942 |
GLOBAL(void) |
| 943 |
jsimd_encode_mcu_AC_first_prepare(const JCOEF *block, |
| 944 |
const int *jpeg_natural_order_start, int Sl, |
| 945 |
int Al, UJCOEF *values, size_t *zerobits) |
| 946 |
{ |
| 947 |
jsimd_encode_mcu_AC_first_prepare_neon(block, jpeg_natural_order_start, |
| 948 |
Sl, Al, values, zerobits); |
| 949 |
} |
| 950 |
|
| 951 |
GLOBAL(int) |
| 952 |
jsimd_can_encode_mcu_AC_refine_prepare(void) |
| 953 |
{ |
| 954 |
init_simd(); |
| 955 |
|
| 956 |
if (DCTSIZE != 8) |
| 957 |
return 0; |
| 958 |
if (sizeof(JCOEF) != 2) |
| 959 |
return 0; |
| 960 |
|
| 961 |
if ((simd_support & JSIMD_NEON) && simd_huffman) |
| 962 |
return 1; |
| 963 |
|
| 964 |
return 0; |
| 965 |
} |
| 966 |
|
| 967 |
GLOBAL(int) |
| 968 |
jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block, |
| 969 |
const int *jpeg_natural_order_start, int Sl, |
| 970 |
int Al, UJCOEF *absvalues, size_t *bits) |
| 971 |
{ |
| 972 |
return jsimd_encode_mcu_AC_refine_prepare_neon(block, |
| 973 |
jpeg_natural_order_start, Sl, |
| 974 |
Al, absvalues, bits); |
| 975 |
} |