external/jpeg-9b.patch
author Sam Lantinga <slouken@libsdl.org>
Fri, 26 Oct 2018 14:58:01 -0700
changeset 617 d64228a395fc
parent 542 4009a3c9612b
permissions -rw-r--r--
Fixed webp library detection when cross-compiling for Windows
slouken@522
     1
diff -ruN jpeg-9b.orig/Android.mk jpeg-9b/Android.mk
slouken@522
     2
--- jpeg-9b.orig/Android.mk	1969-12-31 16:00:00.000000000 -0800
slouken@542
     3
+++ jpeg-9b/Android.mk	2017-10-23 07:33:24.698623073 -0700
slouken@522
     4
@@ -0,0 +1,37 @@
slouken@522
     5
+LOCAL_PATH:= $(call my-dir)
slouken@522
     6
+include $(CLEAR_VARS)
slouken@522
     7
+
slouken@522
     8
+LOCAL_ARM_MODE := arm
slouken@522
     9
+
slouken@522
    10
+LOCAL_SRC_FILES := \
slouken@522
    11
+    jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \
slouken@522
    12
+    jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \
slouken@522
    13
+    jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \
slouken@522
    14
+    jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \
slouken@522
    15
+    jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \
slouken@522
    16
+    jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \
slouken@542
    17
+    jfdctfst.c jfdctint.c jidctflt.c jquant1.c \
slouken@522
    18
+    jquant2.c jutils.c jmemmgr.c \
slouken@522
    19
+	jmem-android.c
slouken@522
    20
+
slouken@522
    21
+# the assembler is only for the ARM version, don't break the Linux sim
slouken@522
    22
+ifneq ($(TARGET_ARCH),arm)
slouken@522
    23
+ANDROID_JPEG_NO_ASSEMBLER := true
slouken@522
    24
+endif
slouken@522
    25
+
slouken@522
    26
+# temp fix until we understand why this broke cnn.com
slouken@542
    27
+ANDROID_JPEG_NO_ASSEMBLER := true
slouken@522
    28
+
slouken@522
    29
+ifeq ($(strip $(ANDROID_JPEG_NO_ASSEMBLER)),true)
slouken@522
    30
+LOCAL_SRC_FILES += jidctint.c jidctfst.c
slouken@522
    31
+else
slouken@522
    32
+LOCAL_SRC_FILES += jidctint.c jidctfst.S
slouken@522
    33
+endif
slouken@522
    34
+
slouken@522
    35
+LOCAL_CFLAGS += -DAVOID_TABLES 
slouken@522
    36
+LOCAL_CFLAGS += -O3 -fstrict-aliasing -fprefetch-loop-arrays
slouken@522
    37
+#LOCAL_CFLAGS += -march=armv6j
slouken@522
    38
+
slouken@522
    39
+LOCAL_MODULE:= jpeg
slouken@522
    40
+
slouken@522
    41
+include $(BUILD_STATIC_LIBRARY)
slouken@522
    42
diff -ruN jpeg-9b.orig/jconfig.h jpeg-9b/jconfig.h
slouken@522
    43
--- jpeg-9b.orig/jconfig.h	1969-12-31 16:00:00.000000000 -0800
slouken@542
    44
+++ jpeg-9b/jconfig.h	2017-10-22 10:55:55.745170265 -0700
slouken@522
    45
@@ -0,0 +1,156 @@
slouken@522
    46
+/* android jconfig.h */
slouken@522
    47
+/*
slouken@522
    48
+ * jconfig.doc
slouken@522
    49
+ *
slouken@522
    50
+ * Copyright (C) 1991-1994, Thomas G. Lane.
slouken@522
    51
+ * This file is part of the Independent JPEG Group's software.
slouken@522
    52
+ * For conditions of distribution and use, see the accompanying README file.
slouken@522
    53
+ *
slouken@522
    54
+ * This file documents the configuration options that are required to
slouken@522
    55
+ * customize the JPEG software for a particular system.
slouken@522
    56
+ *
slouken@522
    57
+ * The actual configuration options for a particular installation are stored
slouken@522
    58
+ * in jconfig.h.  On many machines, jconfig.h can be generated automatically
slouken@522
    59
+ * or copied from one of the "canned" jconfig files that we supply.  But if
slouken@522
    60
+ * you need to generate a jconfig.h file by hand, this file tells you how.
slouken@522
    61
+ *
slouken@522
    62
+ * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING.
slouken@522
    63
+ * EDIT A COPY NAMED JCONFIG.H.
slouken@522
    64
+ */
slouken@522
    65
+
slouken@522
    66
+
slouken@522
    67
+/*
slouken@522
    68
+ * These symbols indicate the properties of your machine or compiler.
slouken@522
    69
+ * #define the symbol if yes, #undef it if no.
slouken@522
    70
+ */
slouken@522
    71
+
slouken@522
    72
+/* Does your compiler support function prototypes?
slouken@522
    73
+ * (If not, you also need to use ansi2knr, see install.doc)
slouken@522
    74
+ */
slouken@522
    75
+#define HAVE_PROTOTYPES
slouken@522
    76
+
slouken@522
    77
+/* Does your compiler support the declaration "unsigned char" ?
slouken@522
    78
+ * How about "unsigned short" ?
slouken@522
    79
+ */
slouken@522
    80
+#define HAVE_UNSIGNED_CHAR
slouken@522
    81
+#define HAVE_UNSIGNED_SHORT
slouken@522
    82
+
slouken@522
    83
+/* Define "void" as "char" if your compiler doesn't know about type void.
slouken@522
    84
+ * NOTE: be sure to define void such that "void *" represents the most general
slouken@522
    85
+ * pointer type, e.g., that returned by malloc().
slouken@522
    86
+ */
slouken@522
    87
+/* #define void char */
slouken@522
    88
+
slouken@522
    89
+/* Define "const" as empty if your compiler doesn't know the "const" keyword.
slouken@522
    90
+ */
slouken@522
    91
+/* #define const */
slouken@522
    92
+
slouken@522
    93
+/* Define this if an ordinary "char" type is unsigned.
slouken@522
    94
+ * If you're not sure, leaving it undefined will work at some cost in speed.
slouken@522
    95
+ * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.
slouken@522
    96
+ */
slouken@522
    97
+#undef CHAR_IS_UNSIGNED
slouken@522
    98
+
slouken@522
    99
+/* Define this if your system has an ANSI-conforming <stddef.h> file.
slouken@522
   100
+ */
slouken@522
   101
