示例#1
0
void LJpegPlain::decodeScan() {
  // If image attempts to decode beyond the image bounds, strip it.
  if ((frame.w * frame.cps + offX * mRaw->getCpp()) > mRaw->dim.x * mRaw->getCpp())
    skipX = ((frame.w * frame.cps + offX * mRaw->getCpp()) - mRaw->dim.x * mRaw->getCpp()) / frame.cps;
  if (frame.h + offY > (uint32)mRaw->dim.y)
    skipY = frame.h + offY - mRaw->dim.y;

  _RPT1(0,"SlicesW:0x%x,\n",&slicesW);
  _RPT1(0,"Slices:%d\n",slicesW.size());

  if (slicesW.empty())
    slicesW.push_back(frame.w*frame.cps);

  if ( 0 == frame.h || 0 == frame.w)
    ThrowRDE("LJpegPlain::decodeScan: Image width or height set to zero");

  for (uint32 i = 0; i < frame.cps;  i++) {
    if (frame.compInfo[i].superH != 1 || frame.compInfo[i].superV != 1) {
      if (mRaw->isCFA)
        ThrowRDE("LJpegDecompressor::decodeScan: Cannot decode subsampled image to CFA data");

      if (mRaw->getCpp() != frame.cps)
        ThrowRDE("LJpegDecompressor::decodeScan: Subsampled component count does not match image.");

      if (pred == 1) {
        if (frame.compInfo[0].superH == 2 && frame.compInfo[0].superV == 2 &&
            frame.compInfo[1].superH == 1 && frame.compInfo[1].superV == 1 &&
            frame.compInfo[2].superH == 1 && frame.compInfo[2].superV == 1) {
          // Something like Cr2 sRaw1, use fast decoder
          decodeScanLeft4_2_0();
          return;
        } else if (frame.compInfo[0].superH == 2 && frame.compInfo[0].superV == 1 &&
                   frame.compInfo[1].superH == 1 && frame.compInfo[1].superV == 1 &&
                   frame.compInfo[2].superH == 1 && frame.compInfo[2].superV == 1) {
          // Something like Cr2 sRaw2, use fast decoder
          decodeScanLeft4_2_2();
          return;
        } else {
          decodeScanLeftGeneric();
          return;
        }
      } else {
        ThrowRDE("LJpegDecompressor::decodeScan: Unsupported prediction direction.");
      }
    }
  }

  if (pred == 1) {
    if (frame.cps == 2)
      decodeScanLeft2Comps();
    else if (frame.cps == 3)
      decodeScanLeft3Comps();
    else if (frame.cps == 4)
      decodeScanLeft4Comps();
    else
      ThrowRDE("LJpegDecompressor::decodeScan: Unsupported component direction count.");
    return;
  }
  ThrowRDE("LJpegDecompressor::decodeScan: Unsupported prediction direction.");
}
示例#2
0
void LJpegPlain::decodeScan() {

  // Fix for Canon 6D mRaw, which has flipped width & height for some part of the image
  // We temporarily swap width and height for cropping.
  if (mCanonFlipDim) {
    uint32 w = frame.w;
    frame.w = frame.h;
    frame.h = w;
  }

  // If image attempts to decode beyond the image bounds, strip it.
  if ((frame.w * frame.cps + offX * mRaw->getCpp()) > mRaw->dim.x * mRaw->getCpp())
    skipX = ((frame.w * frame.cps + offX * mRaw->getCpp()) - mRaw->dim.x * mRaw->getCpp()) / frame.cps;
  if (frame.h + offY > (uint32)mRaw->dim.y)
    skipY = frame.h + offY - mRaw->dim.y;

  // Swap back (see above)
  if (mCanonFlipDim) {
    uint32 w = frame.w;
    frame.w = frame.h;
    frame.h = w;
  }

  /* Correct wrong slice count (Canon G16) */
  if (slicesW.size() == 1)
    slicesW[0] = frame.w * frame.cps;

 if (slicesW.empty())
    slicesW.push_back(frame.w*frame.cps);

  if ( 0 == frame.h || 0 == frame.w)
    ThrowRDE("LJpegPlain::decodeScan: Image width or height set to zero");

  for (uint32 i = 0; i < frame.cps;  i++) {
    if (frame.compInfo[i].superH != 1 || frame.compInfo[i].superV != 1) {
      if (mRaw->isCFA)
        ThrowRDE("LJpegDecompressor::decodeScan: Cannot decode subsampled image to CFA data");

      if (mRaw->getCpp() != frame.cps)
        ThrowRDE("LJpegDecompressor::decodeScan: Subsampled component count does not match image.");

      if (pred == 1) {
        if (frame.compInfo[0].superH == 2 && frame.compInfo[0].superV == 2 &&
            frame.compInfo[1].superH == 1 && frame.compInfo[1].superV == 1 &&
            frame.compInfo[2].superH == 1 && frame.compInfo[2].superV == 1) {
          // Something like Cr2 sRaw1, use fast decoder
          decodeScanLeft4_2_0();
          return;
        } else if (frame.compInfo[0].superH == 2 && frame.compInfo[0].superV == 1 &&
                   frame.compInfo[1].superH == 1 && frame.compInfo[1].superV == 1 &&
                   frame.compInfo[2].superH == 1 && frame.compInfo[2].superV == 1) {
          // Something like Cr2 sRaw2, use fast decoder
          if (mCanonFlipDim)
            ThrowRDE("LJpegDecompressor::decodeScan: Cannot flip non 4:2:2 subsampled images.");
          decodeScanLeft4_2_2();
          return;
        } else {
          ThrowRDE("LJpegDecompressor::decodeScan: Unsupported subsampling");
          decodeScanLeftGeneric();
          return;
        }
      } else {
        ThrowRDE("LJpegDecompressor::decodeScan: Unsupported prediction direction.");
      }
    }
  }

  if (pred == 1) {
    if (mCanonFlipDim)
      ThrowRDE("LJpegDecompressor::decodeScan: Cannot flip non subsampled images.");

    if (frame.cps == 2)
      decodeScanLeft2Comps();
    else if (frame.cps == 3)
      decodeScanLeft3Comps();
    else if (frame.cps == 4)
      decodeScanLeft4Comps();
    else
      ThrowRDE("LJpegDecompressor::decodeScan: Unsupported component direction count.");
    return;
  }
  ThrowRDE("LJpegDecompressor::decodeScan: Unsupported prediction direction.");
}