Skip to content

Commit cfffa4d

Browse files
committed
added filenames back to media items
1 parent a97794d commit cfffa4d

File tree

6 files changed

+71
-34
lines changed

6 files changed

+71
-34
lines changed

src/app/core/modal/imageeditor/imageeditor.component.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
cdkDrag
33
cdkDragRootElement=".cdk-overlay-pane"
44
cdkDragHandle>
5-
Manage Image Colors
5+
<span *ngIf="editable">View/Edit Image Colors</span>
6+
<span *ngIf="!editable">View Image Colors</span>
67
</p>
78

89

910
<mat-dialog-content >
1011

1112
<div class="content_left">
12-
<p>Use this editor to modify the color space of your image. You can do this grouping colors together that you would like the software to treat as the same.</p>
13+
<p *ngIf="editable">Use this editor to modify the color space of your image. You can do this grouping colors together that you would like the software to treat as the same.</p>
1314

1415
<div class="image_preview" id="image_preview">
1516
<canvas id="preview_canvas"></canvas>
@@ -41,7 +42,7 @@
4142
<!--color mapped to-->
4243
<mat-form-field>
4344
<mat-label>groups with:</mat-label>
44-
<mat-select [(value)]="color.to" (selectionChange)="mappingChanged(color.from, $event)">
45+
<mat-select [disabled]="!editable" [(value)]="color.to" (selectionChange)="mappingChanged(color.from, $event)">
4546
<mat-option *ngFor="let to_color of img.colors; index as i" [value]="i">
4647
<div class="swatch" [style.background-color]="to_color.hex">
4748
<div class="centered_id">{{i}}</div>

