aboutsummaryrefslogtreecommitdiff
path: root/simd/jsimd_arm_neon.c
blob: 722dc6209c3802340d7ff3304e38d29f642feed1 (plain)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/*
 * jsimd_arm_neon.c
 *
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
 * Copyright 2009 D. R. Commander
 * Copyright 2011 Mandeep Kumar <mandeep.kumar@linaro.org> 
 * 
 * Based on the x86 SIMD extension for IJG JPEG library,
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
 * For conditions of distribution and use, see copyright notice in jsimdext.inc
 *
 * This file contain ARM NEON optimized routines. 
 */

#define JPEG_INTERNALS
#include "../jinclude.h"
#include "../jpeglib.h"
#include "../jsimd.h"
#include "../jdct.h"
#include "../jsimddct.h"


/* Private subobject */

typedef struct {
  struct jpeg_color_deconverter pub; /* public fields */

  /* Private state for YCC->RGB conversion */
  int * Cr_r_tab;		/* => table for Cr to R conversion */
  int * Cb_b_tab;		/* => table for Cb to B conversion */
  INT32 * Cr_g_tab;		/* => table for Cr to G conversion */
  INT32 * Cb_g_tab;		/* => table for Cb to G conversion */
} my_color_deconverter;

typedef my_color_deconverter * my_cconvert_ptr;


#define DEQUANTIZE(coef,quantval)  ((coef) * ((INT16)quantval))

/* IDCT routines */
EXTERN (void) idct_1x1_venum (INT16 * coeffPtr, INT16 * samplePtr, INT32 stride);
EXTERN (void) idct_2x2_venum (INT16 * coeffPtr, INT16 * samplePtr, INT32 stride);
EXTERN (void) idct_4x4_venum (INT16 * coeffPtr, INT16 * samplePtr, INT32 stride);
EXTERN (void) idct_8x8_venum (INT16 * coeffPtr, UINT8 **samplePtr, INT32 col, INT16 *qtab);

/* Color conversion routines */
EXTERN (void) yvup2rgb565_venum (UINT8 *pLumaLine,
                UINT8 *pCrLine,
                UINT8 *pCbLine,
                UINT8 *pRGB565Line,
                JDIMENSION nLineWidth);
EXTERN (void) yyvup2rgb565_venum (UINT8 * pLumaLine,
                UINT8 *pCrLine,
                UINT8 *pCbLine,
                UINT8 * pRGB565Line,
                JDIMENSION nLineWidth);
EXTERN (void) yvup2bgr888_venum (UINT8 * pLumaLine,
                UINT8 *pCrLine,
                UINT8 *pCbLine,
                UINT8 * pBGR888Line,
                JDIMENSION nLineWidth);
EXTERN (void) yyvup2bgr888_venum (UINT8 * pLumaLine,
                UINT8 *pCrLine,
                UINT8 *pCbLine,
                UINT8 * pBGR888Line,
                JDIMENSION nLineWidth);
EXTERN (void) yvup2abgr8888_venum (UINT8 * pLumaLine,
                UINT8 *pCrLine,
                UINT8 *pCbLine,
                UINT8 * pABGR888Line,
                JDIMENSION nLineWidth);
EXTERN (void) yyvup2abgr8888_venum (UINT8 * pLumaLine,
                UINT8 *pCrLine,
                UINT8 *pCbLine,
                UINT8 * pABGR888Line,
                JDIMENSION nLineWidth);


