<commit_before>package nme.display;
#if (cpp || neko)


import haxe.io.Bytes;
import nme.geom.Rectangle;
import nme.geom.Point;
import nme.geom.Matrix;
import nme.geom.ColorTransform;
import nme.utils.ByteArray;


/**
* @author   <NAME>
* @author   <NAME>
* @todo getPixel, getPixel32 should be optimized to use library methods
*/
class BitmapData implements IBitmapDrawable
{
   public var width(nmeGetWidth,null):Int;
   public var height(nmeGetHeight,null):Int;
   public var rect(nmeGetRect,null) : nme.geom.Rectangle;
   public var transparent(nmeGetTransparent,null) : Bool;

   public static var TRANSPARENT = 0x0001;
   public static var HARDWARE    = 0x0002;

   public inline static var CLEAR = createColor(0,0);
   public inline static var BLACK = createColor(0x000000);
   public inline static var WHITE =  createColor(0x000000);
   public inline static var RED =  createColor(0xff0000);
   public inline static var GREEN =  createColor(0x00ff00);
   public inline static var BLUE =  createColor(0x0000ff);

   // Public, but only use if you know what you are doing
   public var nmeHandle:Dynamic;

   public inline static var PNG = "png";
   public inline static var JPG = "jpg";


   public function new(inWidth:Int, inHeight:Int,
                  inTransparent:Bool=true,
                  ?inFillRGBA:BitmapInt32 )
   {
      var fill_col:Int;
      var fill_alpha:Int;

      if (inFillRGBA==null)
      {
         fill_col = 0xffffff;
         fill_alpha = 0xff;
      }
      else
      {
         fill_col = extractColor(inFillRGBA);
         fill_alpha = extractAlpha(inFillRGBA);
      }

      if (inWidth<1 || inHeight<1) {
         nmeHandle = null;
      }
      else
      {
         var flags = HARDWARE;
         if (inTransparent)
            flags |= TRANSPARENT;
         nmeHandle = nme_bitmap_data_create(inWidth,inHeight,flags,fill_col,fill_alpha);
      }
   }

   /**
   * Load from a file path
   *
   * @param inFilename Full or relative path to image file
   * @return New BitmapData instance representing file
   **/
   
   static var format_8888:Int = 0;
   static var format_FF4444:Int = 1; //Due to the iOS loader premultiplying alpha - you can't 
   static var format_4444:Int = 2; //Placeholder - will switch this on when we use libpng for all
 
   static public function load(inFilename:String, format:Int = 0) : BitmapData
   {
      var result = new BitmapData(0,0);
      result.nmeHandle = nme_bitmap_data_load(inFilename, format);
      return result;
   }

   /**
   * Create BitmapData from a compressed image stream.
   * PNG & JPG supported on all platforms.
   *
   * @param inBytes - A buffer of compressed image data
   * @param inAlpha - optional alpha values to go with image RGB values - there should
   *                   be width*height values.
   **/
   static public function loadFromBytes(inBytes:nme.utils.ByteArray, ?inRawAlpha:nme.utils.ByteArray)
   {
      var result = new BitmapData(0,0);
      result.nmeHandle = nme_bitmap_data_from_bytes( inBytes,inRawAlpha );
      return result;
   }

   // Same as above, except uses haxe.ioBytes
   static public function loadFromHaxeBytes(inBytes:haxe.io.Bytes, ?inRawAlpha:haxe.io.Bytes)<commit_msg>Made pixel formats public, renamed them to more closely match other constants in BitmapData, also renamed FF4444 to 4444_PADDED (FF4444 was unclear and technically wrong).<commit_after>package nme.display;
#if (cpp || neko)


import haxe.io.Bytes;
import nme.geom.Rectangle;
import nme.geom.Point;
import nme.geom.Matrix;
import nme.geom.ColorTransform;
import nme.utils.ByteArray;


/**
* @author   <NAME>
* @author   <NAME>
* @todo getPixel, getPixel32 should be optimized to use library methods
*/
class BitmapData implements IBitmapDrawable
{
   public var width(nmeGetWidth,null):Int;
   public var height(nmeGetHeight,null):Int;
   public var rect(nmeGetRect,null) : nme.geom.Rectangle;
   public var transparent(nmeGetTransparent,null) : Bool;

   public static var TRANSPARENT = 0x0001;
   public static var HARDWARE    = 0x0002;

   public inline static var CLEAR = createColor(0,0);
   public inline static var BLACK = createColor(0x000000);
   public inline static var WHITE =  createColor(0x000000);
   public inline static var RED =  createColor(0xff0000);
   public inline static var GREEN =  createColor(0x00ff00);
   public inline static var BLUE =  createColor(0x0000ff);

   // Public, but only use if you know what you are doing
   public var nmeHandle:Dynamic;

   public inline static var PNG = "png";
   public inline static var JPG = "jpg";


   public function new(inWidth:Int, inHeight:Int,
                  inTransparent:Bool=true,
                  ?inFillRGBA:BitmapInt32 )
   {
      var fill_col:Int;
      var fill_alpha:Int;

      if (inFillRGBA==null)
      {
         fill_col = 0xffffff;
         fill_alpha = 0xff;
      }
      else
      {
         fill_col = extractColor(inFillRGBA);
         fill_alpha = extractAlpha(inFillRGBA);
      }

      if (inWidth<1 || inHeight<1) {
         nmeHandle = null;
      }
      else
      {
         var flags = HARDWARE;
         if (inTransparent)
            flags |= TRANSPARENT;
         nmeHandle = nme_bitmap_data_create(inWidth,inHeight,flags,fill_col,fill_alpha);
      }
   }

   /**
   * Load from a file path
   *
   * @param inFilename Full or relative path to image file
   * @return New BitmapData instance representing file
   **/
   
   public static var FORMAT_8888:Int = 0;
   public static var FORMAT_4444_PADDED:Int = 1; //Due to the iOS loader premultiplying alpha - you can't 
   public static var FORMAT_4444:Int = 2; //Placeholder - will switch this on when we use libpng for all
 
   static public function load(inFilename:String, format:Int = 0) : BitmapData
   {
      var result = new BitmapData(0,0);
      result.nmeHandle = nme_bitmap_data_load(inFilename, format);
      return result;
   }

   /**
   * Create BitmapData from a compressed image stream.
   * PNG & JPG supported on all platforms.
   *
   * @param inBytes - A buffer of compressed image data
   * @param inAlpha - optional alpha values to go with image RGB values - there should
   *                   be width*height values.
   **/
   static public function loadFromBytes(inBytes:nme.utils.ByteArray, ?inRawAlpha:nme.utils.ByteArray)
   {
      var result = new BitmapData(0,0);
      result.nmeHandle = nme_bitmap_data_from_bytes( inBytes,inRawAlpha );
      return result;
   }

   // Same as above, except uses haxe.ioBytes
   static public function loadFromHaxeBytes(inBytes:haxe.io.Bytes, ?inRawAlpha:haxe.io.Bytes)
{'fraction_non_alphanumeric': 0.08592570220477197, 'fraction_numerical': 0.02265176683781335, 'mean_word_length': 2.939916716240333, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '484407', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2058, 'n_words': 600}