@umituz/react-native-ai-generation-content 1.17.230 → 1.17.232

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.
@@ -1,247 +1,396 @@
1
- # Upscaling
1
+ # Upscaling Feature
2
2
 
3
3
  Increase image resolution while maintaining quality using AI.
4
4
 
5
- ## Features
5
+ ## 📍 Import Path
6
6
 
7
- - Upscale images by 2x, 4x, or more
8
- - Maintain image quality and details
9
- - Remove noise and artifacts during upscaling
10
- - Support for various image formats
7
+ ```typescript
8
+ import { useUpscaleFeature } from '@umituz/react-native-ai-generation-content';
9
+ ```
11
10
 
12
- ## Installation
11
+ **Location**: `src/features/upscaling/`
13
12
 
14
- This feature is part of `@umituz/react-native-ai-generation-content`.
13
+ ## 🎯 Feature Purpose
15
14
 
16
- ```bash
17
- npm install @umituz/react-native-ai-generation-content`
18
- ```
15
+ Increase image resolution by 2x or 4x while maintaining and enhancing quality using AI. Removes noise and artifacts during the upscaling process.
19
16
 
20
- ## Basic Usage
17
+ ---
21
18
 
22
- ### Using the Hook
19
+ ## 📋 Usage Strategy
23
20
 
24
- ```tsx
25
- import { useUpscaleFeature } from '@umituz/react-native-ai-generation-content';
26
- import * as ImagePicker from 'react-native-image-picker';
27
-
28
- function UpscaleScreen() {
29
- const [image, setImage] = useState<string | null>(null);
30
-
31
- const feature = useUpscaleFeature({
32
- config: {
33
- defaultScaleFactor: 2,
34
- onProcessingStart: () => console.log('Starting upscaling...'),
35
- onProcessingComplete: (result) => console.log('Complete:', result),
36
- onError: (error) => console.error('Error:', error),
37
- },
38
- onSelectImage: async () => {
39
- const result = await ImagePicker.launchImageLibrary({ mediaType: 'photo' });
40
- if (result.assets && result.assets[0].uri) {
41
- const base64 = await convertToBase64(result.assets[0].uri);
42
- setImage(base64);
43
- return base64;
44
- }
45
- return null;
46
- },
47
- onSaveImage: async (imageUrl) => {
48
- await saveToGallery(imageUrl);
49
- },
50
- });
51
-
52
- return (
53
- <View>
54
- <PhotoUploadCard
55
- image={image}
56
- onSelectImage={feature.selectImage}
57
- title="Select Image to Upscale"
58
- />
59
-
60
- <Button
61
- title="Upscale Image"
62
- onPress={feature.process}
63
- disabled={!feature.isReady || feature.state.isProcessing}
64
- />
65
-
66
- {feature.state.isProcessing && (
67
- <View>
68
- <Text>Upscaling image...</Text>
69
- <ProgressBar progress={feature.state.progress} />
70
- </View>
71
- )}
72
-
73
- {feature.state.result && (
74
- <Image source={{ uri: feature.state.result.imageUrl }} />
75
- )}
76
- </View>
77
- );
78
- }
79
- ```
21
+ ### When to Use This Feature
80
22
 
81
- ### Using the Unified AI Feature Screen
23
+ **Use Cases:**
24
+ - Enhancing low-resolution photos
25
+ - Preparing images for print
26
+ - Improving image quality for presentations
27
+ - Upscaling for large format displays
28
+ - Increasing resolution for cropping
29
+ - Enhancing old digital photos
82
30
 
83
- ```tsx
84
- import { AIFeatureScreen } from '@umituz/react-native-ai-generation-content';
31
+ ❌ **When NOT to Use:**
32
+ - Simple resizing without quality enhancement (use basic image resizing)
33
+ - Photo restoration with scratches (use Photo Restoration)
34
+ - Image sharpening only (use HD Touch Up)
35
+ - Artistic style changes (use Style Transfer)
85
36
 