GLOBAL(int)
jsimd_can_rgb_ycc (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_ycc_rgb (void)
{
  return 1;
}

GLOBAL(int)
jsimd_can_idct_islow (void)
{
  return 1;
}

GLOBAL(int)
jsimd_can_idct_ifast (void)
{
  return 1;
}

GLOBAL(int)
jsimd_can_idct_float (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_h2v2_downsample (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_h2v1_downsample (void)
{
  return 0;
}
GLOBAL(int)
jsimd_can_h2v2_upsample (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_h2v1_upsample (void)
{
  return 0;
}
GLOBAL(int)
jsimd_can_h2v2_fancy_upsample (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_h2v1_fancy_upsample (void)
{
  return 0;
}
GLOBAL(int)
jsimd_can_h2v2_merged_upsample (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_h2v1_merged_upsample (void)
{
  return 0;
}
GLOBAL(int)
jsimd_can_convsamp (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_convsamp_float (void)
{
  return 0;
}
GLOBAL(int)
jsimd_can_fdct_islow (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_fdct_ifast (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_fdct_float (void)
{
  return 0;
}
GLOBAL(int)
jsimd_can_quantize (void)
{
  return 0;
}

GLOBAL(int)
jsimd_can_quantize_float (void)
{
  return 0;
}
GLOBAL(int)
jsimd_can_idct_2x2 (void)
{
  return 1;
}

GLOBAL(int)
jsimd_can_idct_4x4 (void)
{
  return 1;
}




/* Function Implementation */

GLOBAL(void)
jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
                       JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
                       JDIMENSION output_row, int num_rows)
{
}

GLOBAL(void)
jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
                       JSAMPIMAGE input_buf, JDIMENSION input_row,
                       JSAMPARRAY output_buf, int num_rows)
{
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  JSAMPROW inptr0, inptr1, inptr2;
  JSAMPROW outptr;
  JDIMENSION row;

  for (row = 0; row < (JDIMENSION)num_rows; row++)
  {
    inptr0     = input_buf[0][input_row];
    inptr1     = input_buf[1][input_row];
    inptr2     = input_buf[2][input_row];

    input_row++;
    outptr = *output_buf++;

    yvup2bgr888_venum((UINT8*) inptr0,
                      (UINT8*) inptr2,
                      (UINT8*) inptr1,
                      (UINT8*) outptr,
                      cinfo->output_width);
  }
}



GLOBAL(void)
jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}

GLOBAL(void)
jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}


GLOBAL(void)
jsimd_h2v2_upsample (j_decompress_ptr cinfo,
                     jpeg_component_info * compptr, 
                     JSAMPARRAY input_data,
                     JSAMPARRAY * output_data_ptr)
{
}

GLOBAL(void)
jsimd_h2v1_upsample (j_decompress_ptr cinfo,
                     jpeg_component_info * compptr, 
                     JSAMPARRAY input_data,
                     JSAMPARRAY * output_data_ptr)
{
}


GLOBAL(void)
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
                           jpeg_component_info * compptr, 
                           JSAMPARRAY input_data,
                           JSAMPARRAY * output_data_ptr)
{
}

GLOBAL(void)
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
                           jpeg_component_info * compptr, 
                           JSAMPARRAY input_data,
                           JSAMPARRAY * output_data_ptr)
{
}


GLOBAL(void)
jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
                            JSAMPIMAGE input_buf,
                            JDIMENSION in_row_group_ctr,
                            JSAMPARRAY output_buf)
{
}

GLOBAL(void)
jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
                            JSAMPIMAGE input_buf,
                            JDIMENSION in_row_group_ctr,
                            JSAMPARRAY output_buf)
{
}


GLOBAL(void)
jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
                DCTELEM * workspace)
{
}

GLOBAL(void)
jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
                      FAST_FLOAT * workspace)
{
}


GLOBAL(void)
jsimd_fdct_islow (DCTELEM * data)
{
}

GLOBAL(void)
jsimd_fdct_ifast (DCTELEM * data)
{
}

GLOBAL(void)
jsimd_fdct_float (FAST_FLOAT * data)
{
}


GLOBAL(void)
jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
                DCTELEM * workspace)
{
}

GLOBAL(void)
jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
                      FAST_FLOAT * workspace)
{
}


