<commit_before>//
// QTReader.java
//

/*
LOCI Bio-Formats package for reading and converting biological file formats.
Copyright (C) 2005-2006 <NAME>, <NAME> and <NAME>.

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

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.formats;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.ByteArrayInputStream;
import java.util.Vector;
import javax.imageio.ImageIO;

/**
 * QTReader is the file format reader for QuickTime movie files.
 * It does not require any external libraries to be installed.
 *
 * Additional video codecs will be added as time permits.
 *
 * @author <NAME> linkert at cs.wisc.edu
 */
public class QTReader extends FormatReader {

  // -- Constants --

  /** List of identifiers for each container atom. */
  private static final String[] CONTAINER_TYPES = {
    "moov", "trak", "udta", "tref", "imap", "mdia", "minf", "stbl", "edts",
    "mdra", "rmra", "imag", "vnrp", "dinf"
  };


  // -- Fields --

  /** Current file. */
  private RandomAccessFile in;

  /** Flag indicating whether the current file is little endian. */
  private boolean little = false;

  /** Number of images in the file. */
  private int numImages;

  /** Pixel data stored in "mdat" atom. */
  private byte[] pixels;

  /** Width of a single plane. */
  private int width;

  /** Height of a single plane. */
  private int height;

  /** Pixel depth. */
  private int bitsPerPixel;

  /** Raw plane size, in bytes. */
  private int rawSize;

  /** Offsets to each plane's pixel data. */
  private Vector offsets;

  /** Pixel data for the previous image plane. */
  private byte[] prevPixels;

  /** Video codec used by this movie. */
  private String codec;

  /** An instance of the old QuickTime reader, in case this one fails. */
  private LegacyQTReader legacy;

  /** Amount to subtract from each offset. */
  private int scale;

  // -- Constructor --

  /** Constructs a new QuickTime reader. */
  public QTReader() { super("QuickTime", "mov"); }


  // -- FormatReader API methods --

  /** Checks if the given block is a valid header for a QuickTime file. */
  public boolean isThisType(byte[] block) {
    return false;
  }

  /** Determines the number of images in the given QuickTime file. */
  public int getImageCount(String id) throws FormatException, IOException {
    if(!id.equals(currentId)) initFile(id);
    return numImages;
  }

  /** Obtains the specified image from the given QuickTime file. */
  public BufferedImage open(String id, int no)
    throws FormatException, IOException
  {
    if (!id.equals(currentId)) initFile(id);
    if (no < 0 || no >= getImageCount(id)) {
      throw new FormatException("Invalid image number: " + no);
    }
    if (!codec.equals("raw ") && !codec.equals("rle ") &&
      !codec.equals("jpeg"))
    {
      if (legacy == null) legacy = new LegacyQTReader();
      return legacy.open(id, no);
    }

    int offset = ((Integer) offsets.get(no)).intValue();
    int nextOffset = pixels.length;

    if (no == 0) {
      scale = offset;
    }

    offset -= scale;

    if (no < offsets.size() - 1) {
      nextOffset = ((Integer) offsets.get(no+1)).intValue();
      nextOffset -= scale;
    }

    byte[] pixs = new byte[nextOffset - offset];

    for (int i=0; i<pixs.length; i++) {
      pixs[i] = pixels[offset + i];
    }

    byte[] bytes = uncompress(pixs, codec);<commit_msg>Add debugging statement identifying unsupported codec.<commit_after>//
// QTReader.java
//

/*
LOCI Bio-Formats package for reading and converting biological file formats.
Copyright (C) 2005-2006 <NAME>, <NAME> and <NAME>.

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

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.formats;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.ByteArrayInputStream;
import java.util.Vector;
import javax.imageio.ImageIO;

/**
 * QTReader is the file format reader for QuickTime movie files.
 * It does not require any external libraries to be installed.
 *
 * Additional video codecs will be added as time permits.
 *
 * @author <NAME> linkert at cs.wisc.edu
 */
public class QTReader extends FormatReader {

  // -- Constants --

  /** List of identifiers for each container atom. */
  private static final String[] CONTAINER_TYPES = {
    "moov", "trak", "udta", "tref", "imap", "mdia", "minf", "stbl", "edts",
    "mdra", "rmra", "imag", "vnrp", "dinf"
  };


  // -- Fields --

  /** Current file. */
  private RandomAccessFile in;

  /** Flag indicating whether the current file is little endian. */
  private boolean little = false;

  /** Number of images in the file. */
  private int numImages;

  /** Pixel data stored in "mdat" atom. */
  private byte[] pixels;

  /** Width of a single plane. */
  private int width;

  /** Height of a single plane. */
  private int height;

  /** Pixel depth. */
  private int bitsPerPixel;

  /** Raw plane size, in bytes. */
  private int rawSize;

  /** Offsets to each plane's pixel data. */
  private Vector offsets;

  /** Pixel data for the previous image plane. */
  private byte[] prevPixels;

  /** Video codec used by this movie. */
  private String codec;

  /** An instance of the old QuickTime reader, in case this one fails. */
  private LegacyQTReader legacy;

  /** Amount to subtract from each offset. */
  private int scale;


  // -- Constructor --

  /** Constructs a new QuickTime reader. */
  public QTReader() { super("QuickTime", "mov"); }


  // -- FormatReader API methods --

  /** Checks if the given block is a valid header for a QuickTime file. */
  public boolean isThisType(byte[] block) {
    return false;
  }

  /** Determines the number of images in the given QuickTime file. */
  public int getImageCount(String id) throws FormatException, IOException {
    if(!id.equals(currentId)) initFile(id);
    return numImages;
  }

  /** Obtains the specified image from the given QuickTime file. */
  public BufferedImage open(String id, int no)
    throws FormatException, IOException
  {
    if (!id.equals(currentId)) initFile(id);
    if (no < 0 || no >= getImageCount(id)) {
      throw new FormatException("Invalid image number: " + no);
    }
    if (!codec.equals("raw ") && !codec.equals("rle ") &&
      !codec.equals("jpeg"))
    {
      if (DEBUG) {
        System.out.println("Unsupported codec (" +
          codec + "); using QTJava reader");
      }
      if (legacy == null) legacy = new LegacyQTReader();
      return legacy.open(id, no);
    }

    int offset = ((Integer) offsets.get(no)).intValue();
    int nextOffset = pixels.length;

    if (no == 0) {
      scale = offset;
    }

    offset -= scale;

    if (no < offsets.size() - 1) {
      nextOffset = ((Integer) offsets.get(no+1)).intValue();
      nextOffset -= scale;
    }

    byte[] pixs = new byte[nextOffset - offset];

    for (int i=0; i<pixs.length; i++) {
      pixs[i] = pixels[offset + i];
    }

    byte[] bytes = uncompress(pixs, codec);
{'fraction_non_alphanumeric': 0.11813885859687387, 'fraction_numerical': 0.006785411365564037, 'mean_word_length': 3.0780632411067192, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '328293', 'n_tokens_mistral': 2542, 'n_tokens_neox': 2377, 'n_words': 948}