-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDevelopment.txt
More file actions
243 lines (205 loc) · 9.24 KB
/
Development.txt
File metadata and controls
243 lines (205 loc) · 9.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
Ideas for further development
1. Another cues tab - "user" which is mutable and saved at exit
2. Thumbnail view of image review table (DONE)
3. Evolve modifiers in two (or three) stages:
- thumbnails images representing the style, material or artist
- keywords associated with each modifier, and then filter by keyword(s)
-? category specific views (presentation)
4. In scan mode to have a two or three copies of modifiers panel so the scan can have more than one modifiers.
5. Get thesaurus and dictionary on board - many possibilities after
6. API-specific control panel: between cues and modif. OR above modif.
7. Snippets - small pieces of code to control a scan with parameters inside to iterate over
1.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static class ImageUtils
{
/// <summary>
/// Captures all or part of the raw png metadata.
/// Can use this to capture PhonoBooth metadata by setting the filter to "iTXt"
///
/// throws: ArgumentException if not a png file
/// </summary>
/// <param name="imageFilePath"></param>
/// <param name="itemMap"></param>
/// <param name="filter"> optional filter on the key (contains)</param>
/// <returns>true if successful, false otherwise.</returns>
public static bool GetMetaDataItems(string imageFilePath, ref Dictionary<string, string> itemMap, string filter=null)
{
Assertion<ArgumentException>(imageFilePath.ToLower().EndsWith(".png"), "Expected png file");
var ret = false;
var query = string.Empty;
itemMap.Clear();
try
{
using (Stream fileStream = File.Open(imageFilePath, FileMode.Open))
{
var decoder = BitmapDecoder.Create(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
GetMetaDataItems(decoder.Frames[0].Metadata as BitmapMetadata, ref itemMap, filter);
}
ret = true;
}
catch (Exception e)
{
ret = false;
LogE(e.Message);
}
return ret;
}
/// <summary>
/// Used to get the meta data from png file metadata
/// Can use this to capture PhonoBooth metadata by setting the filter to "iTXt"
/// </summary>
/// <param name="bitmapMetadata"></param>
/// <param name="itemMap"></param>
/// <param name="filter">set this to iTXt for Phenosuite image data</param>
/// <param name="query">initally null, used in recursive calls to get the child data</param>
public static void GetMetaDataItems(BitmapMetadata bitmapMetadata , ref Dictionary<string, string> itemMap, string filter= null, string query = null )
{
if (query is null)
query = string.Empty;
if (bitmapMetadata != null)
{
var key = string.Empty;
foreach (string relativeQuery in bitmapMetadata)
{
var fullQuery = query + relativeQuery;
// GetQuery returns an object: either a string or child metadata
// If a string then it is one of 4 values: ["Keyword", "Translated", "Compression", "Language Tag", "TextEntry"]
// We want the Keyword and the subsequent TextEntry items, the tags are a sequence in the order specified above
var metadata = bitmapMetadata.GetQuery(relativeQuery);
var innerBitmapMetadata = metadata as BitmapMetadata;
if (innerBitmapMetadata is null)
AddToMap(ref key, fullQuery, metadata?.ToString(), ref itemMap, filter); // Not a metadata structure so it is data - therefore check and Add to map
else
GetMetaDataItems(innerBitmapMetadata, ref itemMap, filter, fullQuery); // Recursive call
}
}
}
/// <summary>
/// Suitable for Png iTXt metadata
/// This is used to buld the item map from the metadata
/// </summary>
/// <param name="key">key like "Application" or "Lighting Mode"</param>
/// <param name="fullQuery">metadata query</param>
/// <param name="metadata">image metadata</param>
/// <param name="itemMap">map being populated from the metadata</param>
/// <param name="filter">we dont want all the meta data - so this filters on the "sub folder" of the meta data -Phenosuite uses "iTXt" </param>
private static void AddToMap(ref string key, string fullQuery, string metadata, ref Dictionary<string, string> itemMap, string filter)
{
if (metadata != null)
{
if (!fullQuery.Contains("Translated"))
{
if ((filter is null) || ((fullQuery.Contains(filter))))
{
if (fullQuery.Contains("Keyword"))
key = metadata;
if (fullQuery.Contains("TextEntry") && (key != null))
itemMap[key] = metadata?.ToString();
}
}
}
}
}
2.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
https://www.codeproject.com/Articles/36342/ExifLib-A-Fast-Exif-Data-Extractor-for-NET
3.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
https://stackoverflow.com/questions/29037442/write-metadata-to-both-jpg-and-png
namespace MarkerGenerator.Utils
{
class PngUtils
{
public string getMetadata(string file, string key)
{
PngReader pngr = FileHelper.CreatePngReader(file);
//pngr.MaxTotalBytesRead = 1024 * 1024 * 1024L * 3; // 3Gb!
//pngr.ReadSkippingAllRows();
string data = pngr.GetMetadata().GetTxtForKey(key);
pngr.End();
return data; ;
}
public static void addMetadata(String origFilename, Dictionary<string, string> data)
{
String destFilename = "tmp.png";
PngReader pngr = FileHelper.CreatePngReader(origFilename); // or you can use the constructor
PngWriter pngw = FileHelper.CreatePngWriter(destFilename, pngr.ImgInfo, true); // idem
//Console.WriteLine(pngr.ToString()); // just information
int chunkBehav = ChunkCopyBehaviour.COPY_ALL_SAFE; // tell to copy all 'safe' chunks
pngw.CopyChunksFirst(pngr, chunkBehav); // copy some metadata from reader
foreach (string key in data.Keys)
{
PngChunk chunk = pngw.GetMetadata().SetText(key, data[key]);
chunk.Priority = true;
}
int channels = pngr.ImgInfo.Channels;
if (channels < 3)
throw new Exception("This example works only with RGB/RGBA images");
for (int row = 0; row < pngr.ImgInfo.Rows; row++)
{
ImageLine l1 = pngr.ReadRowInt(row); // format: RGBRGB... or RGBARGBA...
pngw.WriteRow(l1, row);
}
pngw.CopyChunksLast(pngr, chunkBehav); // metadata after the image pixels? can happen
pngw.End(); // dont forget this
pngr.End();
File.Delete(origFilename);
File.Move(destFilename, origFilename);
}
public static void addMetadata(String origFilename,string key,string value)
{
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add(key, value);
addMetadata(origFilename, data);
}
}
}
4.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
https://www.codeproject.com/Articles/5251929/CompactExifLib-Access-to-EXIF-Tags-in-JPEG-TIFF-an
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<style>
table, th, td {
/*border: 1px solid black;*/
border-collapse: collapse;
}
th, td {
padding: 8px;
}
</style>
</head>
<body>
<table border="0" width="100%" >
<tr>
<td>
<img border="0" src="http://scripthea.com/images/v3line-6.png" width="16" height="1469"></td>
<td align="left" valign="top">
<p align="center"><font face="Lucida Calligraphy">Scripthea images
generated by Stable diffusion<img border="0" src="http://scripthea.com/images/scripthea-pen.png" width="40" align="right"></font></p>
<table id="image-table" >
<tr>
<!-- Insert image cells here -->
</tr>
</table>
<p> </td>
</tr>
</table>
<script>
// The list of image filenames
var images = getImages(); var imgPerRow = $imgPerRow$;
// Get the table element
var table = document.getElementById("image-table");
// Loop through the filenames and add a new row to the table for each image
for (var i = 0; i < images.length; i++) {
var filename = images[i].filename;
if ((i % imgPerRow) == 0) var newRow = table.insertRow();
var newCell = newRow.insertCell(-1); newCell.style.textAlign = "center"; newCell.style.verticalAlign = "bottom"; newCell.style.width = (100/imgPerRow).toString()+"%";
newCell.innerHTML = images[i].prompt+"<br><img src='" + filename + "' width='iWidth' align='center'> <br>"+filename;
}
function getImages(){
return [
$IMAGES$
];
}
</script>
</body>
</html>