Path: blob/master/thirdparty/libjpeg-turbo/src/jcdctmgr.c
9904 views
/*1* jcdctmgr.c2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1994-1996, Thomas G. Lane.5* libjpeg-turbo Modifications:6* Copyright (C) 1999-2006, MIYASAKA Masaru.7* Copyright 2009 Pierre Ossman <[email protected]> for Cendio AB8* Copyright (C) 2011, 2014-2015, 2022, 2024, D. R. Commander.9* For conditions of distribution and use, see the accompanying README.ijg10* file.11*12* This file contains the forward-DCT management logic.13* This code selects a particular DCT implementation to be used,14* and it performs related housekeeping chores including coefficient15* quantization.16*/1718#define JPEG_INTERNALS19#include "jinclude.h"20#include "jpeglib.h"21#include "jdct.h" /* Private declarations for DCT subsystem */22#include "jsimddct.h"232425/* Private subobject for this module */2627typedef void (*forward_DCT_method_ptr) (DCTELEM *data);28typedef void (*float_DCT_method_ptr) (FAST_FLOAT *data);2930typedef void (*convsamp_method_ptr) (_JSAMPARRAY sample_data,31JDIMENSION start_col,32DCTELEM *workspace);33typedef void (*float_convsamp_method_ptr) (_JSAMPARRAY sample_data,34JDIMENSION start_col,35FAST_FLOAT *workspace);3637typedef void (*quantize_method_ptr) (JCOEFPTR coef_block, DCTELEM *divisors,38DCTELEM *workspace);39typedef void (*float_quantize_method_ptr) (JCOEFPTR coef_block,40FAST_FLOAT *divisors,41FAST_FLOAT *workspace);4243METHODDEF(void) quantize(JCOEFPTR, DCTELEM *, DCTELEM *);4445typedef struct {46struct jpeg_forward_dct pub; /* public fields */4748/* Pointer to the DCT routine actually in use */49forward_DCT_method_ptr dct;50convsamp_method_ptr convsamp;51quantize_method_ptr quantize;5253/* The actual post-DCT divisors --- not identical to the quant table54* entries, because of scaling (especially for an unnormalized DCT).55* Each table is given in normal array order.56*/57DCTELEM *divisors[NUM_QUANT_TBLS];5859/* work area for FDCT subroutine */60DCTELEM *workspace;6162#ifdef DCT_FLOAT_SUPPORTED63/* Same as above for the floating-point case. */64float_DCT_method_ptr float_dct;65float_convsamp_method_ptr float_convsamp;66float_quantize_method_ptr float_quantize;67FAST_FLOAT *float_divisors[NUM_QUANT_TBLS];68FAST_FLOAT *float_workspace;69#endif70} my_fdct_controller;7172typedef my_fdct_controller *my_fdct_ptr;737475#if BITS_IN_JSAMPLE == 87677/*78* Find the highest bit in an integer through binary search.79*/8081LOCAL(int)82flss(UINT16 val)83{84int bit;8586bit = 16;8788if (!val)89return 0;9091if (!(val & 0xff00)) {92bit -= 8;93val <<= 8;94}95if (!(val & 0xf000)) {96bit -= 4;97val <<= 4;98}99if (!(val & 0xc000)) {100bit -= 2;101val <<= 2;102}103if (!(val & 0x8000)) {104bit -= 1;105val <<= 1;106}107108return bit;109}110111112/*113* Compute values to do a division using reciprocal.114*115* This implementation is based on an algorithm described in116* "Optimizing subroutines in assembly language:117* An optimization guide for x86 platforms" (https://agner.org/optimize).118* More information about the basic algorithm can be found in119* the paper "Integer Division Using Reciprocals" by Robert Alverson.120*121* The basic idea is to replace x/d by x * d^-1. In order to store122* d^-1 with enough precision we shift it left a few places. It turns123* out that this algoright gives just enough precision, and also fits124* into DCTELEM:125*126* b = (the number of significant bits in divisor) - 1127* r = (word size) + b128* f = 2^r / divisor129*130* f will not be an integer for most cases, so we need to compensate131* for the rounding error introduced:132*133* no fractional part:134*135* result = input >> r136*137* fractional part of f < 0.5:138*139* round f down to nearest integer140* result = ((input + 1) * f) >> r141*142* fractional part of f > 0.5:143*144* round f up to nearest integer145* result = (input * f) >> r146*147* This is the original algorithm that gives truncated results. But we148* want properly rounded results, so we replace "input" with149* "input + divisor/2".150*151* In order to allow SIMD implementations we also tweak the values to152* allow the same calculation to be made at all times:153*154* dctbl[0] = f rounded to nearest integer155* dctbl[1] = divisor / 2 (+ 1 if fractional part of f < 0.5)156* dctbl[2] = 1 << ((word size) * 2 - r)157* dctbl[3] = r - (word size)158*159* dctbl[2] is for stupid instruction sets where the shift operation160* isn't member wise (e.g. MMX).161*162* The reason dctbl[2] and dctbl[3] reduce the shift with (word size)163* is that most SIMD implementations have a "multiply and store top164* half" operation.165*166* Lastly, we store each of the values in their own table instead167* of in a consecutive manner, yet again in order to allow SIMD168* routines.169*/170171LOCAL(int)172compute_reciprocal(UINT16 divisor, DCTELEM *dtbl)173{174UDCTELEM2 fq, fr;175UDCTELEM c;176int b, r;177178if (divisor == 1) {179/* divisor == 1 means unquantized, so these reciprocal/correction/shift180* values will cause the C quantization algorithm to act like the181* identity function. Since only the C quantization algorithm is used in182* these cases, the scale value is irrelevant.183*/184dtbl[DCTSIZE2 * 0] = (DCTELEM)1; /* reciprocal */185dtbl[DCTSIZE2 * 1] = (DCTELEM)0; /* correction */186dtbl[DCTSIZE2 * 2] = (DCTELEM)1; /* scale */187dtbl[DCTSIZE2 * 3] = -(DCTELEM)(sizeof(DCTELEM) * 8); /* shift */188return 0;189}190191b = flss(divisor) - 1;192r = sizeof(DCTELEM) * 8 + b;193194fq = ((UDCTELEM2)1 << r) / divisor;195fr = ((UDCTELEM2)1 << r) % divisor;196197c = divisor / 2; /* for rounding */198199if (fr == 0) { /* divisor is power of two */200/* fq will be one bit too large to fit in DCTELEM, so adjust */201fq >>= 1;202r--;203} else if (fr <= (divisor / 2U)) { /* fractional part is < 0.5 */204c++;205} else { /* fractional part is > 0.5 */206fq++;207}208209dtbl[DCTSIZE2 * 0] = (DCTELEM)fq; /* reciprocal */210dtbl[DCTSIZE2 * 1] = (DCTELEM)c; /* correction + roundfactor */211#ifdef WITH_SIMD212dtbl[DCTSIZE2 * 2] = (DCTELEM)(1 << (sizeof(DCTELEM) * 8 * 2 - r)); /* scale */213#else214dtbl[DCTSIZE2 * 2] = 1;215#endif216dtbl[DCTSIZE2 * 3] = (DCTELEM)r - sizeof(DCTELEM) * 8; /* shift */217218if (r <= 16) return 0;219else return 1;220}221222#endif223224225/*226* Initialize for a processing pass.227* Verify that all referenced Q-tables are present, and set up228* the divisor table for each one.229* In the current implementation, DCT of all components is done during230* the first pass, even if only some components will be output in the231* first scan. Hence all components should be examined here.232*/233234METHODDEF(void)235start_pass_fdctmgr(j_compress_ptr cinfo)236{237my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;238int ci, qtblno, i;239jpeg_component_info *compptr;240JQUANT_TBL *qtbl;241DCTELEM *dtbl;242243for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;244ci++, compptr++) {245qtblno = compptr->quant_tbl_no;246/* Make sure specified quantization table is present */247if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||248cinfo->quant_tbl_ptrs[qtblno] == NULL)249ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);250qtbl = cinfo->quant_tbl_ptrs[qtblno];251/* Compute divisors for this quant table */252/* We may do this more than once for same table, but it's not a big deal */253switch (cinfo->dct_method) {254#ifdef DCT_ISLOW_SUPPORTED255case JDCT_ISLOW:256/* For LL&M IDCT method, divisors are equal to raw quantization257* coefficients multiplied by 8 (to counteract scaling).258*/259if (fdct->divisors[qtblno] == NULL) {260fdct->divisors[qtblno] = (DCTELEM *)261(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,262(DCTSIZE2 * 4) * sizeof(DCTELEM));263}264dtbl = fdct->divisors[qtblno];265for (i = 0; i < DCTSIZE2; i++) {266#if BITS_IN_JSAMPLE == 8267#ifdef WITH_SIMD268if (!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) &&269fdct->quantize == jsimd_quantize)270fdct->quantize = quantize;271#else272compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]);273#endif274#else275dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3;276#endif277}278break;279#endif280#ifdef DCT_IFAST_SUPPORTED281case JDCT_IFAST:282{283/* For AA&N IDCT method, divisors are equal to quantization284* coefficients scaled by scalefactor[row]*scalefactor[col], where285* scalefactor[0] = 1286* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7287* We apply a further scale factor of 8.288*/289#define CONST_BITS 14290static const INT16 aanscales[DCTSIZE2] = {291/* precomputed values scaled up by 14 bits */29216384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,29322725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,29421407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,29519266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,29616384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,29712873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,2988867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,2994520, 6270, 5906, 5315, 4520, 3552, 2446, 1247300};301SHIFT_TEMPS302303if (fdct->divisors[qtblno] == NULL) {304fdct->divisors[qtblno] = (DCTELEM *)305(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,306(DCTSIZE2 * 4) * sizeof(DCTELEM));307}308dtbl = fdct->divisors[qtblno];309for (i = 0; i < DCTSIZE2; i++) {310#if BITS_IN_JSAMPLE == 8311#ifdef WITH_SIMD312if (!compute_reciprocal(313DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],314(JLONG)aanscales[i]),315CONST_BITS - 3), &dtbl[i]) &&316fdct->quantize == jsimd_quantize)317fdct->quantize = quantize;318#else319compute_reciprocal(320DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],321(JLONG)aanscales[i]),322CONST_BITS-3), &dtbl[i]);323#endif324#else325dtbl[i] = (DCTELEM)326DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],327(JLONG)aanscales[i]),328CONST_BITS - 3);329#endif330}331}332break;333#endif334#ifdef DCT_FLOAT_SUPPORTED335case JDCT_FLOAT:336{337/* For float AA&N IDCT method, divisors are equal to quantization338* coefficients scaled by scalefactor[row]*scalefactor[col], where339* scalefactor[0] = 1340* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7341* We apply a further scale factor of 8.342* What's actually stored is 1/divisor so that the inner loop can343* use a multiplication rather than a division.344*/345FAST_FLOAT *fdtbl;346int row, col;347static const double aanscalefactor[DCTSIZE] = {3481.0, 1.387039845, 1.306562965, 1.175875602,3491.0, 0.785694958, 0.541196100, 0.275899379350};351352if (fdct->float_divisors[qtblno] == NULL) {353fdct->float_divisors[qtblno] = (FAST_FLOAT *)354(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,355DCTSIZE2 * sizeof(FAST_FLOAT));356}357fdtbl = fdct->float_divisors[qtblno];358i = 0;359for (row = 0; row < DCTSIZE; row++) {360for (col = 0; col < DCTSIZE; col++) {361fdtbl[i] = (FAST_FLOAT)362(1.0 / (((double)qtbl->quantval[i] *363aanscalefactor[row] * aanscalefactor[col] * 8.0)));364i++;365}366}367}368break;369#endif370default:371ERREXIT(cinfo, JERR_NOT_COMPILED);372break;373}374}375}376377378/*379* Load data into workspace, applying unsigned->signed conversion.380*/381382METHODDEF(void)383convsamp(_JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)384{385register DCTELEM *workspaceptr;386register _JSAMPROW elemptr;387register int elemr;388389workspaceptr = workspace;390for (elemr = 0; elemr < DCTSIZE; elemr++) {391elemptr = sample_data[elemr] + start_col;392393#if DCTSIZE == 8 /* unroll the inner loop */394*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;395*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;396*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;397*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;398*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;399*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;400*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;401*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;402#else403{404register int elemc;405for (elemc = DCTSIZE; elemc > 0; elemc--)406*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;407}408#endif409}410}411412413/*414* Quantize/descale the coefficients, and store into coef_blocks[].415*/416417METHODDEF(void)418quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)419{420int i;421DCTELEM temp;422JCOEFPTR output_ptr = coef_block;423424#if BITS_IN_JSAMPLE == 8425426UDCTELEM recip, corr;427int shift;428UDCTELEM2 product;429430for (i = 0; i < DCTSIZE2; i++) {431temp = workspace[i];432recip = divisors[i + DCTSIZE2 * 0];433corr = divisors[i + DCTSIZE2 * 1];434shift = divisors[i + DCTSIZE2 * 3];435436if (temp < 0) {437temp = -temp;438product = (UDCTELEM2)(temp + corr) * recip;439product >>= shift + sizeof(DCTELEM) * 8;440temp = (DCTELEM)product;441temp = -temp;442} else {443product = (UDCTELEM2)(temp + corr) * recip;444product >>= shift + sizeof(DCTELEM) * 8;445temp = (DCTELEM)product;446}447output_ptr[i] = (JCOEF)temp;448}449450#else451452register DCTELEM qval;453454for (i = 0; i < DCTSIZE2; i++) {455qval = divisors[i];456temp = workspace[i];457/* Divide the coefficient value by qval, ensuring proper rounding.458* Since C does not specify the direction of rounding for negative459* quotients, we have to force the dividend positive for portability.460*461* In most files, at least half of the output values will be zero462* (at default quantization settings, more like three-quarters...)463* so we should ensure that this case is fast. On many machines,464* a comparison is enough cheaper than a divide to make a special test465* a win. Since both inputs will be nonnegative, we need only test466* for a < b to discover whether a/b is 0.467* If your machine's division is fast enough, define FAST_DIVIDE.468*/469#ifdef FAST_DIVIDE470#define DIVIDE_BY(a, b) a /= b471#else472#define DIVIDE_BY(a, b) if (a >= b) a /= b; else a = 0473#endif474if (temp < 0) {475temp = -temp;476temp += qval >> 1; /* for rounding */477DIVIDE_BY(temp, qval);478temp = -temp;479} else {480temp += qval >> 1; /* for rounding */481DIVIDE_BY(temp, qval);482}483output_ptr[i] = (JCOEF)temp;484}485486#endif487488}489490491/*492* Perform forward DCT on one or more blocks of a component.493*494* The input samples are taken from the sample_data[] array starting at495* position start_row/start_col, and moving to the right for any additional496* blocks. The quantized coefficients are returned in coef_blocks[].497*/498499METHODDEF(void)500forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr,501_JSAMPARRAY sample_data, JBLOCKROW coef_blocks,502JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)503/* This version is used for integer DCT implementations. */504{505/* This routine is heavily used, so it's worth coding it tightly. */506my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;507DCTELEM *divisors = fdct->divisors[compptr->quant_tbl_no];508DCTELEM *workspace;509JDIMENSION bi;510511/* Make sure the compiler doesn't look up these every pass */512forward_DCT_method_ptr do_dct = fdct->dct;513convsamp_method_ptr do_convsamp = fdct->convsamp;514quantize_method_ptr do_quantize = fdct->quantize;515workspace = fdct->workspace;516517sample_data += start_row; /* fold in the vertical offset once */518519for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {520/* Load data into workspace, applying unsigned->signed conversion */521(*do_convsamp) (sample_data, start_col, workspace);522523/* Perform the DCT */524(*do_dct) (workspace);525526/* Quantize/descale the coefficients, and store into coef_blocks[] */527(*do_quantize) (coef_blocks[bi], divisors, workspace);528}529}530531532#ifdef DCT_FLOAT_SUPPORTED533534METHODDEF(void)535convsamp_float(_JSAMPARRAY sample_data, JDIMENSION start_col,536FAST_FLOAT *workspace)537{538register FAST_FLOAT *workspaceptr;539register _JSAMPROW elemptr;540register int elemr;541542workspaceptr = workspace;543for (elemr = 0; elemr < DCTSIZE; elemr++) {544elemptr = sample_data[elemr] + start_col;545#if DCTSIZE == 8 /* unroll the inner loop */546*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);547*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);548*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);549*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);550*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);551*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);552*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);553*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);554#else555{556register int elemc;557for (elemc = DCTSIZE; elemc > 0; elemc--)558*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);559}560#endif561}562}563564565METHODDEF(void)566quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,567FAST_FLOAT *workspace)568{569register FAST_FLOAT temp;570register int i;571register JCOEFPTR output_ptr = coef_block;572573for (i = 0; i < DCTSIZE2; i++) {574/* Apply the quantization and scaling factor */575temp = workspace[i] * divisors[i];576577/* Round to nearest integer.578* Since C does not specify the direction of rounding for negative579* quotients, we have to force the dividend positive for portability.580* The maximum coefficient size is +-16K (for 12-bit data), so this581* code should work for either 16-bit or 32-bit ints.582*/583output_ptr[i] = (JCOEF)((int)(temp + (FAST_FLOAT)16384.5) - 16384);584}585}586587588METHODDEF(void)589forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr,590_JSAMPARRAY sample_data, JBLOCKROW coef_blocks,591JDIMENSION start_row, JDIMENSION start_col,592JDIMENSION num_blocks)593/* This version is used for floating-point DCT implementations. */594{595/* This routine is heavily used, so it's worth coding it tightly. */596my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;597FAST_FLOAT *divisors = fdct->float_divisors[compptr->quant_tbl_no];598FAST_FLOAT *workspace;599JDIMENSION bi;600601602/* Make sure the compiler doesn't look up these every pass */603float_DCT_method_ptr do_dct = fdct->float_dct;604float_convsamp_method_ptr do_convsamp = fdct->float_convsamp;605float_quantize_method_ptr do_quantize = fdct->float_quantize;606workspace = fdct->float_workspace;607608sample_data += start_row; /* fold in the vertical offset once */609610for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {611/* Load data into workspace, applying unsigned->signed conversion */612(*do_convsamp) (sample_data, start_col, workspace);613614/* Perform the DCT */615(*do_dct) (workspace);616617/* Quantize/descale the coefficients, and store into coef_blocks[] */618(*do_quantize) (coef_blocks[bi], divisors, workspace);619}620}621622#endif /* DCT_FLOAT_SUPPORTED */623624625/*626* Initialize FDCT manager.627*/628629GLOBAL(void)630_jinit_forward_dct(j_compress_ptr cinfo)631{632my_fdct_ptr fdct;633int i;634635if (cinfo->data_precision != BITS_IN_JSAMPLE)636ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);637638fdct = (my_fdct_ptr)639(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,640sizeof(my_fdct_controller));641cinfo->fdct = (struct jpeg_forward_dct *)fdct;642fdct->pub.start_pass = start_pass_fdctmgr;643644/* First determine the DCT... */645switch (cinfo->dct_method) {646#ifdef DCT_ISLOW_SUPPORTED647case JDCT_ISLOW:648fdct->pub._forward_DCT = forward_DCT;649#ifdef WITH_SIMD650if (jsimd_can_fdct_islow())651fdct->dct = jsimd_fdct_islow;652else653#endif654fdct->dct = _jpeg_fdct_islow;655break;656#endif657#ifdef DCT_IFAST_SUPPORTED658case JDCT_IFAST:659fdct->pub._forward_DCT = forward_DCT;660#ifdef WITH_SIMD661if (jsimd_can_fdct_ifast())662fdct->dct = jsimd_fdct_ifast;663else664#endif665fdct->dct = _jpeg_fdct_ifast;666break;667#endif668#ifdef DCT_FLOAT_SUPPORTED669case JDCT_FLOAT:670fdct->pub._forward_DCT = forward_DCT_float;671#ifdef WITH_SIMD672if (jsimd_can_fdct_float())673fdct->float_dct = jsimd_fdct_float;674else675#endif676fdct->float_dct = jpeg_fdct_float;677break;678#endif679default:680ERREXIT(cinfo, JERR_NOT_COMPILED);681break;682}683684/* ...then the supporting stages. */685switch (cinfo->dct_method) {686#ifdef DCT_ISLOW_SUPPORTED687case JDCT_ISLOW:688#endif689#ifdef DCT_IFAST_SUPPORTED690case JDCT_IFAST:691#endif692#if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED)693#ifdef WITH_SIMD694if (jsimd_can_convsamp())695fdct->convsamp = jsimd_convsamp;696else697#endif698fdct->convsamp = convsamp;699#ifdef WITH_SIMD700if (jsimd_can_quantize())701fdct->quantize = jsimd_quantize;702else703#endif704fdct->quantize = quantize;705break;706#endif707#ifdef DCT_FLOAT_SUPPORTED708case JDCT_FLOAT:709#ifdef WITH_SIMD710if (jsimd_can_convsamp_float())711fdct->float_convsamp = jsimd_convsamp_float;712else713#endif714fdct->float_convsamp = convsamp_float;715#ifdef WITH_SIMD716if (jsimd_can_quantize_float())717fdct->float_quantize = jsimd_quantize_float;718else719#endif720fdct->float_quantize = quantize_float;721break;722#endif723default:724ERREXIT(cinfo, JERR_NOT_COMPILED);725break;726}727728/* Allocate workspace memory */729#ifdef DCT_FLOAT_SUPPORTED730if (cinfo->dct_method == JDCT_FLOAT)731fdct->float_workspace = (FAST_FLOAT *)732(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,733sizeof(FAST_FLOAT) * DCTSIZE2);734else735#endif736fdct->workspace = (DCTELEM *)737(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,738sizeof(DCTELEM) * DCTSIZE2);739740/* Mark divisor tables unallocated */741for (i = 0; i < NUM_QUANT_TBLS; i++) {742fdct->divisors[i] = NULL;743#ifdef DCT_FLOAT_SUPPORTED744fdct->float_divisors[i] = NULL;745#endif746}747}748749750