+#define HAVE_STDDEF_H
slouken@522
   102
+
slouken@522
   103
+/* Define this if your system has an ANSI-conforming <stdlib.h> file.
slouken@522
   104
+ */
slouken@522
   105
+#define HAVE_STDLIB_H
slouken@522
   106
+
slouken@522
   107
+/* Define this if your system does not have an ANSI/SysV <string.h>,
slouken@522
   108
+ * but does have a BSD-style <strings.h>.
slouken@522
   109
+ */
slouken@522
   110
+#undef NEED_BSD_STRINGS
slouken@522
   111
+
slouken@522
   112
+/* Define this if your system does not provide typedef size_t in any of the
slouken@522
   113
+ * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in
slouken@522
   114
+ * <sys/types.h> instead.
slouken@522
   115
+ */
slouken@522
   116
+#undef NEED_SYS_TYPES_H
slouken@522
   117
+
slouken@522
   118
+/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
slouken@522
   119
+ * unless you are using a large-data memory model or 80386 flat-memory mode.
slouken@522
   120
+ * On less brain-damaged CPUs this symbol must not be defined.
slouken@522
   121
+ * (Defining this symbol causes large data structures to be referenced through
slouken@522
   122
+ * "far" pointers and to be allocated with a special version of malloc.)
slouken@522
   123
+ */
slouken@522
   124
+#undef NEED_FAR_POINTERS
slouken@522
   125
+
slouken@522
   126
+/* Define this if your linker needs global names to be unique in less
slouken@522
   127
+ * than the first 15 characters.
slouken@522
   128
+ */
slouken@522
   129
+#undef NEED_SHORT_EXTERNAL_NAMES
slouken@522
   130
+
slouken@522
   131
+/* Although a real ANSI C compiler can deal perfectly well with pointers to
slouken@522
   132
+ * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
slouken@522
   133
+ * and pseudo-ANSI compilers get confused.  To keep one of these bozos happy,
slouken@522
   134
+ * define INCOMPLETE_TYPES_BROKEN.  This is not recommended unless you
slouken@522
   135
+ * actually get "missing structure definition" warnings or errors while
slouken@522
   136
+ * compiling the JPEG code.
slouken@522
   137
+ */
slouken@522
   138
+#undef INCOMPLETE_TYPES_BROKEN
slouken@522
   139
+
slouken@522
   140
+
slouken@522
   141
+/*
slouken@522
   142
+ * The following options affect code selection within the JPEG library,
slouken@522
   143
+ * but they don't need to be visible to applications using the library.
slouken@522
   144
+ * To minimize application namespace pollution, the symbols won't be
slouken@522
   145
+ * defined unless JPEG_INTERNALS has been defined.
slouken@522
   146
+ */
slouken@522
   147
+
slouken@522
   148
+#ifdef JPEG_INTERNALS
slouken@522
   149
+
slouken@522
   150
+/* Define this if your compiler implements ">>" on signed values as a logical
slouken@522
   151
+ * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift,
slouken@522
   152
+ * which is the normal and rational definition.
slouken@522
   153
+ */
slouken@522
   154
+#undef RIGHT_SHIFT_IS_UNSIGNED
slouken@522
   155
+
slouken@522
   156
+
slouken@522
   157
+#endif /* JPEG_INTERNALS */
slouken@522
   158
+
slouken@522
   159
+
slouken@522
   160
+/*
slouken@522
   161
+ * The remaining options do not affect the JPEG library proper,
slouken@522
   162
+ * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c).
slouken@522
   163
+ * Other applications can ignore these.
slouken@522
   164
+ */
slouken@522
   165
+
slouken@522
   166
+#ifdef JPEG_CJPEG_DJPEG
slouken@522
   167
+
slouken@522
   168
+/* These defines indicate which image (non-JPEG) file formats are allowed. */
slouken@522
   169
+
slouken@522
   170
+#define BMP_SUPPORTED		/* BMP image file format */
slouken@522
   171
+#define GIF_SUPPORTED		/* GIF image file format */
slouken@522
   172
+#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
slouken@522
   173
+#undef RLE_SUPPORTED		/* Utah RLE image file format */
slouken@522
   174
+#define TARGA_SUPPORTED		/* Targa image file format */
slouken@522
   175
+
slouken@522
   176
+/* Define this if you want to name both input and output files on the command
slouken@522
   177
+ * line, rather than using stdout and optionally stdin.  You MUST do this if
slouken@522
   178
+ * your system can't cope with binary I/O to stdin/stdout.  See comments at
slouken@522
   179
+ * head of cjpeg.c or djpeg.c.
slouken@522
   180
+ */
slouken@522
   181
+#undef TWO_FILE_COMMANDLINE
slouken@522
   182
+
slouken@522
   183
+/* Define this if your system needs explicit cleanup of temporary files.
slouken@522
   184
+ * This is crucial under MS-DOS, where the temporary "files" may be areas
slouken@522
   185
+ * of extended memory; on most other systems it's not as important.
slouken@522
   186
+ */
slouken@522
   187
+#undef NEED_SIGNAL_CATCHER
slouken@522
   188
+
slouken@522
   189
+/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
slouken@522
   190
+ * This is necessary on systems that distinguish text files from binary files,
slouken@522
   191
+ * and is harmless on most systems that don't.  If you have one of the rare
slouken@522
   192
+ * systems that complains about the "b" spec, define this symbol.
slouken@522
   193
+ */
slouken@522
   194
+#undef DONT_USE_B_MODE
slouken@522
   195
+
slouken@522
   196
+/* Define this if you want percent-done progress reports from cjpeg/djpeg.
slouken@522
   197
+ */
slouken@522
   198
+#undef PROGRESS_REPORT
slouken@522
   199
+
slouken@522
   200
+
slouken@522
   201
+#endif /* JPEG_CJPEG_DJPEG */
slouken@522
   202
diff -ruN jpeg-9b.orig/jidctfst.S jpeg-9b/jidctfst.S
slouken@522
   203
--- jpeg-9b.orig/jidctfst.S	1969-12-31 16:00:00.000000000 -0800
slouken@542
   204
+++ jpeg-9b/jidctfst.S	2017-10-22 10:55:55.829170262 -0700
slouken@522
   205
@@ -0,0 +1,476 @@
slouken@522
   206
