mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Move NativeImageDecoder
into a separate file, and convert it to a class
Given the size of the `src/core/evaluator.js` file, it cannot hurt to move some of its (image related) helper functionality into a separate file.
This commit is contained in:
parent
e41c4aece4
commit
2665502055
2 changed files with 87 additions and 62 deletions
|
@ -20,7 +20,6 @@ import {
|
|||
UNSUPPORTED_FEATURES, Util, warn
|
||||
} from '../shared/util';
|
||||
import { CMapFactory, IdentityCMap } from './cmap';
|
||||
import { DecodeStream, Stream } from './stream';
|
||||
import {
|
||||
Dict, isCmd, isDict, isEOF, isName, isRef, isStream, Name
|
||||
} from './primitives';
|
||||
|
@ -41,12 +40,14 @@ import { getTilingPatternIR, Pattern } from './pattern';
|
|||
import { Lexer, Parser } from './parser';
|
||||
import { bidi } from './bidi';
|
||||
import { ColorSpace } from './colorspace';
|
||||
import { DecodeStream } from './stream';
|
||||
import { getGlyphsUnicode } from './glyphlist';
|
||||
import { getLookupTableFactory } from './core_utils';
|
||||
import { getMetrics } from './metrics';
|
||||
import { isPDFFunction } from './function';
|
||||
import { JpegStream } from './jpeg_stream';
|
||||
import { MurmurHash3_64 } from './murmurhash3';
|
||||
import { NativeImageDecoder } from './image_utils';
|
||||
import { OperatorList } from './operator_list';
|
||||
import { PDFImage } from './image';
|
||||
|
||||
|
@ -60,67 +61,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
isEvalSupported: true,
|
||||
};
|
||||
|
||||
function NativeImageDecoder({ xref, resources, handler,
|
||||
forceDataSchema = false,
|
||||
pdfFunctionFactory, }) {
|
||||
this.xref = xref;
|
||||
this.resources = resources;
|
||||
this.handler = handler;
|
||||
this.forceDataSchema = forceDataSchema;
|
||||
this.pdfFunctionFactory = pdfFunctionFactory;
|
||||
}
|
||||
NativeImageDecoder.prototype = {
|
||||
canDecode(image) {
|
||||
return image instanceof JpegStream &&
|
||||
NativeImageDecoder.isDecodable(image, this.xref, this.resources,
|
||||
this.pdfFunctionFactory);
|
||||
},
|
||||
decode(image) {
|
||||
// For natively supported JPEGs send them to the main thread for decoding.
|
||||
var dict = image.dict;
|
||||
var colorSpace = dict.get('ColorSpace', 'CS');
|
||||
colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources,
|
||||
this.pdfFunctionFactory);
|
||||
|
||||
return this.handler.sendWithPromise('JpegDecode', [
|
||||
image.getIR(this.forceDataSchema), colorSpace.numComps
|
||||
]).then(function({ data, width, height, }) {
|
||||
return new Stream(data, 0, data.length, image.dict);
|
||||
});
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Checks if the image can be decoded and displayed by the browser without any
|
||||
* further processing such as color space conversions.
|
||||
*/
|
||||
NativeImageDecoder.isSupported = function(image, xref, res,
|
||||
pdfFunctionFactory) {
|
||||
var dict = image.dict;
|
||||
if (dict.has('DecodeParms') || dict.has('DP')) {
|
||||
return false;
|
||||
}
|
||||
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
||||
pdfFunctionFactory);
|
||||
// isDefaultDecode() of DeviceGray and DeviceRGB needs no `bpc` argument.
|
||||
return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
|
||||
cs.isDefaultDecode(dict.getArray('Decode', 'D'));
|
||||
};
|
||||
/**
|
||||
* Checks if the image can be decoded by the browser.
|
||||
*/
|
||||
NativeImageDecoder.isDecodable = function(image, xref, res,
|
||||
pdfFunctionFactory) {
|
||||
var dict = image.dict;
|
||||
if (dict.has('DecodeParms') || dict.has('DP')) {
|
||||
return false;
|
||||
}
|
||||
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
||||
pdfFunctionFactory);
|
||||
const bpc = dict.get('BitsPerComponent', 'BPC') || 1;
|
||||
return (cs.numComps === 1 || cs.numComps === 3) &&
|
||||
cs.isDefaultDecode(dict.getArray('Decode', 'D'), bpc);
|
||||
};
|
||||
|
||||
function PartialEvaluator({ pdfManager, xref, handler, pageIndex, idFactory,
|
||||
fontCache, builtInCMapCache, options = null,
|
||||
pdfFunctionFactory, }) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue