lightdrift-libraw 1.0.0-alpha.2 → 1.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,8 @@ A high-performance Node.js Native Addon for processing RAW image files using the
20
20
  - ✅ **AI-Powered Settings** - 🆕 Automatic quality optimization based on image analysis
21
21
  - ✅ **Memory Operations** - Process images entirely in memory
22
22
  - ✅ **Multiple Output Formats** - PPM, TIFF, JPEG with advanced compression options
23
+ - ✅ **Buffer Creation API** - 🆕 Create image buffers directly in memory (JPEG, PNG, WebP, AVIF, TIFF, PPM, Thumbnails)
24
+ - ✅ **Stream-based Processing** - 🆕 Return data streams instead of writing to files
23
25
  - ✅ **Buffer Support** - Load RAW data from memory buffers
24
26
  - ✅ **Configuration Control** - Gamma, brightness, color space settings
25
27
  - ✅ **High Performance** - Native C++ processing with JavaScript convenience
@@ -55,16 +57,89 @@ LibRaw supports 100+ RAW formats including:
55
57
  npm install lightdrift-libraw
56
58
  ```
57
59
 
58
- **Version 1.0.0-alpha.1** is now available on [npmjs.com](https://www.npmjs.com/package/lightdrift-libraw)! 🎉
60
+ **Version 1.0.0-alpha.3** is now available on [npmjs.com](https://www.npmjs.com/package/lightdrift-libraw)! 🎉
59
61
 
60
- ### 🛠️ Build Requirements
62
+ ### 🛠️ System Requirements
63
+
64
+ #### **Windows**
65
+
66
+ - **Node.js** 14.0.0 or higher
67
+ - **Python** 3.6+ (for node-gyp)
68
+ - **Visual Studio Build Tools** 2019+ or Visual Studio Community
69
+ - LibRaw is bundled (no additional dependencies needed)
70
+
71
+ #### **Linux (Alpine/Debian/Ubuntu)**
61
72
 
62
73
  - **Node.js** 14.0.0 or higher
63
74
  - **Python** 3.6+ (for node-gyp)
64
- - **C++ Build Tools**:
65
- - Windows: Visual Studio 2019+ or VS Build Tools
66
- - macOS: Xcode Command Line Tools
67
- - Linux: GCC 8+ or equivalent
75
+ - **LibRaw development package**:
76
+
77
+ ```bash
78
+ # Alpine
79
+ apk add libraw-dev build-base
80
+
81
+ # Debian/Ubuntu
82
+ apt-get install libraw-dev build-essential
83
+
84
+ # Then install the package
85
+ npm install lightdrift-libraw
86
+ ```
87
+
88
+ #### **macOS**
89
+
90
+ - **Node.js** 14.0.0 or higher
91
+ - **Xcode Command Line Tools**: `xcode-select --install`
92
+ - **LibRaw**:
93
+ ```bash
94
+ brew install libraw
95
+ npm install lightdrift-libraw
96
+ ```
97
+
98
+ ### 🐳 Docker Usage
99
+
100
+ When using Docker or pnpm, you may need to explicitly rebuild native modules:
101
+
102
+ ```dockerfile
103
+ FROM node:18-alpine
104
+
105
+ # Install system dependencies
106
+ RUN apk add --no-cache \
107
+ python3 \
108
+ make \
109
+ g++ \
110
+ libraw-dev
111
+
112
+ WORKDIR /app
113
+
114
+ # Copy package files
115
+ COPY package*.json ./
116
+
117
+ # Install dependencies
118
+ RUN npm install --frozen-lockfile
119
+
120
+ # Explicitly rebuild native module
121
+ RUN npm rebuild lightdrift-libraw
122
+
123
+ # Copy application
124
+ COPY . .
125
+
126
+ CMD ["node", "app.js"]
127
+ ```
128
+
129
+ #### **pnpm in Docker**
130
+
131
+ If using pnpm, add `.npmrc` to your project:
132
+
133
+ ```
134
+ enable-pre-post-scripts=true
135
+ ```
136
+
137
+ Or rebuild manually:
138
+
139
+ ```dockerfile
140
+ RUN pnpm install --frozen-lockfile
141
+ RUN pnpm rebuild lightdrift-libraw
142
+ ```
68
143
 
69
144
  ### 🚀 Quick Verification
70
145
 
@@ -76,14 +151,6 @@ node -e "const LibRaw = require('lightdrift-libraw'); console.log('LibRaw versio
76
151
 
77
152
  Expected output: `LibRaw version: 0.21.4-Release`
78
153
 
79
- ## Prerequisites (for building from source)
80
-
81
- - **Node.js** 14.0.0 or higher
82
- - **Python** 3.x (for node-gyp)
83
- - **Visual Studio Build Tools** (Windows)
84
- - **Xcode Command Line Tools** (macOS)
85
- - **build-essential** (Linux)
86
-
87
154
  ## Quick Start
88
155
 
89
156
  ```javascript
