• R/O
  • SSH
  • HTTPS

kuon: 提交


Commit MetaInfo

修訂302 (tree)
時間2009-10-19 23:57:57
作者catwalk

Log Message

Added.

Change Summary

差異

--- kuon/trunk/Utilities/Bass.cs (nonexistent)
+++ kuon/trunk/Utilities/Bass.cs (revision 302)
@@ -0,0 +1,569 @@
1+using System;
2+using System.ComponentModel;
3+using System.Collections.Generic;
4+using System.Runtime.InteropServices;
5+
6+namespace Kuon.Utilities{
7+ internal static class Bass{
8+ const string BassDllName = "bass.dll";
9+
10+ [DllImport(BassDllName, EntryPoint = "BASS_Init", CharSet = CharSet.Auto)]
11+ public static extern bool Init(int device, uint freq, BassDeviceSetups flags, IntPtr hwnd, IntPtr clsid);
12+
13+ [DllImport(BassDllName, EntryPoint = "BASS_Free", CharSet = CharSet.Auto)]
14+ public static extern bool Free();
15+
16+ [DllImport(BassDllName, EntryPoint = "BASS_GetVolume", CharSet = CharSet.Auto)]
17+ public static extern float GetVolume();
18+
19+ [DllImport(BassDllName, EntryPoint = "BASS_SetVolume", CharSet = CharSet.Auto)]
20+ public static extern bool SetVolume(float volume);
21+
22+ [DllImport(BassDllName, EntryPoint = "BASS_Start", CharSet = CharSet.Auto)]
23+ public static extern bool Start();
24+
25+ [DllImport(BassDllName, EntryPoint = "BASS_Pause", CharSet = CharSet.Auto)]
26+ public static extern bool Pause();
27+
28+ [DllImport(BassDllName, EntryPoint = "BASS_Stop", CharSet = CharSet.Auto)]
29+ public static extern bool Stop();
30+
31+ [DllImport(BassDllName, EntryPoint = "BASS_SetDevice", CharSet = CharSet.Auto)]
32+ public static extern bool SetDevice(int device);
33+
34+ [DllImport(BassDllName, EntryPoint = "BASS_GetDevice", CharSet = CharSet.Auto)]
35+ public static extern int GetCurrentDevice();
36+
37+ [DllImport(BassDllName, EntryPoint = "BASS_GetDeviceInfo", CharSet = CharSet.Auto)]
38+ public static extern bool GetDeviceInfo(int device, out DeviceInfo deviceInfo);
39+
40+ [DllImport(BassDllName, EntryPoint = "BASS_ErrorGetCode", CharSet = CharSet.Auto)]
41+ public static extern BassErrorCode GetErrorCode();
42+
43+ [DllImport(BassDllName, EntryPoint = "BASS_StreamCreateFile", CharSet = CharSet.Auto)]
44+ public static extern IntPtr CreateStreamFromFile(bool mem, [MarshalAs(UnmanagedType.LPStr)] string file, long offset, long length, BassOptions options);
45+
46+ [DllImport(BassDllName, EntryPoint = "BASS_StreamFree", CharSet = CharSet.Auto)]
47+ public static extern bool FreeStream(IntPtr handle);
48+
49+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelGetLength", CharSet = CharSet.Auto)]
50+ public static extern long GetChannelLength(IntPtr handle, BassPositionMode mode);
51+
52+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelBytes2Seconds", CharSet = CharSet.Auto)]
53+ public static extern double ChannelBytes2Seconds(IntPtr handle, long bytes);
54+
55+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelSeconds2Bytes", CharSet = CharSet.Auto)]
56+ public static extern long ChannelSeconds2Bytes(IntPtr handle, double pos);
57+
58+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelPlay", CharSet = CharSet.Auto)]
59+ public static extern bool PlayChannel(IntPtr handle, bool restart);
60+
61+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelPause", CharSet = CharSet.Auto)]
62+ public static extern bool PauseChannel(IntPtr handle);
63+
64+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelStop", CharSet = CharSet.Auto)]
65+ public static extern bool StopChannel(IntPtr handle);
66+
67+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelSetPosition", CharSet = CharSet.Auto)]
68+ public static extern bool SetChannelPosition(IntPtr handle, long pos, BassPositionMode mode);
69+
70+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelGetPosition", CharSet = CharSet.Auto)]
71+ public static extern long GetChannelPosition(IntPtr handle, BassPositionMode mode);
72+
73+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelGetLevel", CharSet = CharSet.Auto)]
74+ public static extern int GetChannelLevel(IntPtr handle);
75+
76+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelIsActive", CharSet = CharSet.Auto)]
77+ public static extern BassChannelState GetChannelState(IntPtr handle);
78+
79+ [DllImport(BassDllName, EntryPoint = "BASS_ChannelGetInfo", CharSet = CharSet.Auto)]
80+ public static extern bool GetChannelInfo(IntPtr handle, out ChannelInfo info);
81+
82+ [StructLayoutAttribute(LayoutKind.Sequential)]
83+ public struct DeviceInfo{
84+ [MarshalAs(UnmanagedType.LPStr)]
85+ public string Name;
86+ [MarshalAs(UnmanagedType.LPStr)]
87+ public string Device;
88+ public DeviceStates States;
89+ }
90+
91+ [Flags]
92+ public enum DeviceStates : uint{
93+ None = 0,
94+ Enabled = 1,
95+ Default = 2,
96+ Initialized = 4,
97+ }
98+
99+ [StructLayoutAttribute(LayoutKind.Sequential)]
100+ public struct ChannelInfo{
101+ public int Frequency;
102+ public int Channels;
103+ public BassOptions Options;
104+ public BassChannelType ChannelType;
105+ public int OriginalResolution;
106+ public IntPtr Plugin;
107+ public IntPtr Sample;
108+ [MarshalAs(UnmanagedType.LPStr)]
109+ public string Filename;
110+ }
111+ }
112+
113+ public static class BassManager{
114+ private static bool initialized = false;
115+
116+ public static bool IsInitialized{
117+ get{
118+ return initialized;
119+ }
120+ }
121+
122+ public static void Initialize(int freq, BassDeviceSetups flags, IntPtr hwnd){
123+ if(Bass.Init(-1, (uint)freq, flags, hwnd, IntPtr.Zero)){ // 成功
124+ initialized = true;
125+ }else{
126+ BassErrorCode error = Bass.GetErrorCode();
127+ if(error == BassErrorCode.Already){
128+ throw new InvalidOperationException();
129+ }else{
130+ throw new BassException(error);
131+ }
132+ }
133+ }
134+
135+ public static void Free(){
136+ if(Bass.Free()){
137+ initialized = false;
138+ }else{
139+ throw new InvalidOperationException();
140+ }
141+ }
142+
143+ public static void Start(){
144+ if(Bass.Start()){
145+ return;
146+ }else{
147+ throw new BassException(Bass.GetErrorCode());
148+ }
149+ }
150+
151+ public static void Pause(){
152+ if(Bass.Pause()){
153+ return;
154+ }else{
155+ throw new BassException(Bass.GetErrorCode());
156+ }
157+ }
158+
159+ public static void Stop(){
160+ if(Bass.Start()){
161+ return;
162+ }else{
163+ throw new BassException(Bass.GetErrorCode());
164+ }
165+ }
166+
167+ public static float Volume{
168+ get{
169+ float volume = Bass.GetVolume();
170+ if(volume != -1){
171+ return volume;
172+ }else{
173+ throw new BassException(Bass.GetErrorCode());
174+ }
175+ }
176+ set{
177+ if(Bass.SetVolume(value)){
178+ return;
179+ }else{
180+ throw new BassException(Bass.GetErrorCode());
181+ }
182+ }
183+ }
184+
185+ public static BassDevice[] GetDevices(){
186+ List<BassDevice> devices = new List<BassDevice>();
187+ Bass.DeviceInfo device;
188+ for(int i = 0; Bass.GetDeviceInfo(i, out device); i++){
189+ devices.Add(new BassDevice(i, device));
190+ }
191+ return devices.ToArray();
192+ }
193+
194+ public static BassDevice Device{
195+ get{
196+ int device = Bass.GetCurrentDevice();
197+ if(device != -1){
198+ Bass.DeviceInfo info;
199+ Bass.GetDeviceInfo(device, out info);
200+ return new BassDevice(device, info);
201+ }else{
202+ throw new InvalidOperationException();
203+ }
204+ }
205+ set{
206+ if(Bass.SetDevice(value.Index)){
207+ return;
208+ }else{
209+ throw new BassException(Bass.GetErrorCode());
210+ }
211+ }
212+ }
213+ }
214+
215+ public class BassDevice{
216+ public string Name{get; private set;}
217+ public string Device{get; private set;}
218+ public bool IsEnabled{get; private set;}
219+ public bool IsDefault{get; private set;}
220+ public bool IsInitialized{get; private set;}
221+ internal int Index{get; private set;}
222+
223+ internal BassDevice(int index, Bass.DeviceInfo device){
224+ this.Index = index;
225+ this.Name = device.Name;
226+ this.Device = device.Device;
227+ this.IsEnabled = ((device.States & Bass.DeviceStates.Enabled) > 0);
228+ this.IsDefault = ((device.States & Bass.DeviceStates.Default) > 0);
229+ this.IsInitialized = ((device.States & Bass.DeviceStates.Initialized) > 0);
230+ }
231+ }
232+
233+ public abstract class BassChannel : Component{
234+ public IntPtr Handle{get; private set;}
235+
236+ public BassChannel(IntPtr handle){
237+ this.Handle = handle;
238+ }
239+
240+ public void Play(){
241+ this.Play(false);
242+ }
243+
244+ public void Play(bool restart){
245+ if(Bass.PlayChannel(this.Handle, restart)){
246+ return;
247+ }else{
248+ throw new BassException(Bass.GetErrorCode());
249+ }
250+ }
251+
252+ public void Pause(){
253+ if(Bass.PauseChannel(this.Handle)){
254+ return;
255+ }else{
256+ throw new BassException(Bass.GetErrorCode());
257+ }
258+ }
259+
260+ public void Stop(){
261+ if(Bass.StopChannel(this.Handle)){
262+ return;
263+ }else{
264+ throw new BassException(Bass.GetErrorCode());
265+ }
266+ }
267+
268+ public BassChannelState State{
269+ get{
270+ return Bass.GetChannelState(this.Handle);
271+ }
272+ }
273+
274+ public double BytesToSeconds(long bytes){
275+ double seconds = Bass.ChannelBytes2Seconds(this.Handle, bytes);
276+ if(seconds < 0){
277+ throw new BassException(Bass.GetErrorCode());
278+ }else{
279+ return seconds;
280+ }
281+ }
282+
283+ public long SecondsToBytes(double seconds){
284+ long bytes = Bass.ChannelSeconds2Bytes(this.Handle, seconds);
285+ if(bytes < 0){
286+ throw new BassException(Bass.GetErrorCode());
287+ }else{
288+ return bytes;
289+ }
290+ }
291+
292+ public long PositionInByte{
293+ get{
294+ long pos = Bass.GetChannelPosition(this.Handle, BassPositionMode.Byte);
295+ if(pos != -1){
296+ return pos;
297+ }else{
298+ throw new BassException(Bass.GetErrorCode());
299+ }
300+ }
301+ }
302+
303+ public double PositionInSecond{
304+ get{
305+ double seconds = Bass.ChannelBytes2Seconds(this.Handle, this.PositionInByte);
306+ if(seconds < 0){
307+ throw new BassException(Bass.GetErrorCode());
308+ }else{
309+ return seconds;
310+ }
311+ }
312+ }
313+
314+ public long Bytes{
315+ get{
316+ long bytes = Bass.GetChannelLength(this.Handle, BassPositionMode.Byte);
317+ if(bytes == -1){
318+ throw new BassException(Bass.GetErrorCode());
319+ }else{
320+ return bytes;
321+ }
322+ }
323+ }
324+
325+ public double Seconds{
326+ get{
327+ double seconds = Bass.ChannelBytes2Seconds(this.Handle, this.Bytes);
328+ if(seconds < 0){
329+ throw new BassException(Bass.GetErrorCode());
330+ }else{
331+ return seconds;
332+ }
333+ }
334+ }
335+ }
336+
337+ public abstract class BassPlayChannel : BassChannel{
338+ public BassPlayChannel(IntPtr handle) : base(handle){
339+ }
340+
341+ public void Seek(long bytes){
342+ if(Bass.SetChannelPosition(this.Handle, bytes, BassPositionMode.Byte)){
343+ return;
344+ }else{
345+ throw new BassException(Bass.GetErrorCode());
346+ }
347+ }
348+
349+ public void Seek(double seconds){
350+ long bytes = Bass.ChannelSeconds2Bytes(this.Handle, seconds);
351+ if(bytes == -1){
352+ throw new BassException(Bass.GetErrorCode());
353+ }else{
354+ this.Seek(bytes);
355+ }
356+ }
357+
358+ public BassChannelInfo GetChannelInfo(){
359+ Bass.ChannelInfo info;
360+ if(Bass.GetChannelInfo(this.Handle, out info)){
361+ return new BassChannelInfo(info);
362+ }else{
363+ throw new BassException(Bass.GetErrorCode());
364+ }
365+ }
366+ }
367+
368+ public class BassStream : BassPlayChannel{
369+ internal BassStream(IntPtr handle) : base(handle){
370+ }
371+
372+ public static BassStream FromFile(string path){
373+ IntPtr handle = Bass.CreateStreamFromFile(false, path, 0, 0, BassOptions.None);
374+ if(handle != IntPtr.Zero){
375+ return new BassStream(handle);
376+ }else{
377+ throw new BassException(Bass.GetErrorCode());
378+ }
379+ }
380+
381+ public void GetLevel(out int left, out int right){
382+ int level = Bass.GetChannelLevel(this.Handle);
383+ if(level != -1){
384+ left = level & 0xffff;
385+ right = level >> 16;
386+ }else{
387+ throw new BassException(Bass.GetErrorCode());
388+ }
389+ }
390+
391+ private bool disposed = false;
392+ protected override void Dispose(bool disposing){
393+ if(!(this.disposed)){
394+ if(!(Bass.FreeStream(this.Handle))){
395+ throw new BassException(Bass.GetErrorCode());
396+ }
397+ this.disposed = true;
398+ }
399+ }
400+ }
401+
402+ public class BassChannelInfo{
403+ public int Frequency{get; private set;}
404+ public int Channels{get; private set;}
405+ public BassChannelType ChannelType{get; private set;}
406+ public int OriginalResolution{get; private set;}
407+ public string Filename{get; private set;}
408+
409+ internal BassChannelInfo(Bass.ChannelInfo info){
410+ this.Frequency = info.Frequency;
411+ this.Channels = info.Channels;
412+ this.ChannelType = info.ChannelType;
413+ this.OriginalResolution = info.OriginalResolution;
414+ this.Filename = info.Filename;
415+ }
416+ }
417+
418+ [Flags]
419+ public enum BassDeviceSetups : uint{
420+ None = 0,
421+ Resolution8Bits = 1,
422+ Mono = 2,
423+ Enable3D = 4,
424+ CalculateLatency = 256,
425+ ControlPanelSpeakers = 1024,
426+ ForceSpeakers = 2048,
427+ IgnoreSpeakerArrangement = 4096,
428+ }
429+
430+ public enum BassErrorCode : int{
431+ None = 0,
432+ Memory = 1,
433+ FileOpen = 2,
434+ Driver = 3,
435+ BufferLost = 4,
436+ Handle = 5,
437+ Format = 6,
438+ Position = 7,
439+ Initialization = 8,
440+ Starting = 9,
441+ Already = 14,
442+ NoChannel = 18,
443+ IllegalType = 19,
444+ IllegalParameter = 20,
445+ No3D = 21,
446+ NoEax = 22,
447+ Device = 23,
448+ NotPlaying = 24,
449+ Frequency = 25,
450+ NotFile = 27,
451+ NoHardware = 29,
452+ Empty = 31,
453+ NoNet = 32,
454+ Creation = 33,
455+ NoEffects = 34,
456+ NotAvailable = 37,
457+ DecodingChannel = 38,
458+ DirectX = 39,
459+ TimeOut = 40,
460+ FileFormat = 41,
461+ Speaker = 42,
462+ Version = 43,
463+ Codec = 44,
464+ Ended = 45,
465+ Unknown = -1,
466+ }
467+
468+ public enum BassChannelType : uint{
469+ SAMPLE = 1,
470+ RECORD = 2,
471+ Stream = 0x10000,
472+ StreamOgg = 0x10002,
473+ StreamMP1 = 0x10003,
474+ StreamMP2 = 0x10004,
475+ StreamMP3 = 0x10005,
476+ StreamAiff = 0x10006,
477+ StreamCA = 0x10007,
478+ StreamWav = 0x40000, // WAVE flag, LOWORD=codec
479+ StreamWavPcm = 0x50001,
480+ StreamWavFloat = 0x50003,
481+ MusicMod = 0x20000,
482+ MusicMtm = 0x20001,
483+ MusicS3M = 0x20002,
484+ MusicXM = 0x20003,
485+ MusicIT = 0x20004,
486+ MusicMO3 = 0x00100, // MO3 flag
487+ }
488+
489+ public class BassException : ApplicationException{
490+ public BassErrorCode ErrorCode{get; private set;}
491+
492+ public BassException(){
493+ this.ErrorCode = BassErrorCode.Unknown;
494+ }
495+
496+ public BassException(BassErrorCode code){
497+ this.ErrorCode = code;
498+ }
499+
500+ public BassException(string message) : base(message){
501+ }
502+
503+ protected BassException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context){
504+ }
505+
506+ public BassException(string message, Exception innerException) : base(message, innerException){
507+ }
508+ }
509+
510+ internal enum BassPositionMode : uint{
511+ Byte = 0,
512+ MusicOrder = 1,
513+ }
514+
515+ [Flags]
516+ internal enum BassOptions : uint{
517+ None = 0,
518+ Sample8Bits = 1,
519+ SampleFloat = 256,
520+ SampleMono = 2,
521+ SampleLoop = 4,
522+ Sample3D = 8,
523+ SampleSoftware = 16,
524+ SampleMuteMax = 32,
525+ SampleVam = 64,
526+ SampleEffects = 128,
527+ SampleOverVol = 0x10000,
528+ SampleOverPos = 0x20000,
529+ SampleOverDist = 0x30000,
530+
531+ StreamPreScan = 0x20000,
532+ Mp3SetPos = StreamPreScan,
533+ StreamAutoFree = 0x40000,
534+ StreamRestRate = 0x80000,
535+ StreamBlock = 0x100000,
536+ StreamDecode = 0x200000,
537+ StreamStatus = 0x800000,
538+
539+ SpeakerFront = 0x1000000,
540+ SpeakerRear = 0x2000000,
541+ SpeakerCenterLfe = 0x3000000,
542+ SpeakerRear2 = 0x4000000,
543+ Speaker1 = 1<<24,
544+ Speaker2 = 2<<24,
545+ Speaker3 = 3<<24,
546+ Speaker4 = 4<<24,
547+ Speaker5 = 5<<24,
548+ Speaker6 = 6<<24,
549+ Speaker7 = 7<<24,
550+ Speaker8 = 8<<24,
551+ Speaker9 = 9<<24,
552+ Speaker10 = 10<<24,
553+ Speaker11 = 11<<24,
554+ Speaker12 = 12<<24,
555+ Speaker13 = 13<<24,
556+ Speaker14 = 14<<24,
557+ Speaker15 = 15<<24,
558+ SpeakerLeft = 0x10000000,
559+ SpeakerRight = 0x20000000,
560+ Unicode = 0x80000000,
561+ }
562+
563+ public enum BassChannelState : uint{
564+ Stopped = 0,
565+ Playing = 1,
566+ Stalled = 2,
567+ Paused = 3,
568+ }
569+}
\ No newline at end of file
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
--- kuon/trunk/Utilities/GFL.cs (revision 301)
+++ kuon/trunk/Utilities/GFL.cs (revision 302)
@@ -6,6 +6,7 @@
66 using System.IO;
77 using System.ComponentModel;
88 using System.Collections.Generic;
9+using System.Collections.ObjectModel;
910 using System.Runtime.InteropServices;
1011
1112 namespace Kuon.Utilities{
@@ -104,14 +105,91 @@
104105 [DllImport(GflDllName, EntryPoint = "gflGetDefaultLoadParams", CharSet = CharSet.Auto)]
105106 public static extern void GetDefaultLoadParams(ref LoadParams prms);
106107
108+ [DllImport(GflDllName, EntryPoint = "gflGetDefaultThumbnailParams", CharSet = CharSet.Auto)]
109+ public static extern void GetDefaultThumbnailParams(ref LoadParams prms);
110+
107111 [DllImport(GflDllName, EntryPoint = "gflLoadBitmap", CharSet = CharSet.Auto)]
108112 public static extern Error LoadBitmap(string filename, ref IntPtr bitmap, ref LoadParams prms, ref FileInformation info);
109113
114+ [DllImport(GflDllName, EntryPoint = "gflLoadBitmapFromMemory", CharSet = CharSet.Auto)]
115+ public static extern Error LoadBitmapFromMemory(IntPtr data, uint data_length, ref IntPtr bitmap, ref LoadParams prms, ref FileInformation informations);
116+
117+ [DllImport(GflDllName, EntryPoint = "gflLoadBitmapFromHandle", CharSet = CharSet.Auto)]
118+ public static extern Error LoadBitmapFromHandle(IntPtr handle, ref IntPtr bitmap, ref LoadParams prms, ref FileInformation informations);
119+
120+ [DllImport(GflDllName, EntryPoint = "gflGetFileInformation", CharSet = CharSet.Auto)]
121+ public static extern void GetFileInformation(string filename, int index, ref FileInformation info);
122+
123+ [DllImport(GflDllName, EntryPoint = "gflLoadThumbnail", CharSet = CharSet.Auto)]
124+ public static extern Error LoadThumbnail(string filename, int width, int height, ref IntPtr bitmap, ref LoadParams prms, ref FileInformation info);
125+
126+ [DllImport(GflDllName, EntryPoint = "gflLoadThumbnailFromMemory", CharSet = CharSet.Auto)]
127+ public static extern Error LoadThumbnailFromMemory(IntPtr data, uint data_length, int width, int height, ref IntPtr bitmap, ref LoadParams prms, ref FileInformation informations);
128+
129+ [DllImport(GflDllName, EntryPoint = "gflLoadThumbnailFromHandle", CharSet = CharSet.Auto)]
130+ public static extern Error LoadThumbnailFromHandle(IntPtr handle, int width, int height, ref IntPtr bitmap, ref LoadParams prms, ref FileInformation informations);
131+
110132 #endregion
111133
134+ #region Write
135+
136+ [DllImport(GflDllName, EntryPoint = "gflGetDefaultSaveParams", CharSet = CharSet.Auto)]
137+ public static extern void GetDefaultSaveParams(ref SaveParams prms);
138+
139+ [DllImport(GflDllName, EntryPoint = "gflSaveBitmap", CharSet = CharSet.Auto)]
140+ public static extern Error SaveBitmap(string filename, ref Bitmap bitmap, ref SaveParams prms);
141+
142+ #endregion
143+
144+ #region Metadata
145+
146+ [DllImport(GflDllName, EntryPoint = "gflBitmapHasEXIF", CharSet = CharSet.Auto)]
147+ public static extern bool HasExif(ref Bitmap bitmap);
148+
149+ [DllImport(GflDllName, EntryPoint = "gflBitmapHasIPTC", CharSet = CharSet.Auto)]
150+ public static extern bool HasIptc(ref Bitmap bitmap);
151+
152+ [DllImport(GflDllName, EntryPoint = "gflBitmapHasICCProfile", CharSet = CharSet.Auto)]
153+ public static extern bool HasIccProfile(ref Bitmap bitmap);
154+
155+ [DllImport(GflDllName, EntryPoint = "gflBitmapGetEXIF", CharSet = CharSet.Auto)]
156+ [return: MarshalAs(UnmanagedType.LPStruct)]
157+ public static extern ExifData GetExif(ref Bitmap bitmap, GetExifOptions options);
158+
159+ [DllImport(GflDllName, EntryPoint = "gflLoadEXIF", CharSet = CharSet.Auto)]
160+ [return: MarshalAs(UnmanagedType.LPStruct)]
161+ public static extern ExifData LoadExif(string path, GetExifOptions options);
162+
163+ [DllImport(GflDllName, EntryPoint = "gflFreeEXIF", CharSet = CharSet.Auto)]
164+ public static extern void FreeExif(ref ExifData exif);
165+
166+ [DllImport(GflDllName, EntryPoint = "gflBitmapRemoveEXIFThumbnail", CharSet = CharSet.Auto)]
167+ public static extern void RemoveExifThumbnail(ref Bitmap bitmap);
168+
169+ [DllImport(GflDllName, EntryPoint = "gflBitmapRemoveICCProfile", CharSet = CharSet.Auto)]
170+ public static extern void RemoveIccProfile(ref Bitmap bitmap);
171+
172+ [DllImport(GflDllName, EntryPoint = "gflBitmapGetICCProfile", CharSet = CharSet.Auto)]
173+ public static extern void GetIccProfile(ref Bitmap bitmap, ref IntPtr pData, ref UInt32 length);
174+
175+ [DllImport(GflDllName, EntryPoint = "gflBitmapCopyICCProfile", CharSet = CharSet.Auto)]
176+ public static extern void CopyIccProfile(ref Bitmap src, ref Bitmap dst);
177+
178+ [DllImport(GflDllName, EntryPoint = "gflBitmapRemoveMetaData", CharSet = CharSet.Auto)]
179+ public static extern void RemoveMetaData(ref Bitmap bitmap);
180+
181+ [DllImport(GflDllName, EntryPoint = "gflBitmapGetXMP", CharSet = CharSet.Auto)]
182+ public static extern bool GetXmp(ref Bitmap bitmap, ref IntPtr pData, ref UInt32 length);
183+
184+ [DllImport(GflDllName, EntryPoint = "gflBitmapSetEXIFThumbnail", CharSet = CharSet.Auto)]
185+ public static extern void SetExifThumbnail(ref Bitmap bitmap, ref Bitmap thumbnail);
186+
187+ #endregion
188+
112189 #region Error
113190
114191 [DllImport(GflDllName, EntryPoint = "gflGetErrorString", CharSet = CharSet.Auto)]
192+ [return: MarshalAs(UnmanagedType.LPStr)]
115193 public static extern string GetErrorString(Error error);
116194
117195 #endregion
@@ -176,7 +254,7 @@
176254
177255 [StructLayoutAttribute(LayoutKind.Sequential)]
178256 public struct LoadParams{
179- public LoadOptions Flags;
257+ public LoadOptions Options;
180258 public int FormatIndex;
181259 public int ImageWanted;
182260 public Origin Origin;
@@ -267,29 +345,69 @@
267345 public IntPtr ExtraInfos;
268346 }
269347
348+ [StructLayoutAttribute(LayoutKind.Sequential)]
349+ public struct SaveParams{
350+ public SaveOptions Options;
351+ public int FormatIndex;
352+
353+ public GflCompression Compression;
354+ public Int16 Quality;
355+ public Int16 CompressionLevel; // for PNG 1 to 7
356+ public bool Interlaced; // for GIF
357+ public bool Progressive; // for JPEG
358+ public bool OptimizeHuffmanTable; // for JPEG
359+ public bool InAscii; // for PPM
360+
361+ // for DPX/Cineon
362+ public LutType LutType;
363+ public ByteOrder DpxByteOrder;
364+ public byte CompressRatio; // for JPEG2000
365+ public UInt32 MaxFileSize; // for JPEG2000
366+
367+ public IntPtr LutData;
368+ public string LutFilename;
369+
370+ // for RAW/YUV
371+ public UInt32 Offset;
372+ public ChannelOrder ChannelOrder;
373+ public ChannelType ChannelType;
374+
375+ public SaveCallbacks Callbacks;
376+
377+ public IntPtr UserParams;
378+ }
379+
380+ [StructLayoutAttribute(LayoutKind.Sequential)]
381+ public struct SaveCallbacks{
382+ public IntPtr Read;
383+ public IntPtr Tell;
384+ public IntPtr Seek;
385+
386+ public IntPtr GetLine;
387+ public IntPtr GetLineParams;
388+ }
389+
390+ [StructLayoutAttribute(LayoutKind.Sequential)]
391+ public struct ExifData{
392+ public UInt32 NumberOfItems;
393+ [MarshalAs(UnmanagedType.LPArray)]
394+ public ExifEntry[] ItemList;
395+ }
396+
397+ [StructLayoutAttribute(LayoutKind.Sequential)]
398+ public struct ExifEntry{
399+ public GflExifEntryTypes Types;
400+ public UInt32 Tag;
401+ [MarshalAs(UnmanagedType.LPStr)]
402+ public string Name;
403+ [MarshalAs(UnmanagedType.LPStr)]
404+ public string Value;
405+ }
406+
270407 #endregion
271408
272409 #region enum
273410
274- public static Imaging.PixelFormat BitmapTypeToPixelFormat(BitmapType type){
275- switch(type){
276- case BitmapType.Binary:
277- case BitmapType.Grey:
278- case BitmapType.Colors:
279- return Imaging.PixelFormat.Format8bppIndexed;
280- case BitmapType.Rgb:
281- case BitmapType.Bgr:
282- return Imaging.PixelFormat.Format24bppRgb;
283- case BitmapType.Rgba:
284- case BitmapType.Bgra:
285- case BitmapType.Abgr:
286- case BitmapType.Argb:
287- return Imaging.PixelFormat.Format32bppArgb;
288- default:
289- return Imaging.PixelFormat.DontCare;
290- }
291- }
292-
293411 [Flags]
294412 public enum BitmapType : ushort{
295413 Binary = 0x0001,
@@ -375,6 +493,24 @@
375493 To16Bits = 4,
376494 }
377495
496+ public enum SaveOptions : uint{
497+ ReplaceExtension = 0x00000001,
498+ WantFilename = 0x00000002,
499+ SaveAnyway = 0x00000004,
500+ SaveIccProfile = 0x00000008,
501+ }
502+
503+ public enum ByteOrder : byte{
504+ Default = 0,
505+ LSBF = 1,
506+ MDBF = 2,
507+ }
508+
509+ public enum GetExifOptions : uint{
510+ None = 0,
511+ WantMakerNotes = 1,
512+ }
513+
378514 #endregion
379515 }
380516
@@ -466,7 +602,7 @@
466602 internal static GflBitmap GetGflBitmapFromFile(string path, GflProgressCallback progressCallback){
467603 Gfl.LoadParams prms = new Gfl.LoadParams();
468604 Gfl.GetDefaultLoadParams(ref prms);
469- prms.Flags = Gfl.LoadOptions.ForceColorModel;
605+ prms.Options = Gfl.LoadOptions.ForceColorModel;
470606 prms.ColorModel = Gfl.BitmapType.Bgra;
471607 if(progressCallback != null){
472608 prms.Callbacks.Progress = new Gfl.ProgressCallback(delegate(int percent, IntPtr userParams){
@@ -505,6 +641,10 @@
505641
506642 return new GflFormat(name, defaultSuffix, readable, writable, description);
507643 }
644+
645+ internal static GflExif GetGflExif(string path){
646+ return new GflExif(Gfl.LoadExif(path, Gfl.GetExifOptions.None));
647+ }
508648 }
509649
510650 public class GflFormat{
@@ -542,17 +682,19 @@
542682
543683 public Drawing.Bitmap ToBitmap(){
544684 int length = (int)this.bitmap.BytesPerLine * this.bitmap.Height;
685+
545686 Drawing.Bitmap bitmap = new Drawing.Bitmap(
546687 this.bitmap.Width,
547688 this.bitmap.Height,
548689 Imaging.PixelFormat.Format32bppArgb);
690+
549691 Imaging.BitmapData bitmapData = bitmap.LockBits(
550692 new Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
551693 Imaging.ImageLockMode.ReadWrite,
552694 bitmap.PixelFormat);
553695 Win32.CopyMemory(bitmapData.Scan0, this.bitmap.Data, length);
696+ bitmap.UnlockBits(bitmapData);
554697
555- bitmap.UnlockBits(bitmapData);
556698 return bitmap;
557699 }
558700
@@ -568,6 +710,7 @@
568710 this.info.Dispose();
569711 }
570712 if(!(this.disposed)){
713+ Gfl.FreeBitmapData(ref this.bitmap);
571714 Gfl.FreeBitmap(ref this.bitmap);
572715 this.disposed = true;
573716 }
@@ -637,12 +780,42 @@
637780 }
638781 }
639782
640- public long FileSize{
783+ public long Size{
641784 get{
642785 return (long)this.info.FileSize;
643786 }
644787 }
645788
789+ public int BitsPerComponent{
790+ get{
791+ return (int)this.info.BitsPerComponent;
792+ }
793+ }
794+
795+ public int ComponentsPerPixel{
796+ get{
797+ return (int)this.info.BitsPerComponent;
798+ }
799+ }
800+
801+ public string CompressionDescription{
802+ get{
803+ return this.info.CompressionDescription;
804+ }
805+ }
806+
807+ public int XOffset{
808+ get{
809+ return this.info.XOffset;
810+ }
811+ }
812+
813+ public int YOffset{
814+ get{
815+ return this.info.YOffset;
816+ }
817+ }
818+
646819 private bool disposed = false;
647820 protected override void Dispose(bool disposing){
648821 if(!(this.disposed)){
@@ -661,4 +834,56 @@
661834 this.ProgressPercentage = percent;
662835 }
663836 }
837+
838+ public class GflExif : Component{
839+ private ReadOnlyCollection<GflExifEntry> entries;
840+
841+ internal GflExif(Gfl.ExifData exif){
842+ GflExifEntry[] entries = new GflExifEntry[exif.NumberOfItems];
843+ for(int i = 0; i < exif.NumberOfItems; i++){
844+ entries[i] = new GflExifEntry(exif.ItemList[i]);
845+ }
846+ this.entries = new ReadOnlyCollection<GflExifEntry>(entries);
847+ }
848+
849+ public ReadOnlyCollection<GflExifEntry> Entries{
850+ get{
851+ return this.entries;
852+ }
853+ }
854+ }
855+
856+ public class GflExifEntry{
857+ public GflExifEntryTypes Types{get; private set;}
858+ public int Tag{get; private set;}
859+ public string Name{get; private set;}
860+ public string Value{get; private set;}
861+
862+ internal GflExifEntry(Gfl.ExifEntry entry){
863+ this.Types = entry.Types;
864+ this.Tag = (int)entry.Tag;
865+ this.Name = entry.Name;
866+ this.Value = entry.Value;
867+ }
868+ }
869+
870+ [Flags]
871+ public enum GflExifEntryTypes : uint{
872+ Ifd0 = 0x0001,
873+ MainIfd = 0x0002,
874+ InterOperabilityIfd = 0x0004,
875+ IfdThumbnail = 0x0008,
876+ GpsIfd = 0x0010,
877+ MakerNoteIfd = 0x0020,
878+ Maker = 0x010F,
879+ Model = 0x0110,
880+ Orientation = 0x0112,
881+ ExposureTime = 0x829A,
882+ FNumber = 0x829D,
883+ DateTimeOriginal = 0x9003,
884+ ShutterSpeed = 0x9201,
885+ Aperture = 0x9202,
886+ MaxAperture = 0x9205,
887+ FocalLength = 0x920A,
888+ }
664889 }
\ No newline at end of file
Show on old repository browser