<commit_before>{
    fpGUI  -  Free Pascal GUI Toolkit

    Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this
    distribution, for details of the copyright.

    See the file COPYING.modifiedLGPL, included in this distribution,
    for details about redistributing fpGUI.

    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.

    Description:
      BMP format image parser
}


unit fpg_imgfmt_bmp;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  fpg_main;

procedure ReadImage_BMP(img: TfpgImage; bmp: Pointer; bmpsize: longword);
function  LoadImage_BMP(const AFileName: String): TfpgImage;
function  CreateImage_BMP(bmp: Pointer; bmpsize: longword): TfpgImage;


implementation


function CreateImage_BMP(bmp: Pointer; bmpsize: longword): TfpgImage;
begin
  Result := TfpgImage.Create;
  ReadImage_BMP(Result, bmp, bmpsize);
end;

function LoadImage_BMP(const AFileName: String): TfpgImage;
var
  AFile: file of char;
  AImageData: Pointer;
  AImageDataSize: integer;
begin
  Result := nil;
  if not FileExists(AFileName) then
    Exit; //==>

  AssignFile(AFile, AFileName);
  FileMode := fmOpenRead; // read-only
  Reset(AFile);
  AImageDataSize := FileSize(AFile);
  AImageData := nil;
  GetMem(AImageData, AImageDataSize);
  try
    BlockRead(AFile, AImageData^, AImageDataSize);
    Result := TfpgImage.Create;
    ReadImage_BMP(Result, AImageData, AImageDataSize);
  finally
    CloseFile(AFile);
    FreeMem(AImageData);
  end;
end;
<commit_msg>Use unicode enabled types for the BMP loading code.<commit_after>{
    fpGUI  -  Free Pascal GUI Toolkit

    Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this
    distribution, for details of the copyright.

    See the file COPYING.modifiedLGPL, included in this distribution,
    for details about redistributing fpGUI.

    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.

    Description:
      BMP format image parser
}


unit fpg_imgfmt_bmp;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  fpg_base,
  fpg_main;

procedure ReadImage_BMP(img: TfpgImage; bmp: Pointer; bmpsize: longword);
function  LoadImage_BMP(const AFileName: TfpgString): TfpgImage;
function  CreateImage_BMP(bmp: Pointer; bmpsize: longword): TfpgImage;


implementation

uses
  fpg_utils;


function CreateImage_BMP(bmp: Pointer; bmpsize: longword): TfpgImage;
begin
  Result := TfpgImage.Create;
  ReadImage_BMP(Result, bmp, bmpsize);
end;

function LoadImage_BMP(const AFileName: TfpgString): TfpgImage;
var
  AFile: file of char;
  AImageData: Pointer;
  AImageDataSize: integer;
begin
  Result := nil;
  if not fpgFileExists(AFileName) then
    Exit; //==>

  AssignFile(AFile, AFileName);
  FileMode := fmOpenRead; // read-only
  Reset(AFile);
  AImageDataSize := FileSize(AFile);
  AImageData := nil;
  GetMem(AImageData, AImageDataSize);
  try
    BlockRead(AFile, AImageData^, AImageDataSize);
    Result := TfpgImage.Create;
    ReadImage_BMP(Result, AImageData, AImageDataSize);
  finally
    CloseFile(AFile);
    FreeMem(AImageData);
  end;
end;

{'fraction_non_alphanumeric': 0.08418214499700419, 'fraction_numerical': 0.004793289394847214, 'mean_word_length': 4.266561514195583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1185427', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1103, 'n_words': 329}