Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DIP][OSPP] Add JPEG image encoding and decoding. #222

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUDDY_BINARY_DIR})
set(BUDDY_EXAMPLES OFF CACHE BOOL "Build examples")
set(BUDDY_ENABLE_OPENCV OFF CACHE BOOL "Enable OpenCV support.")

if(BUDDY_ENABLE_OPENCV)
add_definitions(-DBUDDY_ENABLE_OPENCV)
endif()

# Generate libraries into `lib` of build directory.
set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)

Expand Down Expand Up @@ -122,6 +126,13 @@ include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)

#-------------------------------------------------------------------------------
# Dip lib configuration
#-------------------------------------------------------------------------------

find_package(JPEG REQUIRED)
find_package(PNG REQUIRED)

#-------------------------------------------------------------------------------
# Hardware detection
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -183,4 +194,4 @@ add_subdirectory(tests)

add_custom_target(check-buddy
DEPENDS check-examples check-tests
)
)
9 changes: 5 additions & 4 deletions examples/ConvOpt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ SET_TARGET_PROPERTIES(
if(BUDDY_ENABLE_OPENCV)
find_package(OpenCV REQUIRED CONFIG)
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
add_executable(edge-detection edge-detection.cpp)
add_dependencies(edge-detection buddy-opt)
target_link_libraries(edge-detection ${OpenCV_LIBS} Conv2D)
endif()


add_executable(edge-detection edge-detection.cpp)
add_dependencies(edge-detection buddy-opt)
target_link_libraries(edge-detection ${OpenCV_LIBS} Conv2D)
31 changes: 18 additions & 13 deletions examples/DIPDialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
set(DIP_LIBS ${JPEG_LIBRARY} ${PNG_LIBRARY} BuddyLibDIP)

if(BUDDY_ENABLE_OPENCV)
find_package(OpenCV REQUIRED CONFIG)
include_directories(${OpenCV_INCLUDE_DIRS})
endif()

add_executable(correlation2D correlation2D.cpp)
target_link_libraries(correlation2D ${OpenCV_LIBS} BuddyLibDIP)
add_executable(correlation2D correlation2D.cpp)
target_link_libraries(correlation2D ${OpenCV_LIBS} ${DIP_LIBS})

add_executable(correlationFFT2D correlationFFT2D.cpp)
target_link_libraries(correlationFFT2D ${OpenCV_LIBS} ${DIP_LIBS})

add_executable(correlationFFT2D correlationFFT2D.cpp)
target_link_libraries(correlationFFT2D ${OpenCV_LIBS} BuddyLibDIP)
add_executable(morph2D morph2D.cpp)
target_link_libraries(morph2D ${OpenCV_LIBS} ${DIP_LIBS})

add_executable(dip-all DIPAll.cpp)
target_link_libraries(dip-all ${OpenCV_LIBS} ${DIP_LIBS})

add_executable(opencv-all OpenCVAll.cpp)
target_link_libraries(opencv-all ${OpenCV_LIBS})
endif()

add_executable(rotation2D rotation2D.cpp)
target_link_libraries(rotation2D ${OpenCV_LIBS} BuddyLibDIP)
target_link_libraries(rotation2D ${DIP_LIBS})

add_executable(resize2D resize2D.cpp)
target_link_libraries(resize2D ${OpenCV_LIBS} BuddyLibDIP)
target_link_libraries(resize2D ${DIP_LIBS})

add_executable(morph2D morph2D.cpp)
target_link_libraries(morph2D ${OpenCV_LIBS} BuddyLibDIP)

add_executable(dip-all DIPAll.cpp)
target_link_libraries(dip-all ${OpenCV_LIBS} BuddyLibDIP)

add_executable(opencv-all OpenCVAll.cpp)
target_link_libraries(opencv-all ${OpenCV_LIBS})
1 change: 1 addition & 0 deletions examples/DIPDialect/resize2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <buddy/DIP/DIP.h>
#include <buddy/DIP/ImageContainer.h>
#include <iostream>
#include <math.h>

using namespace std;

Expand Down
1 change: 1 addition & 0 deletions examples/DIPDialect/rotation2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <buddy/DIP/DIP.h>
#include <buddy/DIP/ImageContainer.h>
#include <iostream>
#include <math.h>

using namespace std;

Expand Down
Binary file added examples/images/YuTu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/Interfaces/buddy/DIP/DIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "buddy/Core/Container.h"
#include "buddy/DIP/ImageContainer.h"

#include <math.h>
namespace dip {
// Availale types of boundary extrapolation techniques provided in DIP dialect.
enum class BOUNDARY_OPTION { CONSTANT_PADDING, REPLICATE_PADDING };
Expand Down
7 changes: 7 additions & 0 deletions frontend/Interfaces/buddy/DIP/ImageContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
#include "buddy/Core/Container.h"
#include "buddy/DIP/imgcodecs/replenishment.h"
#include <cassert>

#ifdef BUDDY_ENABLE_OPENCV
#include <opencv2/opencv.hpp>
#endif

using namespace dip;
// Image container.
Expand Down Expand Up @@ -68,12 +71,14 @@ template <typename T, size_t N> class Img : public MemRef<T, N> {
// Move assignment operator.
Img &operator=(Img<T, N> &&m);

#ifdef BUDDY_ENABLE_OPENCV
/**
* @brief Load image data from OpenCV Mat.
* @param image represents the OpenCV Mat object.
* @param norm indicates whether to perform.
*/
Img(cv::Mat image, intptr_t sizes[N] = nullptr, bool norm = false);
#endif

int channels();
};
Expand Down Expand Up @@ -133,6 +138,7 @@ Img<T, N> &Img<T, N>::operator=(const Img<T, N> &m) {
template <typename T, size_t N>
Img<T, N>::Img(T *data, intptr_t sizes[N]) : MemRef<T, N>(data, sizes) {}

#ifdef BUDDY_ENABLE_OPENCV
// Image Constructor from OpenCV Mat.
template <typename T, size_t N>
Img<T, N>::Img(cv::Mat image, intptr_t sizes[N], bool norm) : MemRef<T, N>() {
Expand Down Expand Up @@ -173,6 +179,7 @@ Img<T, N>::Img(cv::Mat image, intptr_t sizes[N], bool norm) : MemRef<T, N>() {
}
}
}
#endif

template <typename T, size_t N> int Img<T, N>::channels() {
if (N == 2) {
Expand Down
38 changes: 19 additions & 19 deletions frontend/Interfaces/buddy/DIP/imgcodecs/grfmt_bmp.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//===- Grfmt_bmp.h ---------------------------------------------------===//
//===-----------------------grfmt_bmp.h----------------------------===//
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this
// license. If you do not agree to this license, do not download, install, copy
// or use the software.
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to
// this license. If you do not agree to this license, do not download,
// install, copy or use the software.
//
// Intel License Agreement
// For Open Source Computer Vision Library
Expand All @@ -16,17 +15,17 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright
// notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Redistribution's in binary form must reproduce the above copyright
// notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote
// products
// derived from this software without specific prior written permission.
// * The name of Intel Corporation may not be used to endorse or promote
// products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is"
// and any express or implied warranties, including, but not limited to, the
Expand All @@ -41,11 +40,12 @@
// possibility of such damage.
//
//
//===----------------------------------------------------------------------===//
//----------------------------------------------------------------------//
//
// This file is modified from opencv's modules/imgcodecs/src/grfmt_bmp.hpp file
// This file is modified from opencv's
// modules/imgcodecs/src/grfmt_bmp.hpp file
//
//===----------------------------------------------------------------------===//
//----------------------------------------------------------------------//

#ifndef _GRFMT_BMP_H_
#define _GRFMT_BMP_H_
Expand Down Expand Up @@ -450,4 +450,4 @@ bool BmpEncoder<T, N>::write(Img<T, N> &img, const std::vector<int> &) {
return true;
}
} // namespace dip
#endif /*_GRFMT_BMP_H_*/
#endif /*_GRFMT_BMP_H_*/
Loading