+/*
slouken@522
   207
+ * Copyright (C) 2008 The Android Open Source Project
slouken@522
   208
+ *
slouken@522
   209
+ * Licensed under the Apache License, Version 2.0 (the "License");
slouken@522
   210
+ * you may not use this file except in compliance with the License.
slouken@522
   211
+ * You may obtain a copy of the License at
slouken@522
   212
+ *
slouken@522
   213
+ *      http://www.apache.org/licenses/LICENSE-2.0
slouken@522
   214
+ *
slouken@522
   215
+ * Unless required by applicable law or agreed to in writing, software
slouken@522
   216
+ * distributed under the License is distributed on an "AS IS" BASIS,
slouken@522
   217
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
slouken@522
   218
+ * See the License for the specific language governing permissions and
slouken@522
   219
+ * limitations under the License.
slouken@522
   220
+ */
slouken@522
   221
+
slouken@522
   222
+#include <machine/cpu-features.h>
slouken@522
   223
+
slouken@522
   224
+    .text
slouken@522
   225
+    .align
slouken@522
   226
+
slouken@522
   227
+    .global jpeg_idct_ifast
slouken@522
   228
+    .func   jpeg_idct_ifast
slouken@522
   229
+
slouken@522
   230
+// NOTE: sb=r9, fp=r11 ip=r12, sp=r13, lr=r14, pc=r15
slouken@522
   231
+
slouken@522
   232
+// jpeg_idct_ifast (j_decompress_ptr       cinfo,
slouken@522
   233
+//                 jpeg_component_info *   compptr,
slouken@522
   234
+//                 short*                  coef_block,
slouken@522
   235
+//                 unsigned char*          output_buf,
slouken@522
   236
+//                 int                     output_col)
slouken@522
   237
+
slouken@522
   238
+#define  local_TMP0123       sp
slouken@522
   239
+#define  local_TMP0          [sp, #0]
slouken@522
   240
+#define  local_TMP1          [sp, #4]
slouken@522
   241
+#define  local_TMP2          [sp, #8]
slouken@522
   242
+#define  local_TMP3          [sp, #12]
slouken@522
   243
+#define  local_RANGE_TABLE   [sp, #16]
slouken@522
   244
+#define  local_OUTPUT_COL    [sp, #20]
slouken@522
   245
+#define  local_OUTPUT_BUF    [sp, #24]
slouken@522
   246
+#define  local_UNUSED        [sp, #28]
slouken@522
   247
+#define  off_WORKSPACE       32
slouken@522
   248
+#define  local_WORKSPACE     [sp, #offWORKSPACE]
slouken@522
   249
+#define  local_SIZE          (off_WORKSPACE + 8*8*4)
slouken@522
   250
+
slouken@522
   251
+#define  off_DECOMPRESS_range_limit_base  324
slouken@522
   252
+#define  off_COMPINFO_quanttable          80
slouken@522
   253
+
slouken@522
   254
+#define  DCTSIZE   8
slouken@522
   255
+#define  VY(x)   ((x)*DCTSIZE*2)
slouken@522
   256
+#define  QY(x)   ((x)*DCTSIZE*4)
slouken@522
   257
+
slouken@522
   258
+#define  VX(x)   ((x)*2)
slouken@522
   259
+#define  QX(x)   ((x)*4)
slouken@522
   260
+
slouken@522
   261
+#define  FIX_1_414213562    #362
slouken@522
   262
+#define  FIX_1_082392200    #277
slouken@522
   263
+#define  FIX_1_847759065    #473
slouken@522
   264
+#define  FIX_2_613125930    #669
slouken@522
   265
+
slouken@522
   266
+#define  RANGE_MASK   1023
slouken@522
   267
+
slouken@522
   268
+
slouken@522
   269
+
slouken@522
   270
+jpeg_idct_ifast:
slouken@522
   271
