private void button1_Click(object sender, EventArgs e) { CalibrationProcessLib.CalibrationProcess calibrationProcess = new CalibrationProcessLib.CalibrationProcess(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = true; openFileDialog.Filter = "*.zdat|*.zdat"; if (openFileDialog.ShowDialog(this) == DialogResult.Cancel) { return; } string[] srcFile = openFileDialog.FileNames; FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); if (folderBrowserDialog.ShowDialog(this) == DialogResult.Cancel) { return; } string targetPath = folderBrowserDialog.SelectedPath; string error = "文件:"; bool hasError = false; foreach (var item in srcFile) { string fileName = System.IO.Path.Combine(targetPath, System.IO.Path.GetFileNameWithoutExtension(item) + ".dat"); if (!calibrationProcess.TranslateZdatToDat(item, CabinetSize.GetPixelWidth(), CabinetSize.GetPixelHeight(), fileName, 1)) { error += item + ";"; hasError = true; } error += "转换失败"; } if (hasError) { MessageBox.Show(this, error); } }
private void btnCreateCal_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "*.zdat|*.zdat"; if (saveFileDialog.ShowDialog(this) == DialogResult.Cancel) { return; } byte[] srcData = new byte[_width * _height * 18]; if (ckRandom.Checked) { Random rnd = new Random(); rnd.NextBytes(srcData); } else { for (int i = 0; i < srcData.Length; i++) { srcData[i] = (byte)numCalInitData.Value; } } byte specData = (byte)numSpecData.Value; string[] specRow = txtSpeRow.Text.Split(';'); if (specRow.Length != 0) { for (int i = 0; i < specRow.Length; i++) { int row = 0; if (int.TryParse(specRow[i], out row)) { int rowStartPos = row * _width * 18; for (int j = 0; j < _width; j++) { for (int k = 0; k < 9; k++) { int colPos = rowStartPos + j * 18 + 2 * k; srcData[colPos] = HiByte(specData); colPos = rowStartPos + j * 18 + 2 * k + 1; srcData[colPos] = LoByte(specData); } } } } } specData = (byte)numSpecCol.Value; string[] specCol = txtSpecCol.Text.Split(';'); if (specCol.Length != 0) { for (int i = 0; i < specCol.Length; i++) { int col = 0; if (int.TryParse(specCol[i], out col)) { for (int j = 0; j < _height; j++) { int rowStartPos = j * _width * 18; for (int k = 0; k < 9; k++) { int colPos = rowStartPos + col * 18 + 2 * k; srcData[colPos] = HiByte(specData); colPos = rowStartPos + col * 18 + 2 * k + 1; srcData[colPos] = LoByte(specData); } } } } } byte[] newData = new byte[_width * _height * 16]; int pos = 0; byte[] oldPixelData = new byte[18]; byte[] newPixelData = new byte[16]; int nLeftMove = 5;//2017-11-16 nLeftMove = nLeftMove + 1; ushort uMask = (ushort)(0xFF << nLeftMove);//构造掩码 for (int pt = 0; pt < _width * _height; pt++) { pos = 0; //获取一个像素的数据 Array.Copy(srcData, pt * 18, oldPixelData, 0, 18); //清空一个像素的新数据 for (int k = 0; k < 16; k++) { newPixelData[k] = 0; } //进行转换 for (int i = 0; i < 9; i++) { ushort old = (ushort)((oldPixelData[2 * i] << 8) | oldPixelData[2 * i + 1]); //2017-11-16 modify //byte newVal = (byte)((old & 0x1FE0) >> 5);//16->8 bit byte newVal = (byte)((old & uMask) >> nLeftMove);//16->8 bit if (i == 0) { //红色主色 newPixelData[pos] = oldPixelData[2 * i]; newPixelData[pos + 1] = oldPixelData[2 * i + 1]; pos += 2; } else if (i == 4) { //绿色主色 newPixelData[pos] = oldPixelData[2 * i]; newPixelData[pos + 1] = oldPixelData[2 * i + 1]; pos += 2; } else if (i == 8) { //蓝色主色 newPixelData[pos] = oldPixelData[2 * i]; newPixelData[pos + 1] = oldPixelData[2 * i + 1]; pos += 2; } else { //普通点 newPixelData[pos] = newVal; pos++; } } Array.Copy(newPixelData, 0, newData, pt * 16, 16); } string dirName = System.IO.Path.GetDirectoryName(saveFileDialog.FileName); string fileNameWithoutExt = "All"; string zdat = System.IO.Path.Combine(dirName, fileNameWithoutExt + ".zdat"); string sdat = System.IO.Path.Combine(dirName, fileNameWithoutExt + ".sdat"); string dat = System.IO.Path.Combine(dirName, fileNameWithoutExt + ".dat"); FileStream writer = null; try { //ZDAT writer = new FileStream(zdat, FileMode.Create, FileAccess.Write); writer.Write(newData, 0, newData.Length); } catch { } finally { newData = null; } writer.Flush(); writer.Close(); string divideFolder = System.IO.Path.Combine(dirName, "Divide"); if (!Directory.Exists(divideFolder)) { Directory.CreateDirectory(divideFolder); } CalibrationProcessLib.CalibrationProcess calibrationProcess = new CalibrationProcessLib.CalibrationProcess(); calibrationProcess.TranslateZdatToSdat(zdat, CabinetSize.GetPixelWidth(), CabinetSize.GetPixelHeight(), sdat, 1); calibrationProcess.TranslatezData2dat(zdat, CabinetSize.GetPixelWidth(), CabinetSize.GetPixelHeight(), dat, 1); //TVComm.TV71.TW30Oper _caliDivideOper = TVComm.TV71.TW30Oper.LoadLibrary(System.IO.Path.Combine(exePath, @"Libs\LeyardTW30forCalibration.dll")); ;//仅用于校正数据拆分 //_caliDivideOper.SysCorrectionFileDivide(CabinetSize.ModuleHeight, CabinetSize.ModuleWidth, CabinetSize.GetPixelWidth(), CabinetSize.GetPixelHeight(), sdat, divideFolder); calibrationProcess.DivideCalibrationFile(sdat, CabinetSize.ModuleWidth, CabinetSize.ModuleHeight, CabinetSize.ModulePixelWidth, CabinetSize.ModulePixelHeight, divideFolder, CalibrationProcessLib.EnumCalibrationType.Dat); for (int i = 0; i < CabinetSize.ModuleHeight; i++) { for (int j = 0; j < CabinetSize.ModuleWidth; j++) { string datFile = System.IO.Path.Combine(divideFolder, i + "_" + j + ".dat"); string zdatFile = System.IO.Path.Combine(divideFolder, i + "_" + j + ".zdat"); calibrationProcess.TranslateDat2zdat(datFile, CabinetSize.ModulePixelWidth, CabinetSize.ModulePixelHeight, zdatFile, 1); } } }
private void btnDivide_Click(object sender, EventArgs e) { CalibrationProcessLib.CalibrationProcess calibrationProcess = new CalibrationProcessLib.CalibrationProcess(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = false; openFileDialog.Filter = "*.sdat|*.sdat|*.dat|*.dat"; if (openFileDialog.ShowDialog(this) == DialogResult.Cancel) { return; } string[] srcFile = openFileDialog.FileNames; FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); if (folderBrowserDialog.ShowDialog(this) == DialogResult.Cancel) { return; } string targetPath = folderBrowserDialog.SelectedPath; string error = "文件:"; bool hasError = false; foreach (var item in srcFile) { //if (!calibrationProcess.DivideCalibrationFile(item, CabinetSize.ModuleWidth, CabinetSize.ModuleHeight, CabinetSize.ModulePixelWidth, CabinetSize.ModulePixelHeight, targetPath, CalibrationProcessLib.EnumCalibrationType.Sdat)) if (!(_oper.sys_CorrectionFile_divide(CabinetSize.ModuleHeight, CabinetSize.ModuleWidth, CabinetSize.GetPixelWidth(), CabinetSize.GetPixelHeight(), item, targetPath) == 0 ? true : false)) { error += "转换失败"; hasError = true; } for (int i = 0; i < CabinetSize.ModuleHeight; i++) { for (int j = 0; j < CabinetSize.ModuleWidth; j++) { string datFile = System.IO.Path.Combine(targetPath, i + "_" + j + ".dat"); string zdatFile = System.IO.Path.Combine(targetPath, i + "_" + j + ".zdat"); calibrationProcess.TranslateDat2zdat(datFile, CabinetSize.ModulePixelWidth, CabinetSize.ModulePixelHeight, zdatFile, 1); } } } if (hasError) { MessageBox.Show(this, error); } }