<commit_before>/*
 *  FatFind
 *  A Diamond application for adipocyte image exploration
 *  Version 1
 *
 *  Copyright (c) 2006, 2010 Carnegie Mellon University
 *  All Rights Reserved.
 *
 *  This software is distributed under the terms of the Eclipse Public
 *  License, Version 1.0 which can be found in the file named LICENSE.
 *  ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS SOFTWARE CONSTITUTES
 *  RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT
 */

package edu.cmu.cs.diamond.fatfind;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.util.List;

import org.freedesktop.cairo.Context;
import org.gnome.gdk.InterpType;
import org.gnome.gdk.Pixbuf;
import org.gnome.gdk.Window;
import org.gnome.gtk.Allocation;
import org.gnome.gtk.Widget;
import org.gnome.pango.FontDescription;
import org.gnome.pango.Layout;

class ProcessedImage {
    public Pixbuf getOriginal() {
        return original;
    }

    public Pixbuf getScaled() {
        return scaled;
    }

    public List<Circle> getCircles() {
        return circles;
    }

    public double getScale() {
        return scale;
    }

    public boolean deleteCircleAtPoint(int x, int y) {
        int index = getCircleIndexAtPoint(x, y);

        if (index == -1) {
            return false;
        } else {
            circles.remove(index);
            updateHitmap();
            widget.queueDraw();
            return true;
        }
    }

    public Circle getCircleAtPoint(int x, int y) {
        int index = getCircleIndexAtPoint(x, y);
        if (index == -1) {
            return null;
        } else {
            return circles.get(index);
        }
    }

    private int getCircleIndexAtPoint(int x, int y) {
        int index = hitmap[y * allocW + x];
        return index;
    }

    final private Pixbuf original;

    final private Widget widget;

    final private Window window;

    private Pixbuf scaled;

    private List<Circle> circles;

    private int hitmap[];

    double scale;

    int allocW;

    int allocH;

    boolean showCircles;

    public static ProcessedImage createBusyImage(Widget widget) {
        return new ProcessedImage(widget, null, null);
    }

    public ProcessedImage(Widget widget, Pixbuf original, List<Circle> circles) {
        this.widget = widget;
        this.original = original;
        this.circles = circles;

        window = widget.getWindow(); // work around refcount bug?

        rescale();
    }

    public void rescale() {
        Allocation a = widget.getAllocation();

        if ((allocW == a.getWidth()) && (allocH == a.getHeight())) {
            return;
        }

        allocW = a.getWidth();
        allocH = a.getHeight();

        if (original == null) {
            return;<commit_msg>Add comment and check for https://bugzilla.gnome.org/show_bug.cgi?id=628348<commit_after>/*
 *  FatFind
 *  A Diamond application for adipocyte image exploration
 *  Version 1
 *
 *  Copyright (c) 2006, 2010 Carnegie Mellon University
 *  All Rights Reserved.
 *
 *  This software is distributed under the terms of the Eclipse Public
 *  License, Version 1.0 which can be found in the file named LICENSE.
 *  ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS SOFTWARE CONSTITUTES
 *  RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT
 */

package edu.cmu.cs.diamond.fatfind;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.util.List;

import org.freedesktop.cairo.Context;
import org.gnome.gdk.InterpType;
import org.gnome.gdk.Pixbuf;
import org.gnome.gdk.Window;
import org.gnome.gtk.Allocation;
import org.gnome.gtk.Widget;
import org.gnome.pango.FontDescription;
import org.gnome.pango.Layout;

class ProcessedImage {
    public Pixbuf getOriginal() {
        return original;
    }

    public Pixbuf getScaled() {
        return scaled;
    }

    public List<Circle> getCircles() {
        return circles;
    }

    public double getScale() {
        return scale;
    }

    public boolean deleteCircleAtPoint(int x, int y) {
        int index = getCircleIndexAtPoint(x, y);

        if (index == -1) {
            return false;
        } else {
            circles.remove(index);
            updateHitmap();
            widget.queueDraw();
            return true;
        }
    }

    public Circle getCircleAtPoint(int x, int y) {
        int index = getCircleIndexAtPoint(x, y);
        if (index == -1) {
            return null;
        } else {
            return circles.get(index);
        }
    }

    private int getCircleIndexAtPoint(int x, int y) {
        int index = hitmap[y * allocW + x];
        return index;
    }

    final private Pixbuf original;

    final private Widget widget;

    final private Window window;

    private Pixbuf scaled;

    private List<Circle> circles;

    private int hitmap[];

    double scale;

    int allocW;

    int allocH;

    boolean showCircles;

    public static ProcessedImage createBusyImage(Widget widget) {
        return new ProcessedImage(widget, null, null);
    }

    public ProcessedImage(Widget widget, Pixbuf original, List<Circle> circles) {
        this.widget = widget;
        this.original = original;
        this.circles = circles;

        // https://bugzilla.gnome.org/show_bug.cgi?id=628348
        window = widget.getWindow();
        if (window == null) {
            throw new IllegalArgumentException("widget must be realized");
        }

        rescale();
    }

    public void rescale() {
        Allocation a = widget.getAllocation();

        if ((allocW == a.getWidth()) && (allocH == a.getHeight())) {
            return;
        }

        allocW = a.getWidth();
        allocH = a.getHeight();

        if (original == null) {
            return;
{'fraction_non_alphanumeric': 0.09714960364311014, 'fraction_numerical': 0.0067465002529937595, 'mean_word_length': 2.36740488358887, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '1784580', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1737, 'n_words': 492}