-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add halide official tutorial07 with my own code
- Loading branch information
1 parent
1ca0670
commit a80a391
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,5 @@ | ||
{ | ||
"cmake.configureSettings": { | ||
"CMAKE_TOOLCHAIN_FILE": "C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,29 @@ | ||
cmake_minimum_required(VERSION 3.21) | ||
|
||
project(halide_tutorial07) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED YES) | ||
set(CMAKE_CXX_EXTENSIONS NO) | ||
|
||
find_package(Halide REQUIRED) | ||
find_package(PNG REQUIRED) | ||
find_package(JPEG REQUIRED) | ||
|
||
add_executable( | ||
${PROJECT_NAME} | ||
main.cpp | ||
) | ||
target_include_directories( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
${JPEG_INCLUDE_DIR} | ||
) | ||
target_link_libraries( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
Halide::Halide | ||
Halide::Tools | ||
PNG::PNG | ||
${JPEG_LIBRARIES} | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,75 @@ | ||
#include "Halide.h" | ||
#include <stdio.h> | ||
|
||
using namespace Halide; | ||
|
||
#include "halide_image_io.h" | ||
|
||
using namespace Halide::Tools; | ||
|
||
int main() | ||
{ | ||
Var x("x"), y("y"), c("c"); | ||
{ | ||
Buffer<uint8_t> input = load_image("../images/rgb.png"); | ||
Func input_16("input16"); | ||
input_16(x, y, c) = cast<uint16_t>(input(x, y, c)); | ||
|
||
Func blur_x("blur_x"); | ||
blur_x(x, y, c) = (input_16(x - 1, y, c) | ||
2 * input_16(x, y, c) | ||
input_16(x 1, y, c)) / | ||
4; | ||
|
||
Func blur_y("blur_y"); | ||
blur_y(x, y, c) = (blur_x(x, y - 1, c) | ||
2 * blur_x(x, y, c) | ||
blur_x(x, y 1, c)) / | ||
4; | ||
|
||
Func output("output"); | ||
output(x, y, c) = cast<uint8_t>(blur_y(x, y, c)); | ||
|
||
// Buffer<uint8_t> result = output.realize({input.width(), input.height(), input.channels()}); | ||
|
||
Buffer<uint8_t> result(input.width() - 2, input.height() - 2, 3); | ||
result.set_min(1, 1); | ||
output.realize(result); | ||
|
||
save_image(result, "blurry_parrot_1.png"); | ||
} | ||
{ | ||
Buffer<uint8_t> input = load_image("../images/rgb.png"); | ||
|
||
Func clamped("clamped"); | ||
|
||
Expr clamped_x = clamp(x, 0, input.width() - 1); | ||
Expr clamped_y = clamp(y, 0, input.height() - 1); | ||
|
||
clamped(x, y, c) = input(clamped_x, clamped_y, c); | ||
|
||
Func input_16("input_16"); | ||
input_16(x, y, c) = cast<uint16_t>(clamped(x, y, c)); | ||
|
||
Func blur_x("blur_x"); | ||
blur_x(x, y, c) = (input_16(x - 1, y, c) | ||
2 * input_16(x, y, c) | ||
input_16(x 1, y, c)) / | ||
4; | ||
|
||
Func blur_y("blur_y"); | ||
blur_y(x, y, c) = (blur_x(x, y - 1, c) | ||
2 * blur_x(x, y, c) | ||
blur_x(x, y 1, c)) / | ||
4; | ||
|
||
Func output("output"); | ||
output(x, y, c) = cast<uint8_t>(blur_y(x, y, c)); | ||
|
||
Buffer<uint8_t> result = output.realize({input.width(), input.height(), input.channels()}); | ||
|
||
save_image(result, "blurry_parrot_2.png"); | ||
} | ||
printf("Success!\n"); | ||
return 0; | ||
} |