86
- function App() {
87
- return (
88
- <AIFeatureScreen
89
- featureId="upscaling"
90
- userId="user-123"
91
- />
92
- );
93
- }
94
- ```
37
+ ### Implementation Strategy
95
38
 
96
- ## Configuration Options
39
+ 1. **Select image** to upscale
40
+ 2. **Choose scale factor** (2x or 4x)
41
+ 3. **Select enhancement options** (denoise, enhance)
42
+ 4. **Show file size warning** for 4x upscaling
43
+ 5. **Display before/after comparison**
44
+ 6. **Provide download in multiple formats**
97
45
 
98
- ### Feature Config
46
+ ---
99
47
 
100
- ```tsx
101
- interface UpscaleFeatureConfig {
102
- defaultScaleFactor?: 2 | 4; // Scale factor (default: 2)
103
- onProcessingStart?: () => void;
104
- onProcessingComplete?: (result: UpscaleResult) => void;
105
- onError?: (error: string) => void;
106
- }
48
+ ## ⚠️ Critical Rules (MUST FOLLOW)
49
+
50
+ ### 1. Image Requirements
51
+ - **MUST** provide ONE image to upscale
52
+ - **MUST** use reasonable resolution (min 256x256)
53
+ - **MUST** consider file size limits (original < 10MB recommended)
54
+ - **MUST** use supported formats (JPEG, PNG, WebP)
55
+ - **MUST NOT** exceed output dimensions limits
56
+
57
+ ### 2. Configuration
58
+ - **MUST** provide valid `userId` for tracking
59
+ - **MUST** specify `scaleFactor` (2 or 4)
60
+ - **MUST** implement `onError` callback
61
+ - **MUST** implement `onSelectImage` callback
62
+ - **MUST** warn about file size increase
63
+
64
+ ### 3. State Management
65
+ - **MUST** check `isReady` before enabling upscale button
66
+ - **MUST** display progress during upscaling
67
+ - **MUST** handle very large file sizes (4x can be 16x larger)
68
+ - **MUST** display `error` state with clear messages
69
+ - **MUST** implement proper cleanup on unmount
70
+
71
+ ### 4. Performance
72
+ - **MUST** warn about 4x file sizes (can be very large)
73
+ - **MUST** show progress indicator for long operations
74
+ - **MUST** implement timeout (180s for 4x upscaling)
75
+ - **MUST** allow users to cancel processing
76
+ - **MUST** cache results locally to avoid re-processing
77
+
78
+ ### 5. User Experience
79
+ - **MUST** show before/after comparison
80
+ - **MUST** display estimated output file size
81
+ - **MUST** warn about processing time
82
+ - **MUST** provide quality settings
83
+ - **MUST** handle large result downloads
84
+
85
+ ---
86
+
87
+ ## 🚫 Prohibitions (MUST AVOID)
88
+
89
+ ### Strictly Forbidden
90
+
91
+ ❌ **NEVER** do the following:
92
+
93
+ 1. **No Missing Images**
94
+ - Always validate image is selected
95
+ - Never call process() without image
96
+
97
+ 2. **No Auto-Processing**
98
+ - Never start upscaling without user action
99
+ - Always require explicit "Upscale" button press
100
+ - Show preview before processing
101
+
102
+ 3. **No Ignoring File Sizes**
103
+ - Never hide file size warnings for 4x upscaling
104
+ - Always display estimated output size
105
+ - Warn about download times
106
+
107
+ 4. **No Unhandled Errors**
108
+ - Never ignore upscaling failures
109
+ - Always explain what went wrong
110
+ - Provide retry or alternative options
111
+
112
+ 5. **No Memory Leaks**
113
+ - Never keep both original and 4x upscaled in memory
114
+ - Clean up temporary images
115
+ - Implement proper image disposal
116
+
117
+ 6. **No Blocking UI**
118
+ - Never block main thread with image processing
119
+ - Always show progress indicator
120
+ - Allow cancellation of long operations
121
+
122
+ 7. **No Quality Loss**
123
+ - Never compress upscaled image excessively
124
+ - Use appropriate quality settings
125
+ - Preserve enhancement benefits
126
+
127
+ ---
128
+
129
+ ## 🤖 AI Agent Directions
130
+
131
+ ### For AI Code Generation Tools
132
+
133
+ When using this feature with AI code generation tools, follow these guidelines:
134
+
135
+ #### Prompt Template for AI Agents
136
+
137
+ ```
138
+ You are implementing an image upscaling feature using @umituz/react-native-ai-generation-content.
139
+
140
+ REQUIREMENTS:
141
+ 1. Import from: @umituz/react-native-ai-generation-content
142
+ 2. Use the useUpscaleFeature hook
143
+ 3. Select scale factor (2x or 4x)
144
+ 4. Implement image selection UI
145
+ 5. Validate image before upscaling
146
+ 6. Show before/after comparison
147
+ 7. Warn about file sizes (especially 4x)
148
+ 8. Handle long processing times with progress
149
+ 9. Implement proper error handling
150
+ 10. Implement cleanup on unmount
151
+
152
+ CRITICAL RULES:
153
+ - MUST validate image before calling upscale()
154
+ - MUST warn about 4x file sizes (can be 16x larger)
155
+ - MUST show before/after comparison
156
+ - MUST handle very large result files
157
+ - MUST implement debouncing (300ms)
158
+ - MUST allow cancellation of long operations
159
+
160
+ CONFIGURATION:
161
+ - Provide valid userId (string)
162
+ - Set scaleFactor: 2 | 4 (2 = double, 4 = quadruple)
163
+ - Implement onSelectImage callback
164
+ - Implement onSaveImage callback
165
+ - Configure callbacks: onProcessingStart, onProcessingComplete, onError
166
+
167
+ UPSCALING OPTIONS:
168
+ - scaleFactor: 2 | 4 (resolution multiplier)
169
+ - enhance: boolean (improve details during upscaling)
170
+ - denoise: boolean (remove noise and artifacts)
171
+
172
+ STRICTLY FORBIDDEN:
173
+ - No missing image validation
174
+ - No auto-processing without user action
175
+ - No ignoring file size warnings
176
+ - No unhandled errors
177
+ - No memory leaks with large images
178
+ - No blocking UI
179
+ - No excessive compression of results
180
+
181
+ QUALITY CHECKLIST:
182
+ - [ ] Image selection implemented
183
+ - [ ] Scale factor selector (2x, 4x)
184
+ - [ ] File size warning displayed
185
+ - [ ] Before/after comparison view
186
+ - [ ] Progress indicator for long operations
187
+ - [ ] Error display with retry option
188
+ - [ ] Download with format options
189
+ - [ ] Cancellation capability
190
+ - [ ] Original image preserved
107
191
  ```
