Wednesday, December 25, 2024

Lazarus Detect Unicode of keyboard all language

 Detect Unicode Keyboard in Lazarus all Language

Set Windows keyboard and language.

Go to Control Panel > Time & Language > Language & Region > Add a language.
Add Keyboard, language as we want instance Thai, which in this example would use Thai charactor.
Switch to the Thai keyboard layout when testing.
Check Windows Locale and Keyboard
Go to Control Panel > Region:
Under the Formats tab, set the format to Thai.
Under the Administrative tab, set the Language for non-Unicode programs to Thai.


In Lazarus Project before build

Enable Full UTF-8 Support in Lazarus
Go to Project > Project Options > Application.
Ensure Use ANSI code page as UTF-8 is checked.
Set the Font property of Form, Edit1: 
CharSet : set to UNICODE
Font Name to one that supports Thai characters, such as:

* Note: Locale language as we want, for this example use Thai character to be reference



Starting Code

Use unit part:

LazUTF8,LCLProc, LConvEncoding

Create function to convert integer to binary

function IntToBin(Value: LongInt; Digits: Integer): string; var i: Integer; begin 
 Result := ''; 
 for i := Digits - 1 downto 0 do 
  begin 
   if (Value and (1 shl i)) <> 0 then 
   Result := Result + '1' else Result := Result + '0'; 
 end; 
end;

Create Function convert or Decode UTF8 to Unicode

function DecodeUTF8ToUnicode(const Utf8Str: string): LongInt;
var
  Byte1, Byte2, Byte3, Byte4: Byte;
  Len: Integer;
begin
  Result := -1; // Default to invalid
  Len := Length(Utf8Str);

  if Len = 1 then
  begin
    Byte1 := Byte(Utf8Str[1]);
    Result := Byte1; // ASCII or single-byte UTF-8
  end
  else if Len = 2 then
  begin
    Byte1 := Byte(Utf8Str[1]);
    Byte2 := Byte(Utf8Str[2]);
    Result := ((Byte1 and $1F) shl 6) or (Byte2 and $3F);
  end
  else if Len = 3 then
  begin
    Byte1 := Byte(Utf8Str[1]);
    Byte2 := Byte(Utf8Str[2]);
    Byte3 := Byte(Utf8Str[3]);
    Result := ((Byte1 and $0F) shl 12) or ((Byte2 and $3F) shl 6) or (Byte3 and $3F);
  end
  else if Len = 4 then
  begin
    Byte1 := Byte(Utf8Str[1]);
    Byte2 := Byte(Utf8Str[2]);
    Byte3 := Byte(Utf8Str[3]);
    Byte4 := Byte(Utf8Str[4]);
    Result := ((Byte1 and $07) shl 18) or ((Byte2 and $3F) shl 12) or ((Byte3 and $3F) shl 6) or (Byte4 and $3F);
  end;
end;  

Edit1 OnUTF8KeyPress Events

procedure TForm1.Edit1UTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
var
  UnicodeValue: LongInt;
  Utf8Str: string;
begin
  // UTF8Key contains the full UTF-8 character
  Utf8Str := UTF8Key;

  // Decode the Unicode code point
  UnicodeValue := DecodeUTF8ToUnicode(Utf8Str);

  // Display debug information
  //ShowMessage('Key: ' + Utf8Str);
  //ShowMessage('Unicode Value: ' + IntToStr(UnicodeValue));

  // Display Unicode values
  if UnicodeValue > 0 then
  begin
    Declbl.Caption := IntToStr(UnicodeValue);       // Decimal representation
    Hexlbl.Caption := IntToHex(UnicodeValue, 4);    // Hexadecimal representation
    Binlbl.Caption := IntToBin(UnicodeValue, 16);   // Binary representation
  end
  else
  begin
    Declbl.Caption := 'Error';
    Hexlbl.Caption := 'Error';
    Binlbl.Caption := 'Error';
  end;
end;

Debugging Trick

ShowMessage to confirm the contents of Utf8Str and UnicodeValue.

The Result After comply Lazarus project to detect unicode key code all language as below:




Sunday, January 21, 2024