+    PLD     [r2, #0]
slouken@522
   272
+    stmdb   sp!, {r4,r5, r6,r7, r8,r9, r10,r11, r12,lr}
slouken@522
   273
+    ldr     r4, [sp, #4*10]
slouken@522
   274
+    sub     sp, #local_SIZE
slouken@522
   275
+
slouken@522
   276
+    ldr     r10,[r1, #off_COMPINFO_quanttable]         // r10 = quanttable
slouken@522
   277
+    str     r4, local_OUTPUT_COL
slouken@522
   278
+    str     r3, local_OUTPUT_BUF
slouken@522
   279
+    ldr     r5, [r0, #off_DECOMPRESS_range_limit_base]
slouken@522
   280
+    add     r5, r5, #128
slouken@522
   281
+    str     r5, local_RANGE_TABLE
slouken@522
   282
+    mov     fp, r2                                      // fp = coef_block
slouken@522
   283
+    add     ip, sp, #off_WORKSPACE
slouken@522
   284
+
slouken@522
   285
+VLoopTail:
slouken@522
   286
+    ldrsh    r0, [fp, #VY(0)]
slouken@522
   287
+    ldrsh    r1, [fp, #VY(1)]
slouken@522
   288
+    ldrsh    r2, [fp, #VY(2)]
slouken@522
   289
+    ldrsh    r3, [fp, #VY(3)]
slouken@522
   290
+    ldrsh    r4, [fp, #VY(4)]
slouken@522
   291
+    ldrsh    r5, [fp, #VY(5)]
slouken@522
   292
+    ldrsh    r6, [fp, #VY(6)]
slouken@522
   293
+    ldrsh    r7, [fp, #VY(7)]
slouken@522
   294
+
slouken@522
   295
+    cmp      r1, #0
slouken@522
   296
+    orreqs   r8, r2, r3
slouken@522
   297
+    orreqs   r8, r4, r5
slouken@522
   298
+    orreqs   r8, r6, r7
slouken@522
   299
+    beq      VLoopHeadZero
slouken@522
   300
+
slouken@522
   301
+VLoopHead:
slouken@522
   302
+    // tmp0 = DEQUANTIZE(in[DCTSIZE*0], quant[DCTSIZE*0]   (r0)
slouken@522
   303
+    // tmp2 = DEQUANTIZE(in[DCTSIZE*4], quant[DCTSIZE*4]   (r4)
slouken@522
   304
+    // tmp1 = DEQUANTIZE(in[DCTSIZE*2], quant[DCTSIZE*2]   (r2)
slouken@522
   305
+    // tmp3 = DEQUANTIZE(in[DCTSIZE*6], quant[DCTSIZE*6]   (r6)
slouken@522
   306
+    // tmp10 = tmp0 + tmp2   (r0)
slouken@522
   307
+    // tmp11 = tmp0 - tmp2   (r4)
slouken@522
   308
+
slouken@522
   309
+    ldr      r9, [r10, #QY(4)]
slouken@522
   310
+    ldr      r8, [r10, #QY(0)]
slouken@522
   311
+#if __ARM_HAVE_HALFWORD_MULTIPLY
slouken@522
   312
+    smulbb   r4, r9, r4
slouken@522
   313
+    smlabb   r0, r8, r0, r4
slouken@522
   314
+#else
slouken@522
   315
+    mul      r4, r9, r4
slouken@522
   316
+    mul      r0, r8, r0
slouken@522
   317
+    add      r0, r4
slouken@522
   318
+#endif
slouken@522
   319
+    ldr      r9, [r10, #QY(6)]
slouken@522
   320
+    ldr      r8, [r10, #QY(2)]
slouken@522
   321
+    sub      r4, r0, r4, lsl #1
slouken@522
   322
+#if __ARM_HAVE_HALFWORD_MULTIPLY
slouken@522
   323
+    smulbb   r6, r9, r6
slouken@522
   324
+    smlabb   r2, r8, r2, r6
slouken@522
   325
+#else
slouken@522
   326
+    mul      r6, r9, r6
slouken@522
   327
+    mul      r2, r8, r2
slouken@522
   328
+    add      r2, r6
slouken@522
   329
+#endif
slouken@522
   330
+
slouken@522
   331
+    // tmp13 = tmp1 + tmp3                                       (r2)
slouken@522
   332
+    // tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13    (r6)
slouken@522
   333
+    // FIX_1_4142... = 362 = 45*8 + 2
slouken@522
   334
+    sub      r6, r2, r6, lsl #1
slouken@522
   335
+    mov      r8, #360
slouken@522
   336
+    add      r8, r8, #2
slouken@522
   337
+    mul      r9, r6, r8
slouken@522
   338
+
slouken@522
   339
+    // tmp0 = tmp10 + tmp13;   (r0)
slouken@522
   340
+    // tmp3 = tmp10 - tmp13;   (r8)
slouken@522
   341
+    // tmp1 = tmp11 + tmp12;   (r4)
slouken@522
   342
+    // tmp2 = tmp11 - tmp12;   (r6)
slouken@522
   343
+    add     r0, r0, r2
slouken@522
   344
+    rsb     r6, r2, r9, asr #8
slouken@522
   345
+    sub     r8, r0, r2, lsl #1
slouken@522
   346
+    add     r4, r4, r6
slouken@522
   347
+    sub     r6, r4, r6, lsl #1
slouken@522
   348
+
slouken@522
   349
+    stmia   local_TMP0123, {r0, r4, r6, r8}
slouken@522
   350
+
slouken@522
   351
+    // NOTE: be sure to not user r0,r4,r6,r8 soon after stm above
slouken@522
   352
+
slouken@522
   353
+    // odd part
slouken@522
   354
+    // tmp4 = DEQUANTIZE( in[DCTSIZE*1], quant[DCTSIZE*1] )   (r1)
slouken@522
   355
+    // tmp6 = DEQUANTIZE( in[DCTSIZE*5], quant[DCTSIZE*5] )   (r5)
slouken@522
   356
+    // tmp5 = DEQUANTIZE( in[DCTSIZE*3], quant[DCTSIZE*3] )   (r3)
slouken@522
   357
+    // tmp7 = DEQUANTIZE( in[DCTSIZE*7], quant[DCTSIZE*7] )   (r7)
slouken@522
   358
+    // z13 = tmp6 + tmp5;  (r0)
slouken@522
   359
+    // z10 = tmp6 - tmp5;  (r2)
slouken@522
   360
+    // z11 = tmp4 + tmp7;  (r4)
slouken@522
   361
+    // z12 = tmp4 - tmp7;  (r6)
slouken@522
   362
+
slouken@522
   363
+    ldr     r2, [r10, #QY(1)]
slouken@522
   364
+    ldr     r9, [r10, #QY(5)]
slouken@522
   365
+#if __ARM_HAVE_HALFWORD_MULTIPLY
slouken@522
   366
+    smulbb  r1, r2, r1
slouken@522
   367
+#else
slouken@522
   368
+    mul     r1, r2, r1
slouken@522
   369
+#endif
slouken@522
   370
+    ldr     r2, [r10, #QY(3)]
slouken@522
   371
+#if __ARM_HAVE_HALFWORD_MULTIPLY
slouken@522
   372
+    smulbb  r5, r9, r5
slouken@522
   373
+#else
slouken@522
   374
+    mul     r5, r9, r5
slouken@522
   375
+#endif
slouken@522
   376
+    ldr     r9, [r10, #QY(7)]
slouken@522
   377
+#if __ARM_HAVE_HALFWORD_MULTIPLY
slouken@522
   378
+    smlabb  r0, r2, r3, r5
slouken@522
   379
+    smlabb  r4, r9, r7, r1
slouken@522
   380
+#else
slouken@522
   381
+    mul     r0, r2, r3
slouken@522
   382
+    add     r0, r5
slouken@522
   383
+    mul     r4, r9, r7
slouken@522
   384
+    add     r4, r1
slouken@522
   385
+#endif
slouken@522
   386
+    rsb  r2, r0, r5, lsl #1
slouken@522
   387
+    rsb  r6, r4, r1, lsl #1
slouken@522
   388
+
slouken@522
   389
+    // tmp7 = z11 + z13;                             (r7)
slouken@522
   390
+    // tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); (r1)
slouken@522
   391
+    // FIX_... = 360 + 2
slouken@522
   392
+    add   r7, r4, r0
slouken@522
   393
+    sub   r1, r4, r0
slouken@522
   394
+    mov   r8, #360
slouken@522
   395
+    add   r8, r8, #2
slouken@522
   396
+    mul   r1, r8, r1
slouken@522
   397
+
slouken@522
   398
+    // z5 = MULTIPLY(z10 + z12, FIX_1_847759065);        (r8)
slouken@522
   399
+    // tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;      (r0)
slouken@522
   400
+    // tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;    (r2)
slouken@522
   401
+    // FIX_1_8477... = 473 = 472 + 1
slouken@522
   402
+    // FIX_1_082...  = 277 = 276 + 1
slouken@522
   403
+    // FIX_2_...     = 669 = 668 + 1
slouken@522
   404
+    add     r8, r2, r6
slouken@522
   405
+    mov     r9, #472
slouken@522
   406
+    mla     r8, r9, r8, r8
slouken@522
   407
+    mov     r9, #276
slouken@522
   408
+    mla     r0, r6, r9, r6
slouken@522
   409
+    mov     r9, #668
slouken@522
   410
+    mla     r2, r9, r2, r2
slouken@522
   411
+    sub     r0, r0, r8
slouken@522
   412
+    rsb     r2, r2, r8
slouken@522
   413
+
slouken@522
   414
+    // tmp6 = tmp12 - tmp7;  (r6)
slouken@522
   415
+    // tmp5 = tmp11 - tmp6;  (r5)
slouken@522
   416
+    // tmp4 = tmp10 + tmp5;  (r4)
slouken@522
   417
+    rsb  r6, r7, r2, asr #8
slouken@522
   418
+    rsb  r5, r6, r1, asr #8
slouken@522
   419
+    add  r4, r5, r0, asr #8
slouken@522
   420
+
slouken@522
   421
+    ldmia local_TMP0123, {r0, r1, r2, r3}
slouken@522
   422
+
slouken@522
   423
+    // wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
slouken@522
   424
+    // wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
slouken@522
   425
+    // wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
slouken@522
   426
+    // wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
slouken@522
   427
+    // wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
slouken@522
   428
+    // wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
slouken@522
   429
+    // wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
slouken@522
   430
+    // wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
slouken@522
   431
+
slouken@522
   432
+    add   r0, r0, r7
slouken@522
   433
+    sub   r7, r0, r7, lsl #1
slouken@522
   434
+    add   r1, r1, r6
slouken@522
   435
+    sub   r6, r1, r6, lsl #1
slouken@522
   436
+    add   r2, r2, r5
slouken@522
   437
+    sub   r5, r2, r5, lsl #1
slouken@522
   438
+    sub   r3, r3, r4
slouken@522
   439
+    add   r4, r3, r4, lsl #1
slouken@522
   440
+
slouken@522
   441
+    str   r0, [ip, #QY(0)]
slouken@522
   442
+    str   r1, [ip, #QY(1)]
slouken@522
   443
+    str   r2, [ip, #QY(2)]
slouken@522
   444
+    str   r3, [ip, #QY(3)]
slouken@522
   445
+    str   r4, [ip, #QY(4)]
slouken@522
   446
+    str   r5, [ip, #QY(5)]
slouken@522
   447
+    str   r6, [ip, #QY(6)]
slouken@522
   448
+    str   r7, [ip, #QY(7)]
slouken@522
   449
+
slouken@522
   450
+    // inptr++;                    /* advance pointers to next column */
slouken@522
   451
+    // quantptr++;
slouken@522
   452
+    // wsptr++;
slouken@522
   453
+    add  fp, fp, #2
slouken@522
   454
+    add  r10, r10, #4
slouken@522
   455
+    add  ip, ip, #4
slouken@522
   456
+    add  r0, sp, #(off_WORKSPACE + 4*8)
slouken@522
   457
+    cmp  ip, r0
slouken@522
   458
+    bne  VLoopTail
slouken@522
   459
+
slouken@522
   460
+
slouken@522
   461
+
slouken@522
   462
+HLoopStart:
slouken@522
   463
+    // reset pointers
slouken@522
   464
+    PLD     [sp, #off_WORKSPACE]
slouken@522
   465
+    add     ip, sp, #off_WORKSPACE
slouken@522
   466
+    ldr     r10, local_RANGE_TABLE
slouken@522
   467
+
slouken@522
   468
+HLoopTail:
slouken@522
   469
+    // output = *output_buf++ + output_col
slouken@522
   470
+    ldr      r0, local_OUTPUT_BUF
slouken@522
   471
+    ldr      r1, local_OUTPUT_COL
slouken@522
   472
+    ldr      r2, [r0], #4
slouken@522
   473
+    str      r0, local_OUTPUT_BUF
slouken@522
   474
+    add      fp, r2, r1
slouken@522
   475
+
slouken@522
   476
+    PLD      [ip, #32]
slouken@522
   477
+    ldmia    ip!, {r0-r7}
slouken@522
   478
+
slouken@522
   479
+    cmp      r1, #0
slouken@522
   480
+    orreqs   r8, r2, r3
slouken@522
   481
+    orreqs   r8, r4, r5
slouken@522
   482
+    orreqs   r8, r6, r7
slouken@522
   483
+    beq      HLoopTailZero
slouken@522
   484
+
slouken@522
   485
+HLoopHead:
slouken@522
   486
+    // tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);    (r0)
slouken@522
   487
+    // tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);    (r4)
slouken@522
   488
+    add     r0, r0, r4
slouken@522
   489
+    sub     r4, r0, r4, lsl #1
slouken@522
   490
+
slouken@522
   491
+    // tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);                                   (r2)
slouken@522
   492
+    // tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) - tmp13;  (r6)
slouken@522
   493
+    // FIX_... = 360 + 2
slouken@522
   494
+    add     r2, r2, r6
slouken@522
   495
+    sub     r6, r2, r6, lsl #1
slouken@522
   496
+    mov     r8, #360
slouken@522
   497
+    add     r8, r8, #2
slouken@522
   498
+    mul     r6, r8, r6
slouken@522
   499
+
slouken@522
   500
+    // tmp0 = tmp10 + tmp13;   (r0)
slouken@522
   501
+    // tmp3 = tmp10 - tmp13;   (r8)
slouken@522
   502
+    // tmp1 = tmp11 + tmp12;   (r4)
slouken@522
   503
+    // tmp2 = tmp11 - tmp12;   (r6)
slouken@522
   504
+    add     r0, r0, r2
slouken@522
   505
+    rsb     r6, r2, r6, asr #8
slouken@522
   506
+    sub     r8, r0, r2, lsl #1
slouken@522
   507
+    add     r4, r4, r6
slouken@522
   508
+    sub     r6, r4, r6, lsl #1
slouken@522
   509
+
slouken@522
   510
+    stmia   local_TMP0123, {r0, r4, r6, r8}
slouken@522
   511
+
slouken@522
   512
+    // Odd part
slouken@522
   513
+
slouken@522
   514
+    // z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];  (r0)
slouken@522
   515
+    // z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];  (r2)
slouken@522
   516
+    // z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];  (r4)
slouken@522
   517
+    // z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];  (r6)
slouken@522
   518
+    add  r0, r5, r3
slouken@522
   519
+    sub  r2, r5, r3
slouken@522
   520
+    add  r4, r1, r7
slouken@522
   521
+    sub  r6, r1, r7
slouken@522
   522
+
slouken@522
   523
+    // tmp7 = z11 + z13;                             (r7)
slouken@522
   524
+    // tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); (r1)
slouken@522
   525
+    // FIX_... = 360 + 2
slouken@522
   526
+    add   r7, r4, r0
slouken@522
   527
+    sub   r1, r4, r0
slouken@522
   528
+    mov   r8, #360
slouken@522
   529
+    add   r8, r8, #2
slouken@522
   530
+    mul   r1, r8, r1
slouken@522
   531
+
slouken@522
   532
+    // z5 = MULTIPLY(z10 + z12, FIX_1_847759065);        (r8)
slouken@522
   533
+    // tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;      (r0)
slouken@522
   534
+    // tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;    (r2)
slouken@522
   535
+    // FIX_1_8477... = 473 = 472 + 1
slouken@522
   536
+    // FIX_1_082...  = 277 = 276 + 1
slouken@522
   537
+    // FIX_2_...     = 669 = 668 + 1
slouken@522
   538
+    add  r8, r2, r6
slouken@522
   539
+    mov  r9, #472
slouken@522
   540
+    mla  r8, r9, r8, r8
slouken@522
   541
+    mov  r9, #276
slouken@522
   542
+    mla  r0, r6, r9, r6
slouken@522
   543
+    mov  r9, #668
slouken@522
   544
+    mla  r2, r9, r2, r2
slouken@522
   545
+    sub  r0, r0, r8
slouken@522
   546
+    sub  r2, r8, r2
slouken@522
   547
+
slouken@522
   548
+    // tmp6 = tmp12 - tmp7;  (r6)
slouken@522
   549
+    // tmp5 = tmp11 - tmp6;  (r5)
slouken@522
   550
+    // tmp4 = tmp10 + tmp5;  (r4)
slouken@522
   551
+    rsb  r6, r7, r2, asr #8
slouken@522
   552
+    rsb  r5, r6, r1, asr #8
slouken@522
   553
+    add  r4, r5, r0, asr #8
slouken@522
   554
+
slouken@522
   555
+    ldmia local_TMP0123, {r0, r1, r2, r3}
slouken@522
   556
+
slouken@522
   557
+    // outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   558
+    // outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   559
+    // outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   560
+    // outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   561
+    // outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   562
+    // outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   563
+    // outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   564
+    // outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) & RANGE_MASK];
slouken@522
   565
+
slouken@522
   566
+    mov    r8, #128
slouken@522
   567
+    add    r0, r0, r7
slouken@522
   568
+    sub    r7, r0, r7, lsl #1
slouken@522
   569
+    add    r0, r8, r0, asr #5
slouken@522
   570
+    add    r7, r8, r7, asr #5
slouken@522
   571
+    add    r1, r1, r6
slouken@522
   572
+    sub    r6, r1, r6, lsl #1
slouken@522
   573
+    add    r1, r8, r1, asr #5
slouken@522
   574
+    add    r6, r8, r6, asr #5
slouken@522
   575
+    add    r2, r2, r5
slouken@522
   576
+    sub    r5, r2, r5, lsl #1
slouken@522
   577
+    add    r2, r8, r2, asr #5
slouken@522
   578
+    add    r5, r8, r5, asr #5
slouken@522
   579
+    sub    r3, r3, r4
slouken@522
   580
+    add    r4, r3, r4, lsl #1
slouken@522
   581
+    add    r3, r8, r3, asr #5
slouken@522
   582
+    add    r4, r8, r4, asr #5
slouken@522
   583
+
slouken@522
   584
+#if __ARM_ARCH__ >= 6
slouken@522
   585
+    usat   r0, #8, r0
slouken@522
   586
+    usat   r1, #8, r1
slouken@522
   587
+    usat   r2, #8, r2
slouken@522
   588
+    usat   r3, #8, r3
slouken@522
   589
+    usat   r4, #8, r4
slouken@522
   590
+    usat   r5, #8, r5
slouken@522
   591
+    usat   r6, #8, r6
slouken@522
   592
+    usat   r7, #8, r7
slouken@522
   593
+#else
slouken@522
   594
+    cmp    r0, #255
slouken@522
   595
+    mvnhi  r0, r0, asr #31
slouken@522
   596
+    andhi  r0, #255
slouken@522
   597
+    cmp    r7, #255
slouken@522
   598
+    mvnhi  r7, r7, asr #31
slouken@522
   599
+    cmp    r1, #255
slouken@522
   600
+    mvnhi  r1, r1, asr #31
slouken@522
   601
+    andhi  r1, #255
slouken@522
   602
+    cmp    r6, #255
slouken@522
   603
+    mvnhi  r6, r6, asr #31
slouken@522
   604
+    andhi  r6, #255
slouken@522
   605
+    cmp    r2, #255
slouken@522
   606
+    mvnhi  r2, r2, asr #31
slouken@522
   607
+    andhi  r2, #255
slouken@522
   608
+    cmp    r5, #255
slouken@522
   609
+    mvnhi  r5, r5, asr #31
slouken@522
   610
+    andhi  r5, #255
slouken@522
   611
+    cmp    r3, #255
slouken@522
   612
+    mvnhi  r3, r3, asr #31
slouken@522
   613
+    cmp    r4, #255
slouken@522
   614
+    mvnhi  r4, r4, asr #31
slouken@522
   615
+    andhi  r4, #255
slouken@522
   616
+#endif
slouken@522
   617
+
slouken@522
   618
+    // r3 r2 r1 r0
slouken@522
   619
+    orr    r0, r0, r1, lsl #8
slouken@522
   620
+    orr    r0, r0, r2, lsl #16
slouken@522
   621
+    orr    r0, r0, r3, lsl #24
slouken@522
   622
+
slouken@522
   623
+    // r7 r6 r5 r4
slouken@522
   624
+    orr    r1, r4, r5, lsl #8
slouken@522
   625
+    orr    r1, r1, r6, lsl #16
slouken@522
   626
+    orr    r1, r1, r7, lsl #24
slouken@522
   627
+    stmia  fp, {r0, r1}
slouken@522
   628
+
slouken@522
   629
+    add    r0, sp, #(off_WORKSPACE + 8*8*4)
slouken@522
   630
+    cmp    ip, r0
slouken@522
   631
+    bne    HLoopTail
slouken@522
   632
+
slouken@522
   633
+Exit:
slouken@522
   634
+    add    sp, sp, #local_SIZE
slouken@522
   635
+    ldmia  sp!, {r4,r5, r6,r7, r8,r9, r10,r11, r12,lr}
slouken@522
   636
+    bx     lr
slouken@522
   637
+
slouken@522
   638
+
slouken@522
   639
+VLoopHeadZero:
slouken@522
   640
+// ok, all AC coefficients are 0
slouken@522
   641
+    ldr      r1, [r10, #QY(0)]
slouken@522
   642
+    add      fp, fp, #2
slouken@522
   643
+    add      r10, r10, #4
slouken@522
   644
+    mul      r0, r1, r0
slouken@522
   645
+    str      r0, [ip, #QY(0)]
slouken@522
   646
+    str      r0, [ip, #QY(1)]
slouken@522
   647
+    str      r0, [ip, #QY(2)]
slouken@522
   648
+    str      r0, [ip, #QY(3)]
slouken@522
   649
+    str      r0, [ip, #QY(4)]
slouken@522
   650
+    str      r0, [ip, #QY(5)]
slouken@522
   651
+    str      r0, [ip, #QY(6)]
slouken@522
   652
+    str      r0, [ip, #QY(7)]
slouken@522
   653
+    add      ip, ip, #4
slouken@522
   654
+    add      r0, sp, #(off_WORKSPACE + 4*8)
slouken@522
   655
+    cmp      ip, r0
slouken@522
   656
+    beq      HLoopStart
slouken@522
   657
+    b        VLoopTail
slouken@522
   658
+
slouken@522
   659
+HLoopTailZero:
slouken@522
   660
+    mov      r0, r0, asr #5
slouken@522
   661
+    add      r0, #128
slouken@522
   662
+
slouken@522
   663
+#if __ARM_ARCH__ >= 6
slouken@522
   664
+    usat     r0, #8, r0
slouken@522
   665
+#else
slouken@522
   666
+    cmp      r0, #255
slouken@522
   667
+    mvnhi    r0, r0, asr #31
slouken@522
   668
+    andhi    r0, r0, #255
slouken@522
   669
+#endif
slouken@522
   670
+
slouken@522
   671
+    orr      r0, r0, lsl #8
slouken@522
   672
+    orr      r0, r0, lsl #16
slouken@522
   673
+    mov      r1, r0
slouken@522
   674
+    stmia    fp, {r0, r1}
slouken@522
   675
+
slouken@522
   676
+    add      r0, sp, #(off_WORKSPACE + 64*4)
slouken@522
   677
+    cmp      ip, r0
slouken@522
   678
+    beq      Exit
slouken@522
   679
+    b        HLoopTail
slouken@522
   680
+
slouken@522
   681
+    .endfunc
slouken@522
   682
diff -ruN jpeg-9b.orig/jmem-android.c jpeg-9b/jmem-android.c
slouken@522
   683
--- jpeg-9b.orig/jmem-android.c	1969-12-31 16:00:00.000000000 -0800
slouken@542
   684
+++ jpeg-9b/jmem-android.c	2017-10-22 10:55:55.833170261 -0700
slouken@532
   685
@@ -0,0 +1,187 @@
slouken@522
   686
+/*
slouken@522
   687
+ * Copyright (C) 2007-2008 The Android Open Source Project
slouken@522
   688
+ *
slouken@522
   689
+ * Licensed under the Apache License, Version 2.0 (the "License");
slouken@522
   690
+ * you may not use this file except in compliance with the License.
slouken@522
   691
+ * You may obtain a copy of the License at
slouken@522
   692
+ *
slouken@522
   693
+ *      http://www.apache.org/licenses/LICENSE-2.0
slouken@522
   694
+ *
slouken@522
   695
+ * Unless required by applicable law or agreed to in writing, software
slouken@522
   696
+ * distributed under the License is distributed on an "AS IS" BASIS,
slouken@522
   697
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
slouken@522
   698
+ * See the License for the specific language governing permissions and
slouken@522
   699
+ * limitations under the License.
slouken@522
   700
+ */
slouken@522
   701
+
slouken@522
   702
+#define JPEG_INTERNALS
slouken@522
   703
+#include "jinclude.h"
slouken@522
   704
+#include "jpeglib.h"
slouken@522
   705
+#include "jmemsys.h"		/* import the system-dependent declarations */
slouken@532
   706
+#include <unistd.h>         /* For unlink() and getpid() */
slouken@522
   707
+
slouken@522
   708
+#ifndef HAVE_STDLIB_H		/* <stdlib.h> should declare malloc(),free() */
slouken@522
   709
+extern void * malloc JPP((size_t size));
slouken@522
   710
+extern void free JPP((void *ptr));
slouken@522
   711
+#endif
slouken@522
   712
+
slouken@522
   713
+#ifndef SEEK_SET		/* pre-ANSI systems may not define this; */
slouken@522
   714
+#define SEEK_SET  0		/* if not, assume 0 is correct */
slouken@522
   715
+#endif
slouken@522
   716
+
slouken@522
   717
+
slouken@522
   718
+/*
slouken@522
   719
+ * Memory allocation and freeing are controlled by the regular library
slouken@522
   720
+ * routines malloc() and free().
slouken@522
   721
+ */
slouken@522
   722
+
slouken@522
   723
+GLOBAL(void *)
slouken@522
   724
+jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
slouken@522
   725
+{
slouken@522
   726
+  return (void *) malloc(sizeofobject);
slouken@522
   727
+}
slouken@522
   728
+
slouken@522
   729
+GLOBAL(void)
slouken@522
   730
+jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
slouken@522
   731
+{
slouken@522
   732
+  free(object);
slouken@522
   733
+}
slouken@522
   734
+
slouken@522
   735
+
slouken@522
   736
+/*
slouken@522
   737
+ * "Large" objects are treated the same as "small" ones.
slouken@522
   738
+ * NB: although we include FAR keywords in the routine declarations,
slouken@522
   739
+ * this file won't actually work in 80x86 small/medium model; at least,
slouken@522
   740
+ * you probably won't be able to process useful-size images in only 64KB.
slouken@522
   741
+ */
slouken@522
   742
+
slouken@522
   743
+GLOBAL(void FAR *)
slouken@522
   744
+jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
slouken@522
   745
+{
slouken@522
   746
+  return (void FAR *) malloc(sizeofobject);
slouken@522
   747
+}
slouken@522
   748
+
slouken@522
   749
+GLOBAL(void)
slouken@522
   750
+jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
slouken@522
   751
+{
slouken@522
   752
+  free(object);
slouken@522
   753
+}
slouken@522
   754
+
slouken@522
   755
+
slouken@522
   756
+/*
slouken@522
   757
+ * This routine computes the total memory space available for allocation.
slouken@522
   758
+ * It's impossible to do this in a portable way; our current solution is
slouken@522
   759
+ * to make the user tell us (with a default value set at compile time).
slouken@522
   760
+ * If you can actually get the available space, it's a good idea to subtract
slouken@522
   761
+ * a slop factor of 5% or so.
slouken@522
   762
+ */
slouken@522
   763
+
slouken@522
   764
+#ifndef DEFAULT_MAX_MEM		/* so can override from makefile */
slouken@522
   765
+#define DEFAULT_MAX_MEM		10000000L /* default: ten megabyte */
slouken@522
   766
+#endif
slouken@522
   767
+
slouken@522
   768
+GLOBAL(long)
slouken@522
   769
+jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
slouken@522
   770
+		    long max_bytes_needed, long already_allocated)
slouken@522
   771
+{
slouken@522
   772
+  return cinfo->mem->max_memory_to_use - already_allocated;
slouken@522
   773
+}
slouken@522
   774
+
slouken@522
   775
+
slouken@522
   776
+/*
slouken@522
   777
+ * Backing store (temporary file) management.
slouken@522
   778
+ * Backing store objects are only used when the value returned by
slouken@522
   779
+ * jpeg_mem_available is less than the total space needed.  You can dispense
slouken@522
   780
+ * with these routines if you have plenty of virtual memory; see jmemnobs.c.
slouken@522
   781
+ */
slouken@522
   782
+
slouken@522
   783
+
slouken@522
   784
+METHODDEF(void)
slouken@522
   785
+read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
slouken@522
   786
+		    void FAR * buffer_address,
slouken@522
   787
+		    long file_offset, long byte_count)
slouken@522
   788
+{
slouken@522
   789
+  if (fseek(info->temp_file, file_offset, SEEK_SET))
slouken@522
   790
+    ERREXIT(cinfo, JERR_TFILE_SEEK);
slouken@522
   791
+  if (JFREAD(info->temp_file, buffer_address, byte_count)
slouken@522
   792
+      != (size_t) byte_count)
slouken@522
   793
+    ERREXIT(cinfo, JERR_TFILE_READ);
slouken@522
   794
+}
slouken@522
   795
+
slouken@522
   796
+
slouken@522
   797
+METHODDEF(void)
slouken@522
   798
+write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
slouken@522
   799
+		     void FAR * buffer_address,
slouken@522
   800
+		     long file_offset, long byte_count)
slouken@522
   801
+{
slouken@522
   802
+  if (fseek(info->temp_file, file_offset, SEEK_SET))
slouken@522
   803
+    ERREXIT(cinfo, JERR_TFILE_SEEK);
slouken@522
   804
+  if (JFWRITE(info->temp_file, buffer_address, byte_count)
slouken@522
   805
+      != (size_t) byte_count)
slouken@522
   806
+    ERREXIT(cinfo, JERR_TFILE_WRITE);
slouken@522
   807
+}
slouken@522
   808
+
slouken@522
   809
+
slouken@522
   810
+METHODDEF(void)
slouken@522
   811
+close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
slouken@522
   812
+{
slouken@522
   813
+  fclose(info->temp_file);
slouken@522
   814
+  /* Since this implementation uses tmpfile() to create the file,
slouken@522
   815
+   * no explicit file deletion is needed.
slouken@522
   816
+   */
slouken@522
   817
+}
slouken@522
   818
+
slouken@522
   819
+static FILE* getTempFileFromPath(const char * path) {
slouken@522
   820
+    FILE * fd = fopen(path, "w+");
slouken@522
   821
+    unlink(path);
slouken@522
   822
+    return fd;
slouken@522
   823
+}
slouken@522
   824
+
slouken@522
   825
+static FILE* getTempFile() {
slouken@522
   826
+    char path[1024];
slouken@522
   827
+    snprintf(path, 1023, "/sdcard/.%d.tmp", getpid());
slouken@522
   828
+    FILE * fd = getTempFileFromPath(path);
slouken@522
   829
+    if (fd == NULL) {
slouken@522
   830
+        // anywhere else we can create a temp file?
slouken@522
   831
+		//	    snprintf(path, 1023, "/data/data/.%d.tmp", getpid());
slouken@522
   832
+		//      fd = getTempFileFromPath(path);
slouken@522
   833
+    }
slouken@522
   834
+    return fd;
slouken@522
   835
+}
slouken@522
   836
+
slouken@522
   837
+/*
slouken@522
   838
+ * Initial opening of a backing-store object.
slouken@522
   839
+ *
slouken@522
   840
+ * This version uses tmpfile(), which constructs a suitable file name
slouken@522
   841
+ * behind the scenes.  We don't have to use info->temp_name[] at all;
slouken@522
   842
+ * indeed, we can't even find out the actual name of the temp file.
slouken@522
   843
+ */
slouken@522
   844
+
slouken@522
   845
+GLOBAL(void)
slouken@522
   846
+jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
slouken@522
   847
+			 long total_bytes_needed)
slouken@522
   848
+{
slouken@522
   849
+  if ((info->temp_file = getTempFile()) == NULL)
slouken@522
   850
+    ERREXITS(cinfo, JERR_TFILE_CREATE, "");
slouken@522
   851
+  info->read_backing_store = read_backing_store;
slouken@522
   852
+  info->write_backing_store = write_backing_store;
slouken@522
   853
+  info->close_backing_store = close_backing_store;
slouken@522
   854
+}
slouken@522
   855
+
slouken@522
   856
+
slouken@522
   857
+/*
slouken@522
   858
+ * These routines take care of any system-dependent initialization and
slouken@522
   859
+ * cleanup required.
slouken@522
   860
+ */
slouken@522
   861
+
slouken@522
   862
+GLOBAL(long)
slouken@522
   863
+jpeg_mem_init (j_common_ptr cinfo)
slouken@522
   864
+{
slouken@522
   865
+  return DEFAULT_MAX_MEM;	/* default for max_memory_to_use */
slouken@522
   866
+}
slouken@522
   867
+
slouken@522
   868
+GLOBAL(void)
slouken@522
   869
+jpeg_mem_term (j_common_ptr cinfo)
slouken@522
   870
+{
slouken@522
   871
+  /* no work */
slouken@522
   872
+}