108
192
 
109
- ### Generation Options
193
+ #### AI Implementation Checklist
110
194
 
111
- ```tsx
112
- interface UpscaleOptions {
113
- scaleFactor: 2 | 4;
114
- enhance?: boolean; // Enhance image during upscaling
115
- denoise?: boolean; // Remove noise during upscaling
195
+ Use this checklist when generating code:
196
+
197
+ - [ ] Feature imported from correct path
198
+ - [ ] Image selection implemented
199
+ - [ ] Scale factor selector added (2x, 4x)
200
+ - [ ] Validation before upscale()
201
+ - [ ] File size warning displayed
202
+ - [ ] Before/after comparison view
203
+ - [ ] Progress indicator during processing
204
+ - [ ] Error display with user-friendly message
205
+ - [ ] Download functionality for large files
206
+ - [ ] Cancellation button available
207
+ - [ ] Cleanup on unmount
208
+ - [ ] Original image preserved
209
+
210
+ ---
211
+
212
+ ## 🛠️ Configuration Strategy
213
+
214
+ ### Essential Configuration
215
+
216
+ ```typescript
217
+ // Required fields
218
+ {
219
+ userId: string
220
+ scaleFactor: 2 | 4
221
+ onSelectImage: () => Promise<string | null>
222
+ }
223
+
224
+ // Optional callbacks
225
+ {
226
+ onProcessingStart?: () => void
227
+ onProcessingComplete?: (result) => void
228
+ onError?: (error: string) => void
116
229
  }
