createURLFromRGBImage (frameData) {
    const {
      frames,
      bitsAllocated,
      pixelRepresentation,
      columns,
      rows
    } = frameData

    const {
      pixelData,
      decodedframeInfo,
      mediaType
    } = this._checkImageTypeAndDecode(frames)

    if (!pixelData && mediaType) {
      // the image is png, just use the source compressed array
      const blob = new Blob([frames], { type: mediaType })// eslint-disable-line
      return window.URL.createObjectURL(blob)
    } else if (pixelData && mediaType && decodedframeInfo) {
      // jp2/jpx/jls/jpeg pixelData is decoded and uncompressed into a RGB image array.
      // put the data in a canvas and return data url
      if (decodedframeInfo.componentCount !== 3) {
        throw new Error(
          'decoded image is not a RGB image'
        )
      }
      const width = decodedframeInfo.width
      const height = decodedframeInfo.height
      const dstBmp = new Uint8ClampedArray(width * height * 4)
      let ptrSrc = 0
      let ptrDst = 0
      const dstLen = dstBmp.length

      while (ptrDst < dstLen) {
        dstBmp[ptrDst++] = pixelData[ptrSrc++]
        dstBmp[ptrDst++] = pixelData[ptrSrc++]
        dstBmp[ptrDst++] = pixelData[ptrSrc++]
        dstBmp[ptrDst++] = 255
      }

      // Create a ImageData object using the typed array:
      const idata = new ImageData(dstBmp, width, height)// eslint-disable-line
      this.tempCanvas.width = width
      this.tempCanvas.height = height
      const ctx = this.tempCanvas.getContext('2d')
      ctx.putImageData(idata, 0, 0)

      return this.tempCanvas.toDataURL('image/png')
    } else {
      // octet-stream RGB image
      let octetPixelData
      const signed = pixelRepresentation === 1
      switch (bitsAllocated) {
        case 8:
          if (signed) {
            octetPixelData = new Int8Array(frames)
          } else {
            octetPixelData = new Uint8Array(frames)
          }
          break
        case 16:
          if (signed) {
            octetPixelData = new Int16Array(frames)
          } else {
            octetPixelData = new Uint16Array(frames)
          }
          break
        default:
          throw new Error(
            'The pixel bit ' + bitsAllocated + 'is not supported by the offscreen render.'
          )
      }

      const width = columns
      const height = rows

      if (octetPixelData.length !== width * height * 3) {
        throw new Error(
          'decoded image is not a RGB image'
        )
      }

      const dstBmp = new Uint8ClampedArray(width * height * 4)
      let ptrSrc = 0
      let ptrDst = 0
      const dstLen = dstBmp.length

      while (ptrDst < dstLen) {
        dstBmp[ptrDst++] = octetPixelData[ptrSrc++]
        dstBmp[ptrDst++] = octetPixelData[ptrSrc++]
        dstBmp[ptrDst++] = octetPixelData[ptrSrc++]
        dstBmp[ptrDst++] = 255
      }

      // Create a ImageData object using the typed array:
      const idata = new ImageData(dstBmp, width, height)// eslint-disable-line
      this.tempCanvas.width = width
      this.tempCanvas.height = height
      const ctx = this.tempCanvas.getContext('2d')
      ctx.putImageData(idata, 0, 0)

      return this.tempCanvas.toDataURL('image/png')
    }
  }
/** Creates image url from raw frames or rendered frame of RGB images.
   * Decodes the image if jpeg (jpegturbo), jp2/jpx (OpenJPEG) or jls (CharLS) and re-econde them into a png data url.
   * If png it just creates a url from a blob.
   * The image type is automatically detected by checking the magic number
   * https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files
   * (see https://github.com/sindresorhus/file-type).
   *
   * @param {object} frameData - interface to pass the frame data to the offscreen render
   * @param {number[]} frameData.frames - compressed image array
   * @param {number} frameData.bitsAllocated - bits per pixel
   * @param {number} frameData.pixelRepresentation - pixel sign
   * @param {number} frameData.columns - horizontal image size
   * @param {number} frameData.rows - vertical image size
   * @returns {boolean} blob.
   *
   */
Creates image url from raw frames or rendered frame of RGB images.
Decodes the image if jpeg (jpegturbo), jp2/jpx (OpenJPEG) or jls (CharLS) and re-econde them into a png data url.
If png it just creates a url from a blob.


