void colors(string nombre_color, Image panel) { rgb data = new rgb(); string conn = "URI=file:" + Application.dataPath + "/Recursos/BD/dbdata.db"; IDbConnection dbconn; dbconn = (IDbConnection) new SqliteConnection(conn); dbconn.Open(); IDbCommand dbcmd = dbconn.CreateCommand(); string sqlQuery = "Select r_color,g_color,b_color from color where nombre_color = '" + nombre_color + "'"; Debug.Log(sqlQuery); dbcmd.CommandText = sqlQuery; IDataReader reader = dbcmd.ExecuteReader(); while (reader.Read()) { //int id = reader.GetInt32(0); int r = reader.GetInt32(0); int g = reader.GetInt32(1); int b = reader.GetInt32(2); data.r = r; data.g = g; data.b = b; } Debug.Log("Color = (" + data.r + "," + data.g + "," + data.b + ")"); panel.color = new Color(data.r, data.g, data.b); reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; dbconn.Close(); }
private void initEmpty() { HexValue = new hexvalue(); RGB = new rgb(); HSL = new hsl(); HSV = new hsv(); CMYK = new cmyk(); XYZ = new xyz(); Name = new name(); Image = new image(); Contrast = string.Empty; }
public static hsl toHSL(this rgb source) { hsl output = new hsl(); //GETTING 0 - 1 VALUES float r = (float)source.R / 255.0f; float g = (float)source.G / 255.0f; float b = (float)source.B / 255.0f; //FIND MAX AND MIN float min = Math.Min(Math.Min(r, g), b); float max = Math.Max(Math.Max(r, g), b); //LUMINANCE CALCULATION output.L = (min + max) / 2; //SATURATION CALCULATIONS if (min == max) { output.H = 0; output.S = 0; } else { output.S = output.L < 0.5f ? (max - min) / (max + min) : (max - min) / (2.0f - max - min); } //HUE CALCULATIONS if (r == max) { output.H = (g - b) / (max - min); } else if (g == max) { output.H = 2.0f + (b - r) / (max - min); } else { output.H = 4.0f + (r - g) / (max - min); } //Fit to circle output.H *= 60; if (output.H < 0) { output.H += 360; } return(output); }
public ColorfulRestProperty(object json) { var colorData = (ColorfulJsonParser)json; HexValue = new hexvalue(colorData.Hex); RGB = new rgb(colorData.RGB); HSL = new hsl(colorData.HSL); HSV = new hsv(colorData.HSV); CMYK = new cmyk(colorData.CMYK); XYZ = new xyz(colorData.XYZ); Name = new name(colorData.Name); Image = new image(colorData.Image); Contrast = colorData.Contrast.value; }
public static rgb toRGB(this hsl source) { rgb output = new rgb(); if (source.S == 0) //The colour is a shade of grey { float val = source.L * 255f; output.R = (int)val; output.G = (int)val; output.B = (int)val; } else //It has some saturation { float temp2 = source.L < 0.5f ? source.L * (1.0f + source.S) : source.L + source.S - (source.L * source.S); float temp1 = 2.0f * source.L - temp2; //Get all the color component output.R = (int)Math.Round(convGetColorComponent(temp1, temp2, (source.H / 360f) + 1.0f / 3.0f) * 255.0f); output.G = (int)Math.Round(convGetColorComponent(temp1, temp2, (source.H / 360f)) * 255.0f); output.B = (int)Math.Round(convGetColorComponent(temp1, temp2, (source.H / 360f) - 1.0f / 3.0f) * 255.0f); } return(output); }
/* * http://en.wikipedia.org/wiki/Demosaicing * 程式使用演算法參考 http://www.siliconimaging.com/RGB%20Bayer.htm 最簡單的內插法 * 有時候對比比較大的邊界處會有鋸齒問題 */ static void raw_demosaicing() { Console.WriteLine("\ndemosaicing..."); UInt32 r = 0, g = 0, b = 0; //有些電腦在這裡使用平行計算會產生錯亂狀況,但是我家電腦正常 //不過基於穩定性,這地方也沒佔多少時間,因此改成一般處理 for (int i = height_m; i < raw_height - height_m; i++) { for (int j = 2; j < width + 2; j++) { { /* * 這裡的寫法並不是很理想,使用cow與col數字積偶與大小來判斷內插處理的序列,使用patten filter表來對照會比較好, * 適對應patten來切換bayer filter,也由於直接用程式寫死,因此有些 rw2 檔解出來色彩會不正確或是序列錯誤, * 其實 rw2 內有附帶資訊,告知使用哪種bayer patten,詳細參考dcraw. */ //這裡的邏輯需要重新檢查確一下 //不過結果似乎沒啥問題....神奇 if (filters == 2 || filters == 3) { //處理g if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0) { g = raw_image[i + 1, j + 1]; } else { g = (UInt16)((raw_image[i, j + 1] + raw_image[i + 2, j + 1] + raw_image[i + 1, j + 2] + raw_image[i + 1, j]) / 4.0); } //處理b if ((j - 2) % 2 == 0 && (i - height_m) % 2 == 1) { b = raw_image[i + 1, j + 1]; } else if ((i - height_m) % 2 == 0 && (j - 2) % 2 == 1) { b = (UInt16)((raw_image[i, j] + raw_image[i, j + 2] + raw_image[i + 2, j] + raw_image[i + 2, j + 2]) / 4.0); } else if (Math.Abs((int)i - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 0) { b = (UInt16)((raw_image[i, j + 1] + raw_image[i + 2, j + 1]) / 2.0); } else if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 1) { b = (UInt16)((raw_image[i + 1, j] + raw_image[i + 1, j + 2]) / 2.0); } //處理r if ((i - height_m) % 2 == 0 && (j - 2) % 2 == 1) { r = raw_image[i + 1, j + 1]; } else if ((j - 2) % 2 == 0 && (i - height_m) % 2 == 1) { r = (UInt16)((raw_image[i, j] + raw_image[i, j + 2] + raw_image[i + 2, j] + raw_image[i + 2, j + 2]) / 4.0); } else if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 1) { r = (UInt16)((raw_image[i, j + 1] + raw_image[i + 2, j + 1]) / 2.0); } else if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 0) { r = (UInt16)((raw_image[i + 1, j] + raw_image[i + 1, j + 2]) / 2.0); } if (filters == 2) { UInt32 tmp = r; r = b; b = tmp; } } //type 1 & 4 邏輯規則跟 2 & 3剛好相反,先確定2&3無誤,再繼續實作1&4 if (filters == 1 || filters == 4) { } r = (UInt32)(((float)r) * scale_mul[0]); g = (UInt32)(((float)g) * scale_mul[1]); b = (UInt32)(((float)b) * scale_mul[2]); // if (r > 4095) r = 4095; // if (g > 4095) g = 4095; // if (b > 4095) b = 4095; //經過白平衡修正參數處理,已經將範圍正規化到16bits //因此上限最大值改為65535 if (r > 65535) { r = 65535; } if (g > 65535) { g = 65535; } if (b > 65535) { b = 65535; } if (r < 0) { r = 0; } if (g < 0) { g = 0; } if (b < 0) { b = 0; } demosaicing_image[j - 2, i - height_m] = new rgb(); demosaicing_image[j - 2, i - height_m].r = (ushort)r; demosaicing_image[j - 2, i - height_m].g = (ushort)g; demosaicing_image[j - 2, i - height_m].b = (ushort)b; } } } Console.WriteLine("demosaicing done."); }
/* * http://en.wikipedia.org/wiki/Demosaicing * 程式使用演算法參考 http://www.siliconimaging.com/RGB%20Bayer.htm 最簡單的內插法 * 有時候對比比較大的邊界處會有鋸齒問題 */ static void raw_demosaicing() { Console.WriteLine("\ndemosaicing..."); UInt32 r = 0, g = 0, b = 0; //有些電腦在這裡使用平行計算會產生錯亂狀況,但是我家電腦正常 //不過基於穩定性,這地方也沒佔多少時間,因此改成一般處理 for (int i = height_m; i < raw_height - height_m; i++) for (int j = 2; j < width + 2; j++) { { /* * 這裡的寫法並不是很理想,使用cow與col數字積偶與大小來判斷內插處理的序列,使用patten filter表來對照會比較好, * 適對應patten來切換bayer filter,也由於直接用程式寫死,因此有些 rw2 檔解出來色彩會不正確或是序列錯誤, * 其實 rw2 內有附帶資訊,告知使用哪種bayer patten,詳細參考dcraw. */ //這裡的邏輯需要重新檢查確一下 //不過結果似乎沒啥問題....神奇 if (filters == 2 || filters == 3) { //處理g if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0) g = raw_image[i + 1, j + 1]; else g = (UInt16)((raw_image[i, j + 1] + raw_image[i + 2, j + 1] + raw_image[i + 1, j + 2] + raw_image[i + 1, j]) / 4.0); //處理b if ((j - 2) % 2 == 0 && (i - height_m) % 2 == 1) b = raw_image[i + 1, j + 1]; else if ((i - height_m) % 2 == 0 && (j - 2) % 2 == 1) b = (UInt16)((raw_image[i, j] + raw_image[i, j + 2] + raw_image[i + 2, j] + raw_image[i + 2, j + 2]) / 4.0); else if (Math.Abs((int)i - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 0) b = (UInt16)((raw_image[i, j + 1] + raw_image[i + 2, j + 1]) / 2.0); else if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 1) b = (UInt16)((raw_image[i + 1, j] + raw_image[i + 1, j + 2]) / 2.0); //處理r if ((i - height_m) % 2 == 0 && (j - 2) % 2 == 1) r = raw_image[i + 1, j + 1]; else if ((j - 2) % 2 == 0 && (i - height_m) % 2 == 1) r = (UInt16)((raw_image[i, j] + raw_image[i, j + 2] + raw_image[i + 2, j] + raw_image[i + 2, j + 2]) / 4.0); else if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 1) r = (UInt16)((raw_image[i, j + 1] + raw_image[i + 2, j + 1]) / 2.0); else if (Math.Abs((int)(i - height_m) - (int)(j - 2)) % 2 == 0 && (i - height_m) % 2 == 0) r = (UInt16)((raw_image[i + 1, j] + raw_image[i + 1, j + 2]) / 2.0); if (filters == 2) { UInt32 tmp = r; r = b; b = tmp; } } //type 1 & 4 邏輯規則跟 2 & 3剛好相反,先確定2&3無誤,再繼續實作1&4 if (filters == 1 || filters == 4) { } r = (UInt32)(((float)r) * scale_mul[0]); g = (UInt32)(((float)g) * scale_mul[1]); b = (UInt32)(((float)b) * scale_mul[2]); // if (r > 4095) r = 4095; // if (g > 4095) g = 4095; // if (b > 4095) b = 4095; //經過白平衡修正參數處理,已經將範圍正規化到16bits //因此上限最大值改為65535 if (r > 65535) r = 65535; if (g > 65535) g = 65535; if (b > 65535) b = 65535; if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; demosaicing_image[j - 2, i - height_m] = new rgb(); demosaicing_image[j - 2, i - height_m].r = (ushort)r; demosaicing_image[j - 2, i - height_m].g = (ushort)g; demosaicing_image[j - 2, i - height_m].b = (ushort)b; } } Console.WriteLine("demosaicing done."); }
private void obtenerDatos1(int id) { byte[] son = new byte[0]; byte[] imagen_personaje = new byte[0]; string conn = "URI=file:" + Application.dataPath + "/Recursos/BD/dbdata.db"; IDbConnection dbconn; dbconn = (IDbConnection) new SqliteConnection(conn); dbconn.Open(); IDbCommand dbcmd = dbconn.CreateCommand(); string sqlQuery; sqlQuery = "select t2.r_color, t2.g_color, t2.b_color, t3.id_personaje, t4.nombre_ubicacion, t3.audio_personaje, t3.imagen_personaje from detalle_aprendizaje as t1 inner join color as t2 on t2.id = t1.id_color inner join personaje as t3 on t1.id_personaje = t3.id_personaje inner join ubicacion as t4 on t1.id_ubicacion = t4.id where t1.id_detalle_apre = " + id; Debug.Log(sqlQuery); dbcmd.CommandText = sqlQuery; IDataReader reader = dbcmd.ExecuteReader(); while (reader.Read()) { nombre_ubicacion = reader.GetString(4); id_personaje_1 = reader.GetInt32(3); imagen_personaje = (byte[])reader["imagen_personaje"]; son = (byte[])reader["audio_personaje"]; if (nombre_ubicacion == "izquierda arriba") { Color_cuadrante_1 = new rgb(); id_boton_1 = id_personaje_1; Color_cuadrante_1.r = reader.GetInt32(0); Color_cuadrante_1.g = reader.GetInt32(1); Color_cuadrante_1.b = reader.GetInt32(2); } if (nombre_ubicacion == "izquierda abajo") { Color_cuadrante_2 = new rgb(); id_boton_2 = id_personaje_1; Color_cuadrante_2.r = reader.GetInt32(0); Color_cuadrante_2.g = reader.GetInt32(1); Color_cuadrante_2.b = reader.GetInt32(2); } if (nombre_ubicacion == "derecha abajo") { Color_cuadrante_3 = new rgb(); id_boton_3 = id_personaje_1; Color_cuadrante_3.r = reader.GetInt32(0); Color_cuadrante_3.g = reader.GetInt32(1); Color_cuadrante_3.b = reader.GetInt32(2); } if (nombre_ubicacion == "derecha arriba") { Color_cuadrante_4 = new rgb(); id_boton_4 = id_personaje_1; Color_cuadrante_4.r = reader.GetInt32(0); Color_cuadrante_4.g = reader.GetInt32(1); Color_cuadrante_4.b = reader.GetInt32(2); } if (nombre_ubicacion == "izquierda medio") { Color_cuadrante_5 = new rgb(); id_boton_5 = id_personaje_1; Color_cuadrante_5.r = reader.GetInt32(0); Color_cuadrante_5.g = reader.GetInt32(1); Color_cuadrante_5.b = reader.GetInt32(2); } if (nombre_ubicacion == "abajo medio") { Color_cuadrante_6 = new rgb(); id_boton_6 = id_personaje_1; Color_cuadrante_6.r = reader.GetInt32(0); Color_cuadrante_6.g = reader.GetInt32(1); Color_cuadrante_6.b = reader.GetInt32(2); } if (nombre_ubicacion == "derecha medio") { Color_cuadrante_7 = new rgb(); id_boton_7 = id_personaje_1; Color_cuadrante_7.r = reader.GetInt32(0); Color_cuadrante_7.g = reader.GetInt32(1); Color_cuadrante_7.b = reader.GetInt32(2); } if (nombre_ubicacion == "arriba medio") { Color_cuadrante_8 = new rgb(); id_boton_8 = id_personaje_1; Color_cuadrante_8.r = reader.GetInt32(0); Color_cuadrante_8.g = reader.GetInt32(1); Color_cuadrante_8.b = reader.GetInt32(2); } if (nombre_ubicacion == "medio centro") { Color_cuadrante_9 = new rgb(); id_boton_9 = id_personaje_1; Color_cuadrante_9.r = reader.GetInt32(0); Color_cuadrante_9.g = reader.GetInt32(1); Color_cuadrante_9.b = reader.GetInt32(2); } } WAV sonido = new WAV(son); audio_personaje_1 = AudioClip.Create("personaje_1", sonido.SampleCount, 1, sonido.Frequency, false, false); audio_personaje_1.SetData(sonido.LeftChannel, 0); if (nombre_ubicacion == "izquierda arriba") { textura_pos_A = new Texture2D(256, 256); textura_pos_A.LoadImage(imagen_personaje); } if (nombre_ubicacion == "izquierda abajo") { textura_pos_B = new Texture2D(256, 256); textura_pos_B.LoadImage(imagen_personaje); } if (nombre_ubicacion == "derecha abajo") { textura_pos_C = new Texture2D(256, 256); textura_pos_C.LoadImage(imagen_personaje); } if (nombre_ubicacion == "derecha arriba") { textura_pos_D = new Texture2D(256, 256); textura_pos_D.LoadImage(imagen_personaje); } if (nombre_ubicacion == "izquierda medio") { textura_pos_E = new Texture2D(256, 256); textura_pos_E.LoadImage(imagen_personaje); } if (nombre_ubicacion == "abajo medio") { textura_pos_F = new Texture2D(256, 256); textura_pos_F.LoadImage(imagen_personaje); } if (nombre_ubicacion == "derecha medio") { textura_pos_G = new Texture2D(256, 256); textura_pos_G.LoadImage(imagen_personaje); } if (nombre_ubicacion == "arriba medio") { textura_pos_H = new Texture2D(256, 256); textura_pos_H.LoadImage(imagen_personaje); } if (nombre_ubicacion == "medio centro") { textura_pos_I = new Texture2D(256, 256); textura_pos_I.LoadImage(imagen_personaje); } reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; dbconn.Close(); nombre_ubicacion = ""; StartCoroutine(playsound(audio_personaje_1)); }