117
230
  ```
118
231
 
119
- ## Usage Flow
232
+ ### Recommended Settings
233
+
234
+ 1. **Scale Factors**
235
+ - 2x: Double resolution (file size ~4x larger)
236
+ - 4x: Quadruple resolution (file size ~16x larger)
237
+ - Start with 2x, try 4x if needed
120
238
 
121
- 1. Select **Image** - Choose an image to upscale
122
- 2. Choose **Scale Factor** - Select 2x or 4x upscaling
123
- 3. Tap **Upscale** - Start the upscaling process
124
- 4. View Result - See the upscaled high-resolution image
125
- 5. Save or Share - Save to gallery or share
239
+ 2. **Image Quality**
240
+ - Minimum input: 256x256 resolution
241
+ - Recommended input: 1024x1024 or higher
242
+ - Format: JPEG, PNG, or WebP
243
+ - Max input size: 10MB
126
244
 
127
- ## Component Examples
245
+ 3. **Performance Settings**
246
+ - Timeout: 180s for 4x upscaling
247
+ - Show progress for long operations
248
+ - Enable result caching
249
+ - Warn about download times
128
250
 
129
- ### Scale Factor Selector
251
+ ---
130
252
 
131
- ```tsx
132
- import { GridSelector } from '@umituz/react-native-ai-generation-content';
253
+ ## 📊 State Management
133
254
 
134
- const scaleOptions = [
135
- { id: '2x', name: '2x', description: 'Double resolution' },
136
- { id: '4x', name: '4x', description: 'Quadruple resolution' },
137
- ];
255
+ ### Feature States
138
256
 
