From: chitta ranjan Date: Mon, 22 Apr 2013 08:43:31 +0000 (+0900) Subject: Changes for unsupported file format of EncodeToFile function X-Git-Tag: accepted/tizen_2.1/20130425.023641~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dac9fb180a03be1850f9e77acab34e93924ad132;p=apps%2Fosp%2FImageViewer.git Changes for unsupported file format of EncodeToFile function Change-Id: I97661e64552d5c5719cc586cfd5d175d800d450e Signed-off-by: chitta ranjan --- diff --git a/src/IvImageCropForm.cpp b/src/IvImageCropForm.cpp index 5928554..ff62419 100644 --- a/src/IvImageCropForm.cpp +++ b/src/IvImageCropForm.cpp @@ -195,8 +195,11 @@ ImageCropForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO); } Image img; - img.Construct(); - __imageFormat = img.GetImageFormat(__sourceFilePath); + r = img.Construct(); + if (r == E_SUCCESS) + { + __imageFormat = img.GetImageFormat(__sourceFilePath); + } } SetValue(); AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); @@ -325,7 +328,7 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) } pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height, - (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height); + (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height); pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100); ContentManager::ScanFile(destFilePath); delete pCropBuffer; @@ -343,7 +346,7 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) if (__statusValue == SET_AT_TYPE_HOME_SCREEN_WALLPAPER) { String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER; - r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100); + r = pCropBuffer->EncodeToFile(destPath, IMG_FORMAT_JPG, true, 100); if (r == E_SUCCESS) { r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPath); @@ -352,7 +355,7 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) else if (__statusValue == SET_AT_TYPE_LOCK_SCREEN_WALLPAPER) { String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER; - r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100); + r = pCropBuffer->EncodeToFile(destPath, IMG_FORMAT_JPG, true, 100); if (r == E_SUCCESS) { r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath); @@ -362,20 +365,13 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) { String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER; String destPathHome = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER; - r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100); - r = pCropBuffer->EncodeToFile(destPathHome, __imageFormat, true, 100); + r = pCropBuffer->EncodeToFile(destPath, IMG_FORMAT_JPG, true, 100); + r = pCropBuffer->EncodeToFile(destPathHome, IMG_FORMAT_JPG, true, 100); if (r == E_SUCCESS) { r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath); r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPathHome); } - else if (r == E_OVERFLOW) - { - MessageBox messageBox; - messageBox.Construct(L"", L"File size is too big", MSGBOX_STYLE_NONE, 3000); - int modalResult = 0; - messageBox.ShowAndWait(modalResult); - } } else if (__statusValue == SET_AT_TYPE_CALLER_IMAGE) { @@ -399,7 +395,7 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) destFilePath.Insert(count, destFilePath.GetLength() - index - 1); } } - r = pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100); + r = pCropBuffer->EncodeToFile(destFilePath, IMG_FORMAT_JPG, true, 100); ContentManager::ScanFile(destFilePath); Contact* pContact = null; AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance(); @@ -473,7 +469,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph { case INSIDE_TOP_RECTANGLE: { - if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 5))) + if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3))) { __cropBox.y += deltaY; __cropBox.height -= deltaY; @@ -484,7 +480,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph case INSIDE_BOTTOM_RECTANGLE: { if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) - && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 5)) + && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3)) { __cropBox.height += deltaY; } @@ -493,7 +489,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph case INSIDE_LEFT_RECTANGLE: { - if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 5)) + if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3)) { __cropBox.x += deltaX; __cropBox.width -= deltaX; @@ -504,7 +500,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph case INSIDE_RIGHT_RECTANGLE: { if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) - && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 5)) + && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3)) { __cropBox.width += deltaX; } @@ -513,8 +509,8 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph case INSIDE_TOP_LEFT_RECTANGLE: { - if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 5)) - && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 5)) + if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3)) + && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3)) { __cropBox.y += deltaY; __cropBox.height -= deltaY; @@ -526,8 +522,8 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph case INSIDE_TOP_RIGHT_RECTANGLE: { - if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 5)) - && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 5)) + if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3)) + && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3)) { __cropBox.width += deltaX; __cropBox.y += deltaY; @@ -538,8 +534,8 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph case INSIDE_BOTTOM_LEFT_RECTANGLE: { - if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 5) - && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 5)) + if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3) + && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3)) { __cropBox.x += deltaX; __cropBox.width -= deltaX; @@ -550,8 +546,8 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph case INSIDE_BOTTOM_RIGHT_RECTANGLE: { - if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 5) - && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 5)) + if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3) + && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3)) { __cropBox.width += deltaX; __cropBox.height += deltaY; @@ -600,11 +596,11 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph int temp = __cropBox.height; int height = (__formHeight * (__cropBox.width - (2 * deltaX))) /__formWidth; temp = height - temp; - if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 5)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width))) + if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width))) { if (__cropBox.x + deltaX >= __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height - && (__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 5))) + && (__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3))) { __cropBox.x += deltaX; __cropBox.width = __cropBox.width - (2 * deltaX); @@ -652,9 +648,9 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph int temp = __cropBox.height; int height = (__formHeight * (__cropBox.width - (2 * deltaX))) / __formWidth; temp = height - temp; - if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 5)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width))) + if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width))) { - if (deltaX < __cropBox.width - (H_CROP_RECTANGLE * 5)) + if (deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3)) { if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height) @@ -719,7 +715,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph int temp = __cropBox.width; int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight; temp = width - temp; - if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 5)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width))) + if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width))) { if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height) @@ -783,7 +779,7 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph int temp = __cropBox.width; int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight; temp = width - temp; - if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 5)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width))) + if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width))) { if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height) @@ -933,6 +929,7 @@ ImageCropForm::SetValue(void) int prevWidth = __imageBox.width; int prevImageboxX = __imageBox.x; int prevImageBoxY = __imageBox.y; + if (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT) { __formHeight = Form::GetBounds().height; @@ -945,6 +942,7 @@ ImageCropForm::SetValue(void) } float clientAreaRatio = (GetClientAreaBoundsF().height - H_FOOTER_PANEL) / GetClientAreaBoundsF().width; + if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - H_FOOTER_PANEL)) { float imageRatio = __imageHeight / (float) __imageWidth; @@ -999,13 +997,13 @@ ImageCropForm::SetValue(void) } else { - float temp = __imageBox.x + ((__cropBox.x - prevImageboxX) * __imageBox.width) / (float)prevWidth; + float temp = __imageBox.x + ((__cropBox.x - prevImageboxX) * __imageBox.width) / (float) prevWidth; __cropBox.x = (temp + 0.5); - temp = __imageBox.y + ((__cropBox.y - prevImageBoxY) * __imageBox.height) / (float)prevHeight; + temp = __imageBox.y + ((__cropBox.y - prevImageBoxY) * __imageBox.height) / (float) prevHeight; __cropBox.y = (temp + 0.5); - temp = (__cropBox.height * __imageBox.height) / (float)prevHeight; + temp = (__cropBox.height * __imageBox.height) / (float) prevHeight; __cropBox.height = (temp + 0.5); - temp = (__cropBox.width * __imageBox.width) / (float)prevWidth; + temp = (__cropBox.width * __imageBox.width) / (float) prevWidth; __cropBox.width = (temp + 0.5); } __pCanvas = GetCanvasN(); diff --git a/src/IvImageViewerForm.cpp b/src/IvImageViewerForm.cpp index 72e4f25..c396fcf 100644 --- a/src/IvImageViewerForm.cpp +++ b/src/IvImageViewerForm.cpp @@ -757,6 +757,7 @@ result ImageViewerForm::InitializeContextMenuMore(void) { AppLogDebug("ENTER"); + result r = E_SUCCESS; int currentIndex = __pGallery->GetCurrentItemIndex(); String filePath = __pPresentationModel->GetFilePathAt(currentIndex); @@ -777,9 +778,19 @@ ImageViewerForm::InitializeContextMenuMore(void) { __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SET_AS"), IDA_CONTEXTMENU_SET_AS); - __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CROP"), IDA_FOOTER_BUTTON_CROP); - __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_ROTATE_RIGHT"), IDA_FOOTER_BUTTON_ROTATE_RIGHT); - __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_ROTATE_LEFT"), IDA_FOOTER_BUTTON_ROTATE_LEFT); + Image img; + r = img.Construct(); + ImageFormat imageFormat = IMG_FORMAT_NONE; + if (r == E_SUCCESS) + { + imageFormat = img.GetImageFormat(filePath); + } + if (imageFormat == IMG_FORMAT_JPG || imageFormat == IMG_FORMAT_PNG || imageFormat == IMG_FORMAT_BMP) + { + __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CROP"), IDA_FOOTER_BUTTON_CROP); + __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_ROTATE_RIGHT"), IDA_FOOTER_BUTTON_ROTATE_RIGHT); + __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_ROTATE_LEFT"), IDA_FOOTER_BUTTON_ROTATE_LEFT); + } } if (__pGallery->GetItemCount() > 1) @@ -793,7 +804,7 @@ ImageViewerForm::InitializeContextMenuMore(void) __pContextMenuMore->AddActionEventListener(*this); AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); - return E_SUCCESS; + return r; } result