This directory contains type definitions and interfaces for handling images and color data in AdaCAD. The media system supports image analysis, color extraction, and rendering color definitions for draft visualization.
Defines all TypeScript interfaces and types for media handling:
-
Img: Wrapper for an analyzed image:id: Unique string identifierdata: The analyzed image data (or null if not loaded)
-
AnalyzedImage: Complete image analysis data structure:name: Original filenamedata: Raw ImageData from the imagecolors: Array of unique hex color values found in the imagecolors_mapping: Array mapping color indices to grouped color indices (for color reduction)proximity_map: Array of color proximity relationships{a: number, b: number, dist: number}image: HTMLImageElement for renderingimage_map: 2D array mapping each pixel to a color index in the colors arraywidth: Image width in pixelsheight: Image height in pixelstype: Image file type/formatwarning: Optional warning message if image violates rules
-
Color: RGB color representation:r: Red component (0-255)g: Green component (0-255)b: Blue component (0-255)hex: Hex color string (e.g., "#FF0000")
-
DraftCellColor: Color definition for rendering draft cells:id: String identifier (e.g., 'up', 'down', 'unset', 'edge')r: Red component (0-255)g: Green component (0-255)b: Blue component (0-255)a: Alpha component (0-255)
-
SingleImage: Simplified image structure without analysis:name: Filenamedata: ImageDataimage: HTMLImageElementwidth: Image widthheight: Image heighttype: Image typewarning: Optional warning
Exports all types from the media directory.
The media types are primarily used for:
- Image Import: When users upload images to convert to drafts, the image is analyzed and stored as an
AnalyzedImage - Color Extraction: The
colorsarray contains all unique colors found in the image - Color Mapping: The
colors_mappingallows grouping similar colors together - Draft Rendering:
DraftCellColordefines how different cell states are rendered
import { AnalyzedImage, DraftCellColor } from './media';
// Draft cell color definitions
const cellColors: Array<DraftCellColor> = [
{
id: 'up',
r: 0,
g: 0,
b: 0,
a: 255 // Black for heddle up
},
{
id: 'down',
r: 255,
g: 255,
b: 255,
a: 255 // White for heddle down
}
];
// Working with analyzed images
function processImage(img: AnalyzedImage) {
// Access unique colors
const uniqueColors = img.colors;
// Map pixels to colors
const pixelColor = img.colors[img.image_map[0][0]];
// Check for warnings
if (img.warning) {
console.warn(img.warning);
}
}The media types integrate with:
- Image Operations: Used by operations that convert images to drafts
- Draft Rendering:
DraftCellColoris used indraft.ts'sgetDraftAsImage()function - Color Effects: Operations that manipulate colors use these types
To add new color or image properties:
// In types.ts
export interface ExtendedColor extends Color {
hsl?: { h: number, s: number, l: number };
lab?: { l: number, a: number, b: number };
}
export interface ExtendedAnalyzedImage extends AnalyzedImage {
dominantColors?: Array<Color>;
colorHistogram?: Map<string, number>;
}