139
- function MyScreen() {
140
- const [scaleFactor, setScaleFactor] = useState('2x');
257
+ **isReady**: boolean
258
+ - Image selected and validated
259
+ - Check before enabling upscale button
141
260
 
142
- return (
143
- <GridSelector
144
- options={scaleOptions}
145
- selectedOption={scaleFactor}
146
- onSelectOption={setScaleFactor}
147
- />
148
- );
261
+ **isProcessing**: boolean
262
+ - Upscaling in progress
263
+ - Show loading/progress indicator
264
+ - Disable upscale button
265
+
266
+ **progress**: number (0-100)
267
+ - Upscaling progress percentage
268
+ - Update progress bar
269
+
270
+ **error**: string | null
271
+ - Error message if upscaling failed
272
+ - Display to user with clear message
273
+
274
+ **result**: {
275
+ imageUrl: string
276
+ originalImageUrl?: string
277
+ scaleFactor?: number
278
+ outputSize?: { width: number; height: number }
279
+ metadata?: any
149
280
  }
150
- ```
151
281
 
152
- ### Before/After Comparison
282
+ ---
153
283
 
154
- ```tsx
155
- import { ResultDisplay } from '@umituz/react-native-ai-generation-content';
284
+ ## 🎨 Best Practices
156
285
 
157
- {feature.state.result && originalImage && (
158
- <View>
159
- <Text>Before:</Text>
160
- <Image source={{ uri: originalImage }} style={{ width: 200, height: 200 }} />
286
+ ### Image Selection
161
287
 
162
- <Text>After (Upscaled):</Text>
163
- <Image source={{ uri: feature.state.result.imageUrl }} style={{ width: 400, height: 400 }} />
164
- </View>
165
- )}
166
- ```
288
+ 1. **Input Quality**
289
+ - Good: Reasonable quality source images
290
+ - Bad: Extremely low resolution (<256px) or very compressed
167
291
 
168
- ## Advanced Usage
292
+ 2. **Scale Factor Choice**
293
+ - Start with 2x for most cases
294
+ - Use 4x for print or large displays
295
+ - Consider file size implications
169
296
 
170
- ### Custom Scale Factor
297
+ 3. **Enhancement Options**
298
+ - Enable enhance for better detail preservation
299
+ - Use denoise for noisy source images
300
+ - Both options recommended for best quality
171
301
 
172
- ```tsx
173
- const result = await feature.process({
174
- scaleFactor: 4,
175
- enhance: true,
176
- denoise: true,
177
- });
178
- ```
302
+ ### User Experience
179
303
 
180
- ### Progress Tracking
304
+ 1. **File Size Warnings**
305
+ - Clearly show estimated output file size
306
+ - Warn about download times for 4x
307
+ - Provide quality vs size options
181
308
 
182
- ```tsx
183
- const { state, process } = useUpscaleFeature({ ...config });
309
+ 2. **Progress Feedback**
310
+ - Show estimated time remaining
311
+ - Update progress regularly
312
+ - Allow cancellation for long operations
184
313
 
185
- useEffect(() => {
186
- if (state.isProcessing) {
187
- console.log(`Upscaling progress: ${state.progress}%`);
188
- }
189
- }, [state.progress]);
190
- ```
314
+ 3. **Comparison Tools**
315
+ - Side-by-side comparison
316
+ - Zoom capability for detail inspection
317
+ - Pixel-level comparison (optional)
191
318
 
192
- ## Use Cases
319
+ ---
193
320
 
194
- ### Enhancing Low-Resolution Photos
321
+ ## 🐛 Common Pitfalls
195
322
 
196
- ```tsx
197
- // Upscale old photos for better quality
198
- const result = await feature.process({ scaleFactor: 2 });
199
- ```
323
+ ### Quality Issues
200
324
 
201
- ### Preparing Images for Print
325
+ **Problem**: Upscaled image looks blurry
326
+ ✅ **Solution**: Enable enhance option, try higher quality source
202
327
 
203
- ```tsx
204
- // Upscale to print-ready resolution
205
- const result = await feature.process({ scaleFactor: 4 });
206
- ```
328
+ ### File Size Issues
207
329
 
208
- ### Improving Image Quality
330
+ **Problem**: 4x file too large to handle
331
+ ✅ **Solution**: Warn users, allow 2x option, compress appropriately
209
332
 
210
- ```tsx
211
- // Upscale with enhancement and denoising
212
- const result = await feature.process({
213
- scaleFactor: 2,
214
- enhance: true,
215
- denoise: true,
216
- });
217
- ```
333
+ ### Performance Issues
218
334
 
219
- ## Best Practices
335
+ **Problem**: Very slow upscaling
336
+ ✅ **Solution**: Show progress, allow cancellation, implement timeout
220
337
 
221
- 1. **Start with 2x**: Try 2x first, then 4x if needed
222
- 2. **Image Quality**: Higher quality source images produce better results
223
- 3. **File Size**: Be aware that 4x upscaling significantly increases file size
224
- 4. **Enhancement**: Use enhancement for better detail preservation
225
- 5. **Testing**: Test different scale factors to find the best result
338
+ ### Memory Issues
226
339
 
227
- ## Error Handling
340
+ **Problem**: App crashes with large upscales
341
+ ✅ **Solution**: Clean up original image, stream download, optimize memory
228
342
 
229
- ```tsx
230
- const { state, process } = useUpscaleFeature({ ...config });
343
+ ---
231
344
 
232
- useEffect(() => {
233
- if (state.error) {
234
- Alert.alert('Upscaling Failed', state.error);
235
- }
236
- }, [state.error]);
237
- ```
345
+ ## 📦 Related Components
346
+
347
+ Use these components from the library:
348
+
349
+ - **PhotoUploadCard**: Upload image interface
350
+ - **ResultDisplay**: Before/after comparison
351
+ - **ScaleFactorSelector**: Choose 2x or 4x
352
+ - **ProgressBar**: Progress display
353
+ - **ImageComparison**: Side-by-side comparison
354
+
355
+ Located at: `src/presentation/components/`
356
+
357
+ ---
358
+
359
+ ## 🔄 Migration Strategy
360
+
361
+ If migrating from previous implementation:
362
+
363
+ 1. **Update imports** to new path
364
+ 2. **Add scale factor selector** (2x, 4x)
365
+ 3. **Implement file size warnings**
366
+ 4. **Update state handling** for new structure
367
+ 5. **Add before/after comparison**
368
+ 6. **Test with large files**
369
+
370
+ ---
371
+
372
+ ## 📚 Additional Resources
373
+
374
+ - Main documentation: `/docs/`
375
+ - API reference: `/docs/api/`
376
+ - Examples: `/docs/examples/basic/upscaling/`
377
+ - Architecture: `/ARCHITECTURE.md`
378
+
379
+ ---
380
+
381
+ **Last Updated**: 2025-01-08
382
+ **Version**: 2.0.0 (Strategy-based Documentation)
238
383
 
239
- ## Related Features
384
+ ---
240
385
 
241
- - [HD Touch Up](../hd-touch-up) - High-detail image enhancements
242
- - [Photo Restoration](../photo-restoration) - Restore old/blurry photos
243
- - [Image to Image](../image-to-image) - Transform images using AI
386
+ ## 📝 Changelog
244
387
 
245
- ## License
388
+ ### v2.0.0 - 2025-01-08
389
+ - **BREAKING**: Documentation format changed to strategy-based
390
+ - Removed extensive code examples
391
+ - Added rules, prohibitions, and AI agent directions
392
+ - Focus on best practices and implementation guidance
393
+ - Added file size handling guidelines
246
394
 
247
- MIT
395
+ ### v1.0.0 - Initial Release
396
+ - Initial feature documentation
@@ -43,11 +43,6 @@ export const ResultStoryCard: React.FC<ResultStoryCardProps> = ({
43
43
  ...base,
44
44
  backgroundColor: tokens.colors.primaryContainer,
45
45
  };
46
- } else if (cfg.borderStyle === "gradient") {
47
- return {
48
- ...base,
49
- backgroundColor: tokens.colors.primaryContainer,
50
- };
51
46
  }
52
47
 
53
48
  return {
@@ -34,7 +34,7 @@ export interface ResultImageConfig {
34
34
  borderRadius?: number;
35
35
  showBadge?: boolean;
36
36
  badgePosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
37
- badgeStyle?: "dark" | "light" | "gradient";
37
+ badgeStyle?: "dark" | "light";
38
38
  badgeIcon?: string;
39
39
  spacing?: {
40
40
  marginBottom?: number;
@@ -59,7 +59,7 @@ export interface ResultStoryConfig {
59
59
  | "700"
60
60
  | "800"
61
61
  | "900";
62
- borderStyle?: "outline" | "filled" | "gradient";
62
+ borderStyle?: "outline" | "filled";
63
63
  spacing?: {
64
64
  marginBottom?: number;
65
65
  paddingHorizontal?: number;
@@ -149,7 +149,7 @@ export const DEFAULT_RESULT_CONFIG: ResultConfig = {
149
149
  fontSize: 14,
150
150
  fontStyle: "italic",
151
151
  fontWeight: "500",
152
- borderStyle: "gradient",
152
+ borderStyle: "filled",
153
153
  spacing: {
154
154
  marginBottom: 20,
155
155
  paddingHorizontal: 20,