128 lines
4.2 KiB
Markdown
128 lines
4.2 KiB
Markdown
|
|
## hcie-draw Projesi Nedir?
|
|||
|
|
|
|||
|
|
**hcie-draw**, HCIE (HC Image Editor) Rust port'unun bir parçası olan **raster çizim motoru** kütüphanesidir.
|
|||
|
|
|
|||
|
|
### Projenin Amacı
|
|||
|
|
Bu kütüphane, RGBA piksel buffer'ları üzerine **vektörel çizim araçlarını** (çizgi, daire, elips, dikdörten, flood fill) ve **fırça darbelerini** (pressure-aware brush strokes) rasterize eder. Pure Rust ile yazılmış, GUI'den bağımsız bir çekirdek kütüphane.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Mimari Yapı (Katman Bakışı)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────┐
|
|||
|
|
│ hcie-core-app (Tauri GUI) │ ← Svelte frontend + Rust backend
|
|||
|
|
├─────────────────────────────┤
|
|||
|
|
│ hcie-engine-api │ ← Public API & command bridge
|
|||
|
|
├─────────────────────────────┤
|
|||
|
|
│ hcie-draw (bu crate) │ ← Rasterization motoru
|
|||
|
|
│ ├─ Layer │ • Pixel buffer yönetimi
|
|||
|
|
│ ├─ draw_line/circle/ellipse│ • Primitif çizim fonksiyonları
|
|||
|
|
│ ├─ draw_brush_stroke │ • Pressure-aware fırça
|
|||
|
|
│ └─ C FFI exports │ • Zero-copy native arayüz
|
|||
|
|
├─────────────────────────────┤
|
|||
|
|
│ hcie-blend │ ← Blend modları (Normal, Multiply, vb.)
|
|||
|
|
│ hcie-brush-engine │ ← Fırça tipi, spacing, jitter
|
|||
|
|
└─────────────────────────────┘
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Ana Bileşenler
|
|||
|
|
|
|||
|
|
**`Layer` struct'ı:**
|
|||
|
|
```rust
|
|||
|
|
pub struct Layer {
|
|||
|
|
pub name: String,
|
|||
|
|
pub pixels: Vec<u8>, // RGBA format (4 bayt/piksel)
|
|||
|
|
pub width: u32,
|
|||
|
|
pub height: u32,
|
|||
|
|
pub visible: bool,
|
|||
|
|
pub opacity: f32,
|
|||
|
|
pub dirty: bool, // Render invalidation flag
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Çizim fonksiyonları:**
|
|||
|
|
| Fonksiyon | Açıklama |
|
|||
|
|
|-----------|----------|
|
|||
|
|
| `draw_line()` | Xiaolin Wu algoritmasıyla AA çizgi |
|
|||
|
|
| `draw_filled_circle()` | Doldurulmuş daire (kenar geçişli) |
|
|||
|
|
| `draw_filled_rect()` | Doldurulmuş dikdörtgen |
|
|||
|
|
| `draw_filled_ellipse()` | Doldurulmuş elips |
|
|||
|
|
| `flood_fill()` | Bağlamsız renk değiştirme |
|
|||
|
|
| `draw_brush_stamp()` | Tek fırça dampası |
|
|||
|
|
| `draw_brush_stroke()` | Tüm noktalar boyunca fırça izi |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Çalışma Mantığı
|
|||
|
|
|
|||
|
|
1. **Piksel Erişimi**: `get_pixel()` / `set_pixel()` ile RGBA okuma-yazma
|
|||
|
|
2. **Blend Entegrasyonu**: `hcie_blend::blend_pixels()` ile renk karıştırma
|
|||
|
|
3. **Brush Entegrasyonu**: `hcie_brush_engine::draw_dab_capped()` ile fırça tipi uygulama
|
|||
|
|
4. **Mask Desteği**: Opsiyonel selection mask (0-255) ile çizim sınırlandırma
|
|||
|
|
|
|||
|
|
**Pressure-aware brush stroke akışı:**
|
|||
|
|
```
|
|||
|
|
Input: points = [(x, y, pressure), ...]
|
|||
|
|
↓
|
|||
|
|
brush_spacing_pixels() → spacing hesapla
|
|||
|
|
↓
|
|||
|
|
Her segment için interpolate → pressure değişimi
|
|||
|
|
↓
|
|||
|
|
jitter_offset() → pozisyon rastgelelik
|
|||
|
|
↓
|
|||
|
|
draw_dab_capped() → fırça dampası render et
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### C FFI Arayüzü
|
|||
|
|
|
|||
|
|
Kütüphane **cdylib** olarak derlenir, bu sayede başka dillerden doğrudan çağrılabilir:
|
|||
|
|
|
|||
|
|
```c
|
|||
|
|
// draw_line_c - raw buffer pointer alır, in-place değiştirir
|
|||
|
|
void draw_line_c(
|
|||
|
|
uint8_t* pixels, uint32_t width, uint32_t height,
|
|||
|
|
float x0, float y0, float x1, float y1,
|
|||
|
|
const uint8_t* color_rgba, float line_thickness,
|
|||
|
|
const uint8_t* mask
|
|||
|
|
);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
Diğer FFI fonksiyonları: `draw_filled_rect_c`, `draw_filled_circle_c`, `flood_fill_c`, `draw_brush_stroke_c`
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Kullanım Örkeli
|
|||
|
|
|
|||
|
|
Test runner'ı çalıştırmak:
|
|||
|
|
```bash
|
|||
|
|
cargo test --manifest-path tests/draw_pixels.rs
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
GUI testörünü çalıştırmak:
|
|||
|
|
```bash
|
|||
|
|
cargo run --example draw_tester
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Bağımlılıklar
|
|||
|
|
|
|||
|
|
```toml
|
|||
|
|
[dependencies]
|
|||
|
|
hcie-blend = { path = "../hcie-blend" } # blend_pixels
|
|||
|
|
hcie-brush-engine = { path = "../hcie-brush-engine" } # brush tip & spacing
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Özellikler
|
|||
|
|
|
|||
|
|
- **Zero-copy FFI**: Buffer kopyası yok, doğrudan pointer manipülasyonu
|
|||
|
|
- **GUI bağımsız**: Pure Rust, egui/tauri olmadan da kullanılabilir
|
|||
|
|
- **Multi-threading hazır**: rayon entegrasyonu (blend katmanında)
|
|||
|
|
- **30+ fırça stıl**: BrushStyle enum'ı içinde (Round, Pencil, Oil, Watercolor, vb.)
|