@@ -96,7 +163,34 @@ async function processRAW() {
96
163
  // Load RAW file
97
164
  await processor.loadFile("photo.cr2");
98
165
 
99
- // 🆕 NEW: High-Performance JPEG Conversion
166
+ // 🆕 NEW: Buffer Creation API - Create images directly in memory
167
+ // Process the RAW data first
168
+ await processor.processImage();
169
+
170
+ // Create JPEG buffer without writing to file
171
+ const jpegBuffer = await processor.createJPEGBuffer({
172
+ quality: 85,
173
+ width: 1920,
174
+ progressive: true,
175
+ });
176
+
177
+ console.log(`JPEG buffer created: ${jpegBuffer.buffer.length} bytes`);
178
+
179
+ // Create multiple formats in parallel
180
+ const [pngResult, webpResult, thumbResult] = await Promise.all([
181
+ processor.createPNGBuffer({ width: 1200, compressionLevel: 6 }),
182
+ processor.createWebPBuffer({ quality: 80, width: 1200 }),
183
+ processor.createThumbnailJPEGBuffer({ maxSize: 300 }),
184
+ ]);
185
+
186
+ // Use buffers directly (e.g., send via HTTP, store in database, etc.)
187
+ // No temporary files needed!
188
+
189
+ console.log(`PNG: ${pngResult.buffer.length} bytes`);
190
+ console.log(`WebP: ${webpResult.buffer.length} bytes`);
191
+ console.log(`Thumbnail: ${thumbResult.buffer.length} bytes`);
192
+
193
+ // 🆕 NEW: High-Performance JPEG Conversion (Legacy method still available)
100
194
  // Convert RAW to JPEG with advanced options
101
195
  const jpegResult = await processor.convertToJPEG("output.jpg", {
102
196
  quality: 85, // JPEG quality (1-100)
@@ -226,7 +320,228 @@ This wrapper provides comprehensive LibRaw functionality with **50+ methods** ac
226
320
 
227
321
  **All methods are thoroughly tested and production-ready!**
228
322
 
229
- ## 🆕 JPEG Conversion (New Feature)
323
+ ## 🆕 Buffer Creation API (New Feature)
324
+
325
+ ### Direct Memory Buffer Creation
326
+
327
+ Create image buffers directly in memory without writing to files. Perfect for web applications, APIs, and streaming workflows.
328
+
329
+ #### Available Buffer Methods
330
+
331
+ ```javascript
332
+ const processor = new LibRaw();
333
+ await processor.loadFile("photo.cr2");
334
+ await processor.processImage();
335
+
336
+ // Create different format buffers
337
+ const jpegBuffer = await processor.createJPEGBuffer(options);
338
+ const pngBuffer = await processor.createPNGBuffer(options);
339
+ const webpBuffer = await processor.createWebPBuffer(options);
340
+ const avifBuffer = await processor.createAVIFBuffer(options);
341
+ const tiffBuffer = await processor.createTIFFBuffer(options);
342
+ const ppmBuffer = await processor.createPPMBuffer();
343
+
344
+ // Extract thumbnail buffer without full processing
345
+ const processor2 = new LibRaw();
346
+ await processor2.loadFile("photo.cr2");
347
+ const thumbBuffer = await processor2.createThumbnailJPEGBuffer(options);
348
+ ```
349
+
350
+ #### Buffer Creation Options
351
+
352
+ ##### JPEG Buffer Options
353
+
354
+ ```javascript
355
+ {
356
+ quality: 85, // 1-100 (default: 85)
357
+ width: 1200, // Target width
358
+ height: 800, // Target height
359
+ progressive: true, // Progressive JPEG
360
+ fastMode: false, // Speed vs quality trade-off
361
+ effort: 4 // Encoding effort 1-8
362
+ }
363
+ ```
364
+
365
+ ##### PNG Buffer Options
366
+
367
+ ```javascript
368
+ {
369
+ width: 1200, // Target width
370
+ height: 800, // Target height
371
+ compressionLevel: 6, // 0-9 (default: 6)
372
+ fastMode: false // Speed vs size trade-off
373
+ }
374
+ ```
375
+
376
+ ##### WebP Buffer Options
377
+
378
+ ```javascript
379
+ {
380
+ quality: 80, // 1-100 (default: 80)
381
+ width: 1200, // Target width
382
+ height: 800, // Target height
383
+ lossless: false, // Lossless mode
384
+ effort: 4, // Encoding effort 0-6
385
+ fastMode: false // Speed optimization
386
+ }
387
+ ```
388
+
389
+ ##### AVIF Buffer Options
390
+
391
+ ```javascript
392
+ {
393
+ quality: 50, // 1-100 (default: 50)
394
+ width: 1200, // Target width
395
+ height: 800, // Target height
396
+ lossless: false, // Lossless mode
397
+ effort: 4 // Encoding effort 0-9
398
+ }
399
+ ```
400
+
401
+ ##### TIFF Buffer Options
402
+
403
+ ```javascript
404
+ {
405
+ width: 1200, // Target width
406
+ height: 800, // Target height
407
+ compression: 'lzw', // 'none', 'lzw', 'zip'
408
+ predictor: 'horizontal' // Compression predictor
409
+ }
410
+ ```
411
+
412
+ ##### Thumbnail Buffer Options
413
+
414
+ ```javascript
415
+ {
416
+ maxSize: 300, // Maximum dimension
417
+ quality: 85, // JPEG quality 1-100
418
+ fastMode: false // Speed optimization
419
+ }
420
+ ```
421
+
422
+ #### Usage Examples
423
+
424
+ ##### Web API Response
425
+
426
+ ```javascript
427
+ app.get("/api/photo/:id/thumbnail", async (req, res) => {
428
+ const processor = new LibRaw();
429
+ try {
430
+ await processor.loadFile(`photos/${req.params.id}.cr2`);
431
+
432
+ const result = await processor.createThumbnailJPEGBuffer({
433
+ maxSize: 300,
434
+ quality: 85,
435
+ });
436
+
437
+ res.set({
438
+ "Content-Type": "image/jpeg",
439
+ "Content-Length": result.buffer.length,
440
+ "Cache-Control": "public, max-age=86400",
441
+ });
442
+
443
+ res.send(result.buffer);
444
+ } finally {
445
+ await processor.close();
446
+ }
447
+ });
448
+ ```
449
+
450
+ ##### Multiple Format Generation
451
+
452
+ ```javascript
453
+ async function generateFormats(rawFile, outputDir) {
454
+ const processor = new LibRaw();
455
+ await processor.loadFile(rawFile);
456
+ await processor.processImage();
457
+
458
+ // Generate all formats in parallel
459
+ const [jpeg, png, webp, avif] = await Promise.all([
460
+ processor.createJPEGBuffer({ quality: 85, width: 1920 }),
461
+ processor.createPNGBuffer({ width: 1200, compressionLevel: 6 }),
462
+ processor.createWebPBuffer({ quality: 80, width: 1920 }),
463
+ processor.createAVIFBuffer({ quality: 50, width: 1200 }),
464
+ ]);
465
+
466
+ // Save or process buffers as needed
467
+ fs.writeFileSync(`${outputDir}/image.jpg`, jpeg.buffer);
468
+ fs.writeFileSync(`${outputDir}/image.png`, png.buffer);
469
+ fs.writeFileSync(`${outputDir}/image.webp`, webp.buffer);
470
+ fs.writeFileSync(`${outputDir}/image.avif`, avif.buffer);
471
+
472
+ await processor.close();
473
+ }
474
+ ```
475
+
476
+ ##### Streaming Upload
477
+
478
+ ```javascript
479
+ async function uploadToCloud(rawFile) {
480
+ const processor = new LibRaw();
481
+ await processor.loadFile(rawFile);
482
+ await processor.processImage();
483
+
484
+ const webpResult = await processor.createWebPBuffer({
485
+ quality: 80,
486
+ width: 1600,
487
+ });
488
+
489
+ // Upload buffer directly to cloud storage
490
+ const uploadResult = await cloudStorage.upload(webpResult.buffer, {
491
+ contentType: "image/webp",
492
+ fileName: "processed-image.webp",
493
+ });
494
+
495
+ await processor.close();
496
+ return uploadResult;
497
+ }
498
+ ```
499
+
500
+ #### Buffer Result Structure
501
+
502
+ All buffer creation methods return a consistent result structure:
503
+
504
+ ```javascript
505
+ {
506
+ success: true,
507
+ buffer: Buffer, // The created image buffer
508
+ metadata: {
509
+ format: "JPEG", // Output format
510
+ outputDimensions: { // Final image dimensions
511
+ width: 1920,
512
+ height: 1280
513
+ },
514
+ fileSize: {
515
+ original: 50331648, // Original processed image size
516
+ compressed: 245760, // Buffer size
517
+ compressionRatio: "204.8" // Compression ratio
518
+ },
519
+ processing: {
520
+ timeMs: "45.23", // Processing time
521
+ throughputMBps: "15.4" // Processing throughput
522
+ },
523
+ options: { // Applied options
524
+ quality: 85,
525
+ width: 1920,
526
+ // ... other options
527
+ }
528
+ }
529
+ }
530
+ ```
531
+
532
+ #### Performance Characteristics
533
+
534
+ | Format | Typical Size (1920px) | Creation Time | Compression Ratio |
535
+ | ---------- | --------------------- | ------------- | ----------------- |
536
+ | JPEG | 80-400KB | 200-500ms | 50-200x |
537
+ | PNG | 1-4MB | 400-800ms | 12-50x |
538
+ | WebP | 50-300KB | 100-300ms | 60-300x |
539
+ | AVIF | 30-150KB | 300-800ms | 100-500x |
540
+ | TIFF (LZW) | 2-8MB | 100-200ms | 6-25x |
541
+ | PPM | 11-45MB | 50-100ms | 1x (uncompressed) |
542
+ | Thumbnail | 5-50KB | 50-150ms | 200-1000x |
543
+
544
+ ## 🆕 JPEG Conversion (Enhanced Feature)
230
545
 
231
546
  ### High-Performance RAW to JPEG Conversion
232
547
 
@@ -698,6 +1013,9 @@ npm run test:quick
698
1013
  # Comprehensive API coverage test
699
1014
  npm run test:comprehensive
700
1015
 
1016
+ # New buffer creation methods test
1017
+ npm run test:buffer-creation
1018
+
701
1019
  # Individual test suites
702
1020
  npm run test:image-processing # Image conversion and processing
703
1021
  npm run test:format-conversion # Output formats and color spaces
@@ -717,6 +1035,9 @@ npm run test:performance
717
1035
  # Test all supported formats
718
1036
  npm run test:formats
719
1037
 
1038
+ # Buffer creation test suites
1039
+ npm run test:buffer-creation # Comprehensive buffer method testing
1040
+
720
1041
  # Test with your own RAW file
721
1042
  npm test path/to/your/photo.cr2
722
1043
  ```
@@ -727,12 +1048,14 @@ The test suites provide comprehensive validation across:
727
1048
 
728
1049
  - ✅ **21 RAW files tested** (Canon CR3, Nikon NEF, Sony ARW, Fujifilm RAF, Panasonic RW2, Leica DNG)
729
1050
  - ✅ **100% thumbnail extraction success rate**
1051
+ - ✅ **100% buffer creation success rate** (7 new buffer methods)
730
1052
  - ✅ **6 camera brands validated** (Canon, Nikon, Sony, Fujifilm, Panasonic, Leica)
731
- - ✅ **Multiple output formats tested** (PPM, TIFF, JPEG thumbnails)
1053
+ - ✅ **Multiple output formats tested** (PPM, TIFF, JPEG, PNG, WebP, AVIF buffers)
732
1054
  - ✅ **Color space conversion** (sRGB, Adobe RGB, Wide Gamut, ProPhoto, XYZ)
733
1055
  - ✅ **Bit depth variations** (8-bit, 16-bit processing)
734
- - ✅ **Memory operations** (buffer management, image copying)
735
- - ✅ **Error handling** (invalid files, corrupted data)
1056
+ - ✅ **Memory operations** (buffer management, image copying, direct buffer creation)
1057
+ - ✅ **Error handling** (invalid files, corrupted data, parameter validation)
1058
+ - ✅ **Performance benchmarking** (buffer creation speed and compression ratios)
736
1059
 
737
1060
  ## Thumbnail Extraction
738
1061
 
@@ -984,8 +1307,8 @@ npm run build # Rebuilds and copies DLL
984
1307
 
985
1308
  **✅ Published to NPM Registry!**
986
1309
 
987
- - **Package**: [`lightdrift-libraw@1.0.0-alpha.1`](https://www.npmjs.com/package/lightdrift-libraw)
988
- - **Published**: August 23, 2025
1310
+ - **Package**: [`lightdrift-libraw@1.0.0-alpha.3`](https://www.npmjs.com/package/lightdrift-libraw)
1311
+ - **Published**: August 30, 2025
989
1312
  - **Total Files**: 487 files (4.0 MB package, 18.1 MB unpacked)
990
1313
  - **Registry**: [npmjs.com](https://www.npmjs.com/package/lightdrift-libraw)
991
1314
 
package/binding.gyp CHANGED
@@ -7,31 +7,50 @@
7
7
  "src/libraw_wrapper.cpp"
8
8
  ],
9
9
  "include_dirs": [
10
- "<!@(node -p \"require('node-addon-api').include\")",
11
- "deps/LibRaw-Win64/LibRaw-0.21.4/libraw",
12
- "deps/LibRaw-Win64/LibRaw-0.21.4"
13
- ],
14
- "libraries": [
15
- "<(module_root_dir)/deps/LibRaw-Win64/LibRaw-0.21.4/lib/libraw.lib"
10
+ "<!@(node -p \"require('node-addon-api').include\")"
16
11
  ],
17
12
  "defines": [
18
13
  "NAPI_DISABLE_CPP_EXCEPTIONS"
19
14
  ],
20
15
  "cflags!": [ "-fno-exceptions" ],
21
16
  "cflags_cc!": [ "-fno-exceptions" ],
22
- "msvs_settings": {
23
- "VCCLCompilerTool": {
24
- "ExceptionHandling": 1,
25
- "RuntimeLibrary": 2
26
- }
27
- },
28
- "copies": [
29
- {
30
- "destination": "<(module_root_dir)/build/Release/",
31
- "files": [
32
- "<(module_root_dir)/deps/LibRaw-Win64/LibRaw-0.21.4/bin/libraw.dll"
17
+ "conditions": [
18
+ ['OS=="win"', {
19
+ "include_dirs": [
20
+ "deps/LibRaw-Win64/LibRaw-0.21.4/libraw",
21
+ "deps/LibRaw-Win64/LibRaw-0.21.4"
22
+ ],
23
+ "libraries": [
24
+ "<(module_root_dir)/deps/LibRaw-Win64/LibRaw-0.21.4/lib/libraw.lib"
25
+ ],
26
+ "msvs_settings": {
27
+ "VCCLCompilerTool": {
28
+ "ExceptionHandling": 1,
29
+ "RuntimeLibrary": 2
30
+ }
31
+ },
32
+ "copies": [
33
+ {
34
+ "destination": "<(module_root_dir)/build/Release/",
35
+ "files": [
36
+ "<(module_root_dir)/deps/LibRaw-Win64/LibRaw-0.21.4/bin/libraw.dll"
37
+ ]
38
+ }
33
39
  ]
34
- }
40
+ }],
41
+ ['OS=="linux"', {
42
+ "libraries": ["-lraw"],
43
+ "cflags": ["-fexceptions"],
44
+ "cflags_cc": ["-fexceptions"]
45
+ }],
46
+ ['OS=="mac"', {
47
+ "libraries": ["-lraw"],
48
+ "xcode_settings": {
49
+ "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
50
+ "CLANG_CXX_LIBRARY": "libc++",
51
+ "MACOSX_DEPLOYMENT_TARGET": "10.9"
52
+ }
53
+ }]
35
54
  ]
36
55
  }
37
56
  ]