src/app/core/modal/imageeditor/imageeditor.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class ImageeditorComponent {
1717
img: AnalyzedImage;
1818
color_table: Array<{from: number, from_hex:string, to:number, to_hex: string}>;
1919
resulting_color_space: Array<{from: number, from_hex:string, to:number, to_hex: string}>;
20+
editable: boolean = true;
2021

2122
constructor(
2223
public tree: TreeService,
@@ -26,7 +27,11 @@ export class ImageeditorComponent {
2627
@Inject(MAT_DIALOG_DATA) public obj: any){
2728

2829

29-
this.media_id = obj;
30+
if(obj.src == 'bwimagemap'){
31+
this.editable = false;
32+
}
33+
34+
this.media_id = obj.media_id;
3035
const media_item = <IndexedColorImageInstance> this.mediaService.getMedia(this.media_id);
3136
this.img = media_item.img;
3237

src/app/core/operations/bwimagemap/bwimagemap.ts

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createCell } from "../../model/cell";
2-
import { AnalyzedImage, Cell, Color, Draft, DynamicOperation, FileParam, NumParam, OperationInlet, OpInput, OpParamVal } from "../../model/datatypes";
3-
import { getHeddle, initDraftFromDrawdown, initDraftWithParams, warps, wefts } from "../../model/drafts";
2+
import { AnalyzedImage, Cell, Draft, DynamicOperation, FileParam, NumParam, OperationInlet, OpInput, OpParamVal } from "../../model/datatypes";
3+
import { createDraft, getHeddle, initDraftFromDrawdown, initDraftWithParams, warps, wefts } from "../../model/drafts";
44
import { getOpParamValById } from "../../model/operations";
55

66

@@ -61,21 +61,17 @@ const perform = (op_params: Array<OpParamVal>, op_inputs: Array<OpInput>) => {
6161

6262
const data:AnalyzedImage = file_param.data;
6363

64-
const color_to_drafts = data.colors_mapping.map((color, ndx) => {
65-
66-
let color_to:Color = data.colors[color.to];
67-
64+
65+
const color_to_drafts = data.colors.map((color, ndx) => {
66+
const child_of_color = op_inputs.find(input => (input.params.findIndex(param => param === color.hex) !== -1));
6867

69-
if(color_to.hex == '#000000'){
70-
if(op_inputs.findIndex(input => input.inlet_id == 0) !== -1) return {color: color_to.hex, draft: op_inputs[0].drafts[0]}
71-
else return {color: color_to.hex, draft: initDraftWithParams({warps: 1, wefts: 1, drawdown: [[createCell(true)]]})}
72-
} else{
73-
if(op_inputs.findIndex(input => input.inlet_id == 1) !== -1) return {color: color_to.hex, draft: op_inputs[1].drafts[0]}
74-
else return {color: color_to.hex, draft: initDraftWithParams({warps: 1, wefts: 1, drawdown: [[createCell(false)]]})}
68+
if(child_of_color === undefined){
69+
if(color.hex == '#000000') return {color: color.hex, draft: initDraftWithParams({warps: 1, wefts:1, drawdown: [[createCell(true)]]})};
70+
else return {color: color.hex, draft: initDraftWithParams({warps: 1, wefts:1, drawdown: [[createCell(false)]]})};;
71+
}
72+
else return {color: color.hex, draft: child_of_color.drafts[0]};
73+
});
7574

76-
}
77-
});
78-
7975

8076
const pattern: Array<Array<Cell>> = [];
8177
for(let i = 0; i < res_h; i++){
@@ -88,8 +84,13 @@ const perform = (op_params: Array<OpParamVal>, op_inputs: Array<OpInput>) => {
8884
const map_i = Math.floor(i * i_ratio);
8985
const map_j = Math.floor(j * j_ratio);
9086

91-
const color_ndx = data.image_map[map_i][map_j]; //
92-
const color_draft = color_to_drafts[color_ndx].draft;
87+
const color_ndx = data.image_map[map_i][map_j];
88+
const mapped_color = data.colors_mapping.find(el => el.from == color_ndx); //this is the mapped id
89+
const mapped_color_hex = data.colors[mapped_color.to].hex
90+
const color_draft = color_to_drafts.find(el => el.color == mapped_color_hex).draft;
91+
92+
93+
9394

9495
if(color_draft === null) pattern[i].push( createCell(false));
9596
else {
@@ -120,11 +121,44 @@ const generateName = (param_vals: Array<OpParamVal>, op_inputs: Array<OpInput>)
120121

121122
const onParamChange = (param_vals: Array<OpParamVal>, inlets: Array<OperationInlet>, inlet_vals: Array<any>, changed_param_id: number, param_val: any) : Array<any> => {
122123

124+
//go through the image and adjust the mapping data so that it adds black and white and maps to those.
123125
const new_inlets: Array<any> = ['#000000', '#ffffff']
126+
let img = param_val.data;
127+
console.log("IMG", img);
128+
129+
if(img == undefined) return new_inlets;
130+
131+
132+
133+
let has_black = false;
134+
let has_white = false;
135+
136+
img.colors.forEach(color => {
137+
if(color.hex == '#000000') has_black = true;
138+
if(color.hex == '#ffffff') has_white = true;
139+
})
140+
141+
if(!has_black) img.colors.push({r: 0, g: 0, b: 0, hex: '#000000', black: true})
142+
if(!has_white) img.colors.push({r: 255, g: 255, b: 255, hex: '#ffffff', black: false})
143+
144+
let black_id = img.colors.findIndex(el => el.hex == '#000000');
145+
let white_id = img.colors.findIndex(el => el.hex == '#ffffff');
146+
147+
148+
img.colors_mapping.forEach(mapping => {
149+
let c = img.colors[mapping.from];
150+
if(c.black) mapping.to = black_id;
151+
else mapping.to = white_id;
152+
})
124153

125154
return new_inlets;
126155

127156

157+
158+
159+
160+
161+
128162
}
129163

130164

src/app/core/operations/system_notation/system_notation.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const perform = (op_params: Array<OpParamVal>, op_inputs: Array<OpInput>) => {
6161

6262
//make sure the system draft map has a representation for every layer, even if the draft at that layer is null.
6363
const layer_draft_map = original_string_split.map((unit, ndx) => {
64-
6564
let layer_id = layer_units.findIndex(el => el.includes(unit));
6665

6766
let drafts = getAllDraftsAtInlet(op_inputs, ndx+1);

src/app/core/provider/media.service.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,28 @@ export class MediaService {
183183
warning: filewarning
184184
}
185185

186-
return obj;
187-
186+
return this.addMediaNameFromStorage(ref, obj);
187+
188188
}).then(imageobj => {
189189

190190
if(imageobj.data == null){
191191
return Promise.reject("no image object found when loading indexed color file");
192192
}
193193
const media_ref = this.addIndexColorMediaInstance(id, ref, imageobj)
194194
return Promise.resolve(media_ref);
195-
196-
// return this.upSvc.getDownloadMetaData(ref)
197-
// .then(metadata => {
198-
// if(metadata.customMetadata.filename !== undefined) imageobj.name = metadata.customMetadata.filename;
199-
// const media_ref = this.addIndexColorMediaInstance(id, ref, imageobj)
200-
// return Promise.resolve(media_ref);
201-
202-
// })
203-
204195
}) ;
205196
});
206197
}
207198

208199

209200

201+
addMediaNameFromStorage(ref: string, img: AnalyzedImage) : Promise<AnalyzedImage>{
202+
return this.upSvc.getDownloadMetaData(ref)
203+
.then(metadata => {
204+
if(metadata.customMetadata.filename !== undefined) img.name = metadata.customMetadata.filename;
205+
return Promise.resolve(img);
206+
})
207+
}
210208

211209

212210
createColorMap(colors: Array<Color>, prox: Array<{a: number, b: number, dist: number}>, space: number) : Array<{from: number, to: number}>{

src/app/mixer/palette/operation/parameter/parameter.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class ParameterComponent implements OnInit {
214214

215215
if(obj === undefined || obj.img == undefined || obj.img.image == null ) return;
216216

217-
const dialogRef = this.dialog.open(ImageeditorComponent, {data: obj.id});
217+
const dialogRef = this.dialog.open(ImageeditorComponent, {data: {media_id: obj.id, src: this.opnode.name}});
218218
dialogRef.afterClosed().subscribe(nothing => {
219219

220220
let updated_media = <IndexedColorImageInstance> this.mediaService.getMedia( this.opnode.params[this.paramid].id)

0 commit comments

Comments
 (0)