private static void stegImageByImageType(string path, BitArray baBits, int securityLevel) { var trimPath = path.ToLower().Trim(); // Check image type if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG { JpegHelper.StegBinary(path, baBits, securityLevel); } else if (trimPath.EndsWith(".bmp")) // BITMAP { BmpHelper.StegBinary(path, baBits, securityLevel); } else if (trimPath.EndsWith(".png")) // PNG { PngHelper.StegBinary(path, baBits, securityLevel); } else if (trimPath.EndsWith(".gif")) // GIF { GifHelper.StegBinary(path, baBits); } else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF { TifHelper.StegBinary(path, baBits, securityLevel); } else if (!string.IsNullOrEmpty(trimPath)) { MessageBox.Show("Wrong extension.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information); } }
void appBarIconBtnSave_Click(object sender, EventArgs e) { try { using (MemoryStream ms = new MemoryStream()) { //이미지 로드 WriteableBitmap wb = ImgDetail.Source as WriteableBitmap; wb.SaveJpeg(ms, wb.PixelWidth, wb.PixelHeight, 0, 100); //마지막 항목 사진중심으로 잘라내기는 사용하지 않음 //JpegHelper.Save(NavigationContext.QueryString["imgName"], wb, ms, false); string name = NavigationContext.QueryString["imgName"]; //축소 가능한 이미지라면 축소 JpegHelper.Resize(wb, ms, ResolutionHelper.CurrentResolution, false); //이미지 파일 저장 FileHelper.SaveImage(name, ms); //썸네일 만들기 (이미지의 중심 비율등이 변경될 수 있으므로 재생성해서 덮어쓰기) JpegHelper.Resize(wb, ms, LockscreenHelper.ThumnailSize, true); //썸네일 저장 FileHelper.SaveImage(name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_THUMNAIL_POSTFIX), ms); //현재 프레임으로 자르기 WriteableBitmap cropImage = GetCropImage(); //락스크린용 이미지로 축소 또는 확대 JpegHelper.Resize(cropImage, ms, LockscreenHelper.Size, false); //락스크린 파일 저장 FileHelper.SaveImage(name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_READY_POSTFIX), ms); } MessageBox.Show(AppResources.MsgSuccessSaveImage); } catch (Exception ex) { MessageBox.Show(string.Format(AppResources.MsgFailSaveImage, ex.Message)); } }
public override void Decode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { if (oldPixelData.NumberOfFrames == 0) { return; } // IJG eats the extra padding bits. Is there a better way to test for this? if (newPixelData.BitsAllocated == 16 && newPixelData.BitsStored <= 8) { // check for embedded overlays here or below? newPixelData.BitsAllocated = 8; } var jparams = parameters as DicomJpegParams ?? GetDefaultParameters() as DicomJpegParams; var oldNativeData = oldPixelData.ToNativePixelData(); int precision; try { try { precision = JpegHelper.ScanJpegForBitDepth(oldPixelData); } catch { // if the internal scanner chokes on an image, try again using ijg precision = new Jpeg12Codec(JpegMode.Baseline, 0, 0).ScanHeaderForPrecision(oldNativeData); } } catch { // the old scanner choked on several valid images... // assume the correct encoder was used and let libijg handle the rest precision = oldPixelData.BitsStored; } if (newPixelData.BitsStored <= 8 && precision > 8) { newPixelData.BitsAllocated = 16; // embedded overlay? } var codec = GetCodec(precision, jparams); var newNativeData = newPixelData.ToNativePixelData(); var jNativeParams = jparams.ToNativeJpegParameters(); for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++) { codec.Decode(oldNativeData, newNativeData, jNativeParams, frame); } }
private byte[] DecodeBlocks(JBLOCK[][][] coefficients, int length) { using (var ms = new MemoryStream()) { for (var i = 0; i < length / BytesPerBlock + 1; i++) { var d = DecodeBlock(JpegHelper.GetBlock(coefficients, i)); ms.Write(d, 0, d.Length); } return(ms.GetBuffer().Take(length).ToArray()); } }
private byte[] Decrypt(JBLOCK[][][] coefficients, int length) { var res = new byte[length]; for (var i = 0; i < length; i++) { for (var j = 0; j < 8; j++) { var block = JpegHelper.GetBlock(coefficients, i * 8 + j); BitHelper.SetBit(ref res[i], j, DecryptShort(block[0])); } } return(res); }
private void MenuItem_Jpeg(object sender, RoutedEventArgs e) { var dialog = new JPEGdialog(); dialog.ShowDialog(); if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { var jpeg = JpegHelper.JpegSteps(Img1, Size, dialog.subsamplingType.Text, getQuantizingType[dialog.quantizationType.Text], int.Parse(dialog.alphaY.Text), int.Parse(dialog.gammaY.Text), int.Parse(dialog.alphaC.Text), int.Parse(dialog.gammaC.Text), int.Parse(dialog.nY.Text), int.Parse(dialog.nC.Text)); Img1.Source = jpeg; } }
private void Encrypt(JBLOCK[][][] coefficients, byte[] data) { var l = JpegHelper.GetLength(coefficients); Console.Out.WriteLine($"Capacity = {l / 8}"); Console.Out.WriteLine("Used = {0}", data.Length); for (var i = 0; i < data.Length; i++) { for (var j = 0; j < 8; j++) { var block = JpegHelper.GetBlock(coefficients, i * 8 + j); block[0] = EncryptShort(block[0], BitHelper.GetBit(data[i], j)); } } }
//단건 폰사진 추가 완료 이벤트 핸들러 void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { if (LockscreenSelector.ItemsSource.Count < Constants.LOCKSCREEN_MAX_COUNT) { using (Stream stream = e.ChosenPhoto) { JpegHelper.Save(FileHelper.GetUniqueFileName(Constants.LOCKSCREEN_IMAGE_POSTFIX), stream); } } else { MessageBox.Show(string.Format(AppResources.MsgFailAddMaxCount, Constants.LOCKSCREEN_MAX_COUNT)); } } }
void bgPhoneLoader_ProgressChanged(object sender, ProgressChangedEventArgs e) { object[] args = e.UserState as object[]; ChameleonAlbum phoneAlbum = args[0] as ChameleonAlbum; Picture picture = args[1] as Picture; using (Stream stream = picture.GetImage()) { WriteableBitmap bitmap = JpegHelper.Resize(stream, new Size(200, 200), true); phoneAlbum.Add(new PhonePicture() { SourceOrigin = SourceOrigin.Phone, AlbumName = picture.Album.Name, ImageSource = bitmap, Name = picture.Name }); } }
private void EncodeBlocks(JBLOCK[][][] coefficients, byte[] data) { var l = JpegHelper.GetLength(coefficients); Console.Out.WriteLine($"Capacity = {l * BytesPerBlock}"); EnforcePadding(data, BytesPerBlock); Console.Out.WriteLine("Used = {0}", data.Length); for (var i = 0; i < data.Length / BytesPerBlock; i++) { var block = JpegHelper.GetBlock(coefficients, i); EncodeBlock(block, data.Skip(i * BytesPerBlock).Take(BytesPerBlock).ToArray()); if (i % 100 == 0) { Console.WriteLine($"{i} bytes encrypted"); } } }
void appBarIconBtnAdd_Click(object sender, EventArgs e) { if (Constants.LOCKSCREEN_MAX_COUNT - LockscreenHelper.CurrentListCount == 0) { MessageBox.Show(string.Format(AppResources.MsgFailAddMaxCount, Constants.LOCKSCREEN_MAX_COUNT)); return; } try { WriteableBitmap bitmap = new WriteableBitmap(ImgDetail.Source as BitmapImage); JpegHelper.Save(FileHelper.GetUniqueFileName(Constants.LOCKSCREEN_IMAGE_POSTFIX), bitmap); MessageBox.Show(AppResources.MsgSuccessAddLockscreen); NavigationService.GoBack(); } catch (Exception ex) { MessageBox.Show(string.Format(AppResources.MsgFailAddLockscreen, ex.Message)); } }
private void imageDownloader_ImageOpened(object sender, RoutedEventArgs e) { try { WriteableBitmap wb = new WriteableBitmap(sender as BitmapImage); JpegHelper.Save(FileHelper.GetUniqueFileName(Constants.LOCKSCREEN_IMAGE_POSTFIX), wb); downloadingItem.DownloadStatus = AppResources.ImageStatusAdded; downloadingItem.DownloadStatusCode = DownloadStatus.Completed; //다운로드 완료된 파일을 숨김 처리 AsyncCollapseDownloadItem(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); downloadingItem.DownloadStatus = AppResources.ImageStatusFailAdd; downloadingItem.DownloadStatusCode = DownloadStatus.SaveFailed; } finally { downloadingItem.DownloadNetwork = string.Empty; DelayStartDownload(); } }
private bool Resize(WriteableBitmap wb, Stream stream, Size size, bool isCenterCrop, DownloadItem item, ManualResetEvent done) { bool isResized = false; done.Reset(); Dispatcher.BeginInvoke(() => { try { isResized = JpegHelper.Resize(wb, stream, size, isCenterCrop); } catch (Exception ex) { item.DownloadStatusCode = DownloadStatus.SaveFailed; System.Diagnostics.Debug.WriteLine(ex.Message); } finally { done.Set(); } }); done.WaitOne(); return(isResized); }
private void getSlotsByImageType(string imagePath) { var trimPath = imagePath.ToLower().Trim(); // Check image type if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG { // Available slots not 0 - DCT values 0 won't be overwritten var dctCoeffs = JpegHelper.GetDctCoefficients(imagePath); // 2 bits for each dct coefficient (0 values are skpped) _slots = 2 * dctCoeffs.DctFullAc.Where(s => 0 != s).Count() - HEADER_BITS_LEN; } else if (trimPath.EndsWith(".bmp")) // BITMAP { _slots = BmpHelper.GetAvailableSlots(imagePath) - HEADER_BITS_LEN; } else if (trimPath.EndsWith(".png")) // PNG { _slots = PngHelper.GetAvailableSlots(imagePath) - HEADER_BITS_LEN; } else if (trimPath.EndsWith(".gif")) // GIF { sldSecLevel.Value = 1; _slots = GifHelper.GetAvailableSlots(imagePath) - HEADER_BITS_IDX_LEN; } else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF { sldSecLevel.Value = 1; _slots = TifHelper.GetAvailableSlots(imagePath) - HEADER_BITS_IDX_LEN; } if (_slots < 10) { tbxSlots.Text = tbxSlotsUsed.Text = tbxSlotsLeft.Text = "0"; MessageBox.Show("Image not suitable for embedding content.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information); } }
private static StegModel unstegImageByImageType(string path) { var sm = new StegModel(); var trimPath = path.ToLower().Trim(); // Check image type if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG { var stegStruct = JpegHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".bmp")) // BITMAP { var stegStruct = BmpHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".png")) // PNG { var stegStruct = PngHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".gif")) // GIF { var stegStruct = GifHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF { var stegStruct = TifHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (!string.IsNullOrEmpty(trimPath)) { MessageBox.Show("Wrong extension.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information); } return(sm); }
private void SetLockscreen(PhonePicture picture, WriteableBitmap wb, Stream beforeImageStream) { string fileName = picture.Name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_A_POSTFIX); Uri currentImage = null; try { currentImage = LockScreen.GetImageUri(); } catch (Exception) { MessageBox.Show(AppResources.MsgFailGetLockscreen); HideLoadingPanel(); return; } if (currentImage != null && currentImage.ToString().EndsWith(Constants.LOCKSCREEN_IMAGE_A_POSTFIX)) { fileName = picture.Name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_B_POSTFIX); } using (MemoryStream ms = new MemoryStream()) { //축소/확대 가능한 이미지라면 축소/확대 JpegHelper.Resize(wb, ms, ResolutionHelper.CurrentResolution, true); FileHelper.SaveImage(fileName, ms); LockscreenHelper.SetLockscreen(fileName, false, (result) => { if (result.AsyncState is string) { MessageBox.Show(AppResources.MsgFailChangeLockscreen); } else if (result.AsyncState is bool && (bool)result.AsyncState == true) { if (currentImage != null && currentImage.ToString().StartsWith(Constants.PREFIX_APP_DATA_FOLDER)) { fileName = currentImage.ToString().Replace(Constants.PREFIX_APP_DATA_FOLDER, string.Empty); FileHelper.RemoveImage(fileName); } for (int i = 0; i < LockscreenSelector.ItemsSource.Count; i++) { PhonePicture pic = (LockscreenSelector.ItemsSource as ChameleonAlbum)[i] as PhonePicture; if (pic.CurrentLockscreen != null) { pic.CurrentLockscreen = null; pic.Margin = new Thickness(); } //자기자신으로 변경한 경우 및 새롭게 변경된 아이템 if (pic.Guid.CompareTo(picture.Guid) == 0) { pic.CurrentLockscreen = currentLockscreenUri; pic.Margin = currentLockscreenMargin; } } //표시항목들이 적용되지 않은 잘라내기가 수행된 이미지 데이터 if (picture.Warnning != null && beforeImageStream != null) { if (MessageBox.Show(AppResources.MsgEditedAutomatically, AppResources.Confirm, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { //ready 파일 저장 //락스크린용 이미지로 축소 WriteableBitmap rwb = JpegHelper.Resize(beforeImageStream, LockscreenHelper.Size, true); using (MemoryStream rms = new MemoryStream()) { rwb.SaveJpeg(rms, rwb.PixelWidth, rwb.PixelHeight, 0, 100); FileHelper.SaveImage(picture.Name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_READY_POSTFIX), rms); } //상태 변경 picture.Warnning = null; //경고 메세지 제어 bool isShowWarn = false; foreach (PhonePicture pic in LockscreenSelector.ItemsSource as ChameleonAlbum) { if (pic.Warnning != null) { isShowWarn = true; break; } } LockscreenEditWarnning = isShowWarn; SetSchedulerChagendTime(false); //MessageBox.Show(AppResources.MsgSuccessChangeLockscreen); } } else { SetSchedulerChagendTime(false); //MessageBox.Show(AppResources.MsgSuccessChangeLockscreen); } if (beforeImageStream != null) { //스트림 종료 beforeImageStream.Close(); } } HideLoadingPanel(); }); } }
//락스크린 리스트 로딩 public void LoadLockscreenList() { //락스크린 썸네일 이미지 크기 설정 LockscreenSelector.GridCellSize = LockscreenHelper.ThumnailSize; ChameleonAlbum phoneAlbum = LockscreenSelector.ItemsSource as ChameleonAlbum; if (phoneAlbum == null) { phoneAlbum = new ChameleonAlbum(); LockscreenSelector.ItemsSource = phoneAlbum; } using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { var imgNames = from element in isoStore.GetFileNames() where element.Contains(Constants.LOCKSCREEN_IMAGE_POSTFIX) orderby element.Substring(0, element.IndexOf("_")) ascending select element; Uri lockscreenFileUri = null; try { lockscreenFileUri = LockScreen.GetImageUri(); } catch (Exception) { } string lockscreenFileName = null; if (lockscreenFileUri != null) { lockscreenFileName = lockscreenFileUri.ToString() .Replace(Constants.PREFIX_APP_DATA_FOLDER, string.Empty) .Replace(Constants.LOCKSCREEN_IMAGE_A_POSTFIX, Constants.LOCKSCREEN_IMAGE_POSTFIX) .Replace(Constants.LOCKSCREEN_IMAGE_B_POSTFIX, Constants.LOCKSCREEN_IMAGE_POSTFIX); } foreach (string imgName in imgNames) { bool isReady = isoStore.GetFileNames(imgName.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_READY_POSTFIX)).Any(); var pic = from element in phoneAlbum where element.Name == imgName select element; if (pic.Any()) { //원래 존재하는 이름이므로 해당 파일에 대한 정보를 업데이트 처리 PhonePicture curPic = pic.First() as PhonePicture; if (curPic.Name == lockscreenFileName) { curPic.CurrentLockscreen = currentLockscreenUri; curPic.Margin = currentLockscreenMargin; } else { curPic.CurrentLockscreen = null; curPic.Margin = new Thickness(); } //이미지 변경 시간을 체크해서, 이미지가 편집이 되었다면 이미지를 다시 로드 DateTimeOffset offset = isoStore.GetLastWriteTime(imgName); if (offset.Subtract(curPic.DateTimeOffset).Milliseconds != 0) { curPic.DateTimeOffset = offset; WriteableBitmap bitmap = null; string thumbName = imgName.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_THUMNAIL_POSTFIX); string[] thumbs = isoStore.GetFileNames(thumbName); //썸네일이 없는 경우면 원본 이름을 셋팅 if (thumbs == null || thumbs.Length == 0) { thumbName = imgName; } //이미지 로드 using (IsolatedStorageFileStream sourceStream = isoStore.OpenFile(thumbName, FileMode.Open, FileAccess.Read)) { //썸네일이 없는 경우면 원본을 리사이징 if (thumbs == null || thumbs.Length == 0) { bitmap = JpegHelper.Resize(sourceStream, LockscreenHelper.ThumnailSize, true); } else { bitmap = BitmapFactory.New(0, 0).FromStream(sourceStream); } } //썸네일 이미지 교체 curPic.ThumbnailImageSource = bitmap; } //편집 페이지에서 준비상태로 편집이 완료되었으면 편집 경고 삭제 if (isReady) { curPic.Warnning = null; } } else { //존재하지 않는 파일이므로 새롭게 리스트에 추가 WriteableBitmap bitmap = null; string thumbName = imgName.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_THUMNAIL_POSTFIX); string[] thumbs = isoStore.GetFileNames(thumbName); Uri uri = null; Thickness margin = new Thickness(); //썸네일이 없는 경우면 원본 이름을 셋팅 if (thumbs == null || thumbs.Length == 0) { thumbName = imgName; } //이미지 로드 using (IsolatedStorageFileStream sourceStream = isoStore.OpenFile(thumbName, FileMode.Open, FileAccess.Read)) { //썸네일이 없는 경우면 원본을 리사이징 if (thumbs == null || thumbs.Length == 0) { bitmap = JpegHelper.Resize(sourceStream, LockscreenHelper.ThumnailSize, true); } else { bitmap = BitmapFactory.New(0, 0).FromStream(sourceStream); } } //현재 락스크린 지정 이미지인 경우 처리 if (lockscreenFileName == imgName) { uri = currentLockscreenUri; margin = currentLockscreenMargin; } //락스크린 이미지 객체 생성 phoneAlbum.Add(new PhonePicture() { Guid = Guid.NewGuid(), Name = imgName, ThumnailName = thumbName, ThumbnailImageSource = bitmap, Margin = margin, CurrentLockscreen = uri, Warnning = isReady ? null : warnningUri, Opacity = 1, DateTimeOffset = isoStore.GetLastWriteTime(thumbName) }); } //경고 안내문구 표시 if (!LockscreenEditWarnning && !isReady) { LockscreenEditWarnning = true; } } } (IAppBarLockscreen.Buttons[0] as ApplicationBarIconButton).IsEnabled = !(phoneAlbum.Count == 0 && IAppBarLockscreen.Buttons.Count > 1); //이미지 갯수 표시 LockscreenCount = string.Format("({0})", phoneAlbum.Count); //에디팅 경고 표시 LockscreenEditWarnning = phoneAlbum.Any(x => (x as PhonePicture).Warnning != null); if (phoneAlbum.Count == 0) { //도움말 표시 토글 TxtLockscreen.Visibility = Visibility.Visible; //이미지가 없고 활성화된 라이브타일이 없으면 스케쥴러 정저 if (!ExistsActiveTile) { RemoveAgent(Constants.PERIODIC_TASK_NAME); } UseLockscreen.IsChecked = false; UseLockscreen.IsEnabled = false; } else { UseLockscreen.IsEnabled = true; TxtLockscreen.Visibility = Visibility.Collapsed; } }