Creates image url from raw frames or rendered frame of RGB images . Decodes the image if jpeg ( jpegturbo ) jp2 / jpx ( OpenJPEG ) or jls ( CharLS ) and re - econde them into a png data url . If png it just creates a url from a blob .
createURLFromRGBImage (frameData) {
    const {
      frames,
      bitsAllocated,
      pixelRepresentation,
      columns,
      rows
    } = frameData
    const {
      pixelData,
      decodedframeInfo,
      mediaType
    } = this._checkImageTypeAndDecode(frames)
    if (!pixelData && mediaType) {
      const blob = new Blob([frames], { type: mediaType })
      return window.URL.createObjectURL(blob)
    } else if (pixelData && mediaType && decodedframeInfo) {
      if (decodedframeInfo.componentCount !== 3) {
        throw new Error(
          'decoded image is not a RGB image'
        )
      }
      const width = decodedframeInfo.width
      const height = decodedframeInfo.height
      const dstBmp = new Uint8ClampedArray(width * height * 4)
      let ptrSrc = 0
      let ptrDst = 0
      const dstLen = dstBmp.length
      while (ptrDst < dstLen) {
        dstBmp[ptrDst++] = pixelData[ptrSrc++]
        dstBmp[ptrDst++] = pixelData[ptrSrc++]
        dstBmp[ptrDst++] = pixelData[ptrSrc++]
        dstBmp[ptrDst++] = 255
      }
      const idata = new ImageData(dstBmp, width, height)
      this.tempCanvas.width = width
      this.tempCanvas.height = height
      const ctx = this.tempCanvas.getContext('2d')
      ctx.putImageData(idata, 0, 0)
      return this.tempCanvas.toDataURL('image/png')
    } else {
      let octetPixelData
      const signed = pixelRepresentation === 1
      switch (bitsAllocated) {
        case 8:
          if (signed) {
            octetPixelData = new Int8Array(frames)
          } else {
            octetPixelData = new Uint8Array(frames)
          }
          break
        case 16:
          if (signed) {
            octetPixelData = new Int16Array(frames)
          } else {
            octetPixelData = new Uint16Array(frames)
          }
          break
        default:
          throw new Error(
            'The pixel bit ' + bitsAllocated + 'is not supported by the offscreen render.'
          )
      }
      const width = columns
      const height = rows
      if (octetPixelData.length !== width * height * 3) {
        throw new Error(
          'decoded image is not a RGB image'
        )
      }
      const dstBmp = new Uint8ClampedArray(width * height * 4)
      let ptrSrc = 0
      let ptrDst = 0
      const dstLen = dstBmp.length
      while (ptrDst < dstLen) {
        dstBmp[ptrDst++] = octetPixelData[ptrSrc++]
        dstBmp[ptrDst++] = octetPixelData[ptrSrc++]
        dstBmp[ptrDst++] = octetPixelData[ptrSrc++]
        dstBmp[ptrDst++] = 255
      }
      const idata = new ImageData(dstBmp, width, height)
      this.tempCanvas.width = width
      this.tempCanvas.height = height
      const ctx = this.tempCanvas.getContext('2d')
      ctx.putImageData(idata, 0, 0)
      return this.tempCanvas.toDataURL('image/png')
    }
  }
createURLFromRGBImage ( frameData ) { const { frames , bitsAllocated , pixelRepresentation , columns , rows } = frameData const { pixelData , decodedframeInfo , mediaType } = this . _checkImageTypeAndDecode ( frames ) if ( ! pixelData && mediaType ) { const blob = new Blob ( [ frames ] , { type : mediaType } ) return window . URL . createObjectURL ( blob ) } else if ( pixelData && mediaType && decodedframeInfo ) { if ( decodedframeInfo . componentCount !== 3 ) { throw new Error ( 'decoded image is not a RGB image' ) } const width = decodedframeInfo . width const height = decodedframeInfo . height const dstBmp = new Uint8ClampedArray ( width * height * 4 ) let ptrSrc = 0 let ptrDst = 0 const dstLen = dstBmp . length while ( ptrDst < dstLen ) { dstBmp [ ptrDst ++ ] = pixelData [ ptrSrc ++ ] dstBmp [ ptrDst ++ ] = pixelData [ ptrSrc ++ ] dstBmp [ ptrDst ++ ] = pixelData [ ptrSrc ++ ] dstBmp [ ptrDst ++ ] = 255 } const idata = new ImageData ( dstBmp , width , height ) this . tempCanvas . width = width this . tempCanvas . height = height const ctx = this . tempCanvas . getContext ( '2d' ) ctx . putImageData ( idata , 0 , 0 ) return this . tempCanvas . toDataURL ( 'image/png' ) } else { let octetPixelData const signed = pixelRepresentation === 1 switch ( bitsAllocated ) { case 8 : if ( signed ) { octetPixelData = new Int8Array ( frames ) } else { octetPixelData = new Uint8Array ( frames ) } break case 16 : if ( signed ) { octetPixelData = new Int16Array ( frames ) } else { octetPixelData = new Uint16Array ( frames ) } break default : throw new Error ( 'The pixel bit ' + bitsAllocated + 'is not supported by the offscreen render.' ) } const width = columns const height = rows if ( octetPixelData . length !== width * height * 3 ) { throw new Error ( 'decoded image is not a RGB image' ) } const dstBmp = new Uint8ClampedArray ( width * height * 4 ) let ptrSrc = 0 let ptrDst = 0 const dstLen = dstBmp . length while ( ptrDst < dstLen ) { dstBmp [ ptrDst ++ ] = octetPixelData [ ptrSrc ++ ] dstBmp [ ptrDst ++ ] = octetPixelData [ ptrSrc ++ ] dstBmp [ ptrDst ++ ] = octetPixelData [ ptrSrc ++ ] dstBmp [ ptrDst ++ ] = 255 } const idata = new ImageData ( dstBmp , width , height ) this . tempCanvas . width = width this . tempCanvas . height = height const ctx = this . tempCanvas . getContext ( '2d' ) ctx . putImageData ( idata , 0 , 0 ) return this . tempCanvas . toDataURL ( 'image/png' ) } }
Creates image url from raw frames or rendered frame of RGB images.
Creates image url from raw frames or rendered frame of RGB images .
// the image is png, just use the source compressed array // eslint-disable-line // jp2/jpx/jls/jpeg pixelData is decoded and uncompressed into a RGB image array. // put the data in a canvas and return data url // Create a ImageData object using the typed array: // eslint-disable-line // octet-stream RGB image // Create a ImageData object using the typed array: // eslint-disable-line