Multiple ControlNets and T2I-Adapters ComfyUI

 Multiple ControlNets and T2I-Adapters ComfyUI

Check Point Name: AOM31A1.safetensors
Prompt:
(solo) girl photograph realistic (flat chest:0.9), (fennec ears:1.0) (fox ears:1.0), (messy hair) blonde hair, blue eyes, standing, serafuku sweater, (brick house) (scenery HDR landscape) (sun clounds) sky, mountains,

Negative Prompt: 
(hands), text, error, cropped, (worst quality:1.2), (low quality:1.2, normal quality, (jpeg artifacts:1.3), signature, watermark, username, blurry, artist name, monochrome, sketch, censorship, censor, (copyright:1.2), extra legs, (forehead mark), (depth of field) (emotionless) (penis)


width 768
height 768
batch_size 1

Seed xxxx
contro_after_generate : Randomize
steps: 12
cfg 6.0
sampler_name: dpmpp_sde
scheduler : normal
denoise: 1.0

vae_name kl-f8-anime2.ckpt



Apply ControlNet: strength = 1

ControlNet Model2: control_scribble.safetensors
Apply ControlNet: strength = 0.8




Result example Multiple ControlNets and T2I-Adapters













Saturday, January 13, 2024

Ancient thai army by Bing Creators

 Ancient thai army by Bing Creators

ทัพไทยโบราณ by Bing Creators

Visualizing History: Crafting the "Ancient Thai Army" Scene with AI Image Creators

Welcome to a special post where we explore the power of readily available AI tools, specifically Bing Image Creator, to bring historical concepts to life. Today's focus is on the striking image, "Ancient Thai Army," which dramatically visualizes a traditional military scene.

While tools like ComfyUI offer deep customization, simpler platforms like Bing Creator excel at rapid prototyping and powerful conceptualization, making historical scenes accessible to all creators. The quality of this image demonstrates the advanced capabilities now common in standard text-to-image models.

📝 Prompt Reconstruction & Style Analysis

The core of this image lies in the precise blend of historical subject matter and dramatic cinematic style. Since Bing Creators uses a text prompt, we need to reconstruct the likely command used to achieve this result.

Recommended Prompt Structure (The Positive Prompt)

The prompt must define the army, the key subject (the elephant), the historical setting, and the dramatic atmosphere.

**SUBJECT:** A massive ancient Thai army marching forward. The main focus is a warrior chieftain riding a powerful war elephant (Chang Suek). The warrior is wearing detailed traditional Thai armor. **SETTING/ATMOSPHERE:** The scene takes place during sunset or sunrise, with dramatic golden light (god rays) streaming through. The background features a large, ancient fort or city wall (like Ayutthaya or Sukhothai era architecture). Dust and smoke fill the air. **STYLE/QUALITY:** Cinematic photo, highly detailed, historical accuracy, epic scale, volumetric lighting, hyper-realistic, 8k, digital painting.

Negative Prompt (Not explicit in Bing, but implied quality goals)

While Bing Creator might handle negative inputs differently, the goal is always to avoid common errors:

(Implicit goal is to avoid: Blur, modern elements, poor anatomy, cartoonish style, lack of detail.)

🎨 Key Elements of Visual Success

The success of the "Ancient Thai Army" image hinges on three critical elements, which you should explain in your blog post to add educational value:

  1. Cinematic Lighting: The dramatic, golden light bursting through the background wall adds an epic, emotional dimension to the scene. This effect is achieved by including keywords like "golden hour," "sunset," and "volumetric lighting" in the prompt.

  2. Historical and Cultural Detail: The model successfully renders Thai historical armor and the iconic war elephant, a tribute to the accuracy and vast training data of modern AI.

  3. Composition and Scale: The low-angle shot and the sheer number of soldiers emphasize the monumental scale of the army, making the image highly impactful.

🚀 Conclusion: Bridging History and AI

The "Ancient Thai Army" image shows that even powerful conceptual images can be generated quickly using tools like Bing Creators. The key is in mastering the language of the prompt to communicate your historical vision effectively. This piece serves as a powerful demonstration of AI's capability to breathe new life into history.

  • What other historical scenes would you like to see visualized? Let us know in the comments below!