GLOBAL(void)
jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
                JDIMENSION output_col)
{
  ISLOW_MULT_TYPE * quantptr;
  JSAMPROW outptr;

  /* Note: Must allocate 8x2 even though only 2x2 is used because
   * IDCT function expects stride of 8. Stride input to function is ignored.
   * There is also a hw limitation requiring input size to be 8x2.
   */
  INT16    idct_out[DCTSIZE * (DCTSIZE>>2)];  /* buffers data between passes */
  INT16*   idctptr;
  JCOEFPTR coefptr;
  int ctr;

  coefptr  = coef_block;
  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;

  /* Dequantize the coeff buffer and write it back to the same location */
  for (ctr = (DCTSIZE>>2); ctr > 0; ctr--) {
    coefptr[0]         = DEQUANTIZE(coefptr[0]        , quantptr[0]        );
    coefptr[DCTSIZE*1] = DEQUANTIZE(coefptr[DCTSIZE*1], quantptr[DCTSIZE*1]);

    /* advance pointers to next column */
    quantptr++;
    coefptr++;
  }

  idct_2x2_venum((INT16*)coef_block,
                 (INT16*)idct_out,
                  DCTSIZE * sizeof(INT16));

  idctptr = idct_out;
  for (ctr = 0; ctr < (DCTSIZE>>2); ctr++) {
    outptr = output_buf[ctr] + output_col;

    /* outptr sample size is 1 bytes, idctptr sample size is 2 bytes */
    outptr[0] = idctptr[0];
    outptr[1] = idctptr[1];

    /* IDCT function assumes stride of 8 units */
    idctptr += (DCTSIZE);    /* advance pointers to next row */
  }
}

GLOBAL(void)
jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
                JDIMENSION output_col)
{
  ISLOW_MULT_TYPE * quantptr;
  JSAMPROW outptr;

  /* Note: Must allocate 8x4 even though only 4x4 is used because
   * IDCT function expects stride of 8. Stride input to function is ignored.
   */
  INT16    idct_out[DCTSIZE * (DCTSIZE>>1)];  /* buffers data between passes */
  INT16*   idctptr;
  JCOEFPTR coefptr;
  int ctr;

  coefptr  = coef_block;
  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;

  /* Dequantize the coeff buffer and write it back to the same location */
  for (ctr = (DCTSIZE>>1); ctr > 0; ctr--) {
    coefptr[0]         = DEQUANTIZE(coefptr[0]        , quantptr[0]        );
    coefptr[DCTSIZE*1] = DEQUANTIZE(coefptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
    coefptr[DCTSIZE*2] = DEQUANTIZE(coefptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
    coefptr[DCTSIZE*3] = DEQUANTIZE(coefptr[DCTSIZE*3], quantptr[DCTSIZE*3]);

    /* advance pointers to next column */
    quantptr++;
    coefptr++;
  }

  idct_4x4_venum((INT16*)coef_block,
                 (INT16*)idct_out,
                  DCTSIZE * sizeof(INT16));

  idctptr = idct_out;
  for (ctr = 0; ctr < (DCTSIZE>>1); ctr++) {
    outptr = output_buf[ctr] + output_col;

    /* outptr sample size is 1 byte while idctptr sample size is 2 bytes */
    outptr[0] = idctptr[0];
    outptr[1] = idctptr[1];
    outptr[2] = idctptr[2];
    outptr[3] = idctptr[3];
    /* IDCT function assumes stride of 8 units */
    idctptr += (DCTSIZE);    /* advance pointers to next row */
  }
}


GLOBAL(void)
jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
                JDIMENSION output_col)
{
  idct_8x8_venum((INT16*)coef_block,
                 output_buf,
                 output_col,
                 compptr->dct_table);
}

GLOBAL(void)
jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
                JDIMENSION output_col)
{
  idct_8x8_venum((INT16*)coef_block,
                 output_buf,
                 output_col,
                 compptr->dct_table);
}

GLOBAL(void)
jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
                JDIMENSION output_col)
{
}