<commit_before>package eu.crowtec.rnpixelcolor;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

import java.io.File;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import fr.bamlab.rnimageresizer.ImageResizer;

import java.io.IOException;


class RNPixelColorModule extends ReactContextBaseJavaModule {
    private Context context;

    public RNPixelColorModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.context = reactContext;
    }

    @Override
    public String getName() {
        return "RNPixelColor";
    }

    @ReactMethod
    public void getHex(String path, ReadableMap options, final Callback callback) {
        Bitmap image;
        if (path.startsWith("data:") || path.startsWith("file:")) {
          image = ImageResizer.loadBitmapFromBase64(path);
        } else {
          Uri imageUrl = Uri.parse(path);
          File file = ImageResizer.getFileFromUri(this.context, imageUrl);
          BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
          bitmapOptions.inJustDecodeBounds = true;
          try {
            image = ImageResizer.loadBitmap(this.context, file.getPath(), bitmapOptions);
          } catch(IOException e){
            callback.invoke("Error parsing bitmap. Error: " + e.getMessage(), null);
            return;
          }
        }

        if (image == null) {
          callback.invoke("Could not create image from given path.", null);
          return;
        }

        int x = (int) options.getDouble("x");
        int y = (int) options.getDouble("y");

        if (options.hasKey("width") && options.hasKey("height")) {
          int scaledWidth = options.getInt("width");
          int scaledHeight = options.getInt("height");

          int originalWidth = image.getWidth();
          int originalHeight = image.getHeight();

          x = x * (originalWidth / scaledWidth);
          y = y * (originalHeight / scaledHeight);

        }

        int color = colorAtPixel(image, x, y);

        callback.invoke(null, colorToHexString(color));<commit_msg>get file from assets<commit_after>package eu.crowtec.rnpixelcolor;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import fr.bamlab.rnimageresizer.ImageResizer;

import java.io.IOException;


class RNPixelColorModule extends ReactContextBaseJavaModule {
    private Context context;

    public RNPixelColorModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.context = reactContext;
    }

    @Override
    public String getName() {
        return "RNPixelColor";
    }

    @ReactMethod
    public void getHex(String path, ReadableMap options, final Callback callback) {
        Bitmap image;
        if (path.startsWith("data:") || path.startsWith("file:")) {
          image = ImageResizer.loadBitmapFromBase64(path);
        } else {

          try {
              InputStream istr = reactContext.getAssets().open(path);
              image = BitmapFactory.decodeStream(istr);
          } catch (IOException e) {
              // handle exception
              Log.e(TAG, "Error loading Bitmap");
          }
        }

        if (image == null) {
          callback.invoke("Could not create image from given path.", null);
          return;
        }

        int x = (int) options.getDouble("x");
        int y = (int) options.getDouble("y");

        if (options.hasKey("width") && options.hasKey("height")) {
          int scaledWidth = options.getInt("width");
          int scaledHeight = options.getInt("height");

          int originalWidth = image.getWidth();
          int originalHeight = image.getHeight();

          x = x * (originalWidth / scaledWidth);
          y = y * (originalHeight / scaledHeight);

        }

        int color = colorAtPixel(image, x, y);

        callback.invoke(null, colorToHexString(color));
{'fraction_non_alphanumeric': 0.10817941952506596, 'fraction_numerical': 0.0008795074758135445, 'mean_word_length': 2.8035117056856187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1464329', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1227, 'n_words': 274}