<commit_before>/*
    RawSpeed - RAW file decoder.

    Copyright (C) 2009-2010 <NAME>
    Copyright (C) 2014-2015 <NAME>
    Copyright (C) 2017 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "decompressors/SamsungV0Decompressor.h"
#include "common/Common.h"                // for ushort16, uint32, int32
#include "common/Point.h"                 // for iPoint2D
#include "common/RawImage.h"              // for RawImage, RawImageData
#include "decoders/RawDecoderException.h" // for ThrowRDE
#include "io/BitPumpMSB32.h"              // for BitPumpMSB32
#include "io/Buffer.h"                    // for Buffer
#include "io/ByteStream.h"                // for ByteStream
#include "io/Endianness.h"                // for Endianness, Endianness::li...
#include "tiff/TiffEntry.h"               // for TiffEntry
#include "tiff/TiffIFD.h"                 // for TiffIFD
#include "tiff/TiffTag.h"                 // for TiffTag, TiffTag::IMAGELENGTH
#include <algorithm>                      // for max
#include <cassert>                        // for assert

namespace rawspeed {

SamsungV0Decompressor::SamsungV0Decompressor(const RawImage& image,
                                             const TiffIFD* ifd,
                                             const Buffer* file)
    : AbstractSamsungDecompressor(image), raw(ifd), mFile(file) {
  const uint32 width = mRaw->dim.x;
  const uint32 height = mRaw->dim.y;
  if (width == 0 || height == 0 || width < 16 || width > 5546 || height > 3714)
    ThrowRDE("Unexpected image dimensions found: (%u; %u)", width, height);
}

void SamsungV0Decompressor::decompress() {
  const uint32 width = mRaw->dim.x;
  const uint32 height = mRaw->dim.y;

  const uint32 offset = raw->getEntry(STRIPOFFSETS)->getU32();
  uint32 compressed_offset =
      raw->getEntry(static_cast<TiffTag>(40976))->getU32();

  ByteStream bs(mFile, compressed_offset, Endianness::little);

  for (uint32 y = 0; y < height; y++) {
    uint32 line_offset = offset + bs.getI32();
    if (line_offset >= mFile->getSize())
      ThrowRDE("Offset outside image file, file probably truncated.");
    int len[4];
    for (int& i : len)
      i = y < 2 ? 7 : 4;<commit_msg>SamsungV0Decompressor: do respect STRIPBYTECOUNTS.<commit_after>/*
    RawSpeed - RAW file decoder.

    Copyright (C) 2009-2010 <NAME>
    Copyright (C) 2014-2015 <NAME>
    Copyright (C) 2017 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "decompressors/SamsungV0Decompressor.h"
#include "common/Common.h"                // for ushort16, uint32, int32
#include "common/Point.h"                 // for iPoint2D
#include "common/RawImage.h"              // for RawImage, RawImageData
#include "decoders/RawDecoderException.h" // for ThrowRDE
#include "io/BitPumpMSB32.h"              // for BitPumpMSB32
#include "io/Buffer.h"                    // for Buffer
#include "io/ByteStream.h"                // for ByteStream
#include "io/Endianness.h"                // for Endianness, Endianness::li...
#include "tiff/TiffEntry.h"               // for TiffEntry
#include "tiff/TiffIFD.h"                 // for TiffIFD
#include "tiff/TiffTag.h"                 // for TiffTag, TiffTag::IMAGELENGTH
#include <algorithm>                      // for max
#include <cassert>                        // for assert

namespace rawspeed {

SamsungV0Decompressor::SamsungV0Decompressor(const RawImage& image,
                                             const TiffIFD* ifd,
                                             const Buffer* file)
    : AbstractSamsungDecompressor(image), raw(ifd), mFile(file) {
  const uint32 width = mRaw->dim.x;
  const uint32 height = mRaw->dim.y;
  if (width == 0 || height == 0 || width < 16 || width > 5546 || height > 3714)
    ThrowRDE("Unexpected image dimensions found: (%u; %u)", width, height);
}

void SamsungV0Decompressor::decompress() {
  const uint32 width = mRaw->dim.x;
  const uint32 height = mRaw->dim.y;

  const uint32 offset = raw->getEntry(STRIPOFFSETS)->getU32();
  const uint32 count = raw->getEntry(STRIPBYTECOUNTS)->getU32();
  uint32 compressed_offset =
      raw->getEntry(static_cast<TiffTag>(40976))->getU32();

  ByteStream bs(mFile, compressed_offset, count, Endianness::little);

  for (uint32 y = 0; y < height; y++) {
    uint32 line_offset = offset + bs.getI32();
    if (line_offset >= mFile->getSize())
      ThrowRDE("Offset outside image file, file probably truncated.");
    int len[4];
    for (int& i : len)
      i = y < 2 ? 7 : 4;
{'fraction_non_alphanumeric': 0.10242085661080075, 'fraction_numerical': 0.03165735567970205, 'mean_word_length': 2.5313807531380754, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1213768', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1724, 'n_words': 579}