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

Add namespace on image C++ codebase #3312

Merged
merged 6 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Renaming public image methods to match the ones on python.
  • Loading branch information
datumbox committed Jan 27, 2021
commit 22925ff7a10eed4afc7f87fbbb72166c3f82e93e
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "jpegcommon.h"
#include "common_jpeg.h"

namespace vision {
namespace image {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "read_image_impl.h"
#include "decode_image.h"

#include "readjpeg_impl.h"
#include "readpng_impl.h"
#include "decode_jpeg.h"
#include "decode_png.h"

namespace vision {
namespace image {
Expand All @@ -20,9 +20,9 @@ torch::Tensor decode_image(const torch::Tensor& data, ImageReadMode mode) {
const uint8_t png_signature[4] = {137, 80, 78, 71}; // == "\211PNG"

if (memcmp(jpeg_signature, datap, 3) == 0) {
return decodeJPEG(data, mode);
return decode_jpeg(data, mode);
} else if (memcmp(png_signature, datap, 4) == 0) {
return decodePNG(data, mode);
return decode_png(data, mode);
} else {
TORCH_CHECK(
false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "readjpeg_impl.h"
#include "jpegcommon.h"
#include "decode_jpeg.h"
#include "common_jpeg.h"

namespace vision {
namespace image {

using namespace detail;

#if !JPEG_FOUND
torch::Tensor decodeJPEG(const torch::Tensor& data, ImageReadMode mode) {
torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
TORCH_CHECK(
false, "decodeJPEG: torchvision not compiled with libjpeg support");
false, "decode_jpeg: torchvision not compiled with libjpeg support");
}
#else

Expand Down Expand Up @@ -73,7 +73,7 @@ static void torch_jpeg_set_source_mgr(

} // namespace

torch::Tensor decodeJPEG(const torch::Tensor& data, ImageReadMode mode) {
torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
// Check that the input tensor dtype is uint8
TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor");
// Check that the input tensor is 1-dimensional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace vision {
namespace image {

C10_EXPORT torch::Tensor decodePNG(
C10_EXPORT torch::Tensor decode_jpeg(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here Github fails to track the right file renames and thinks I moved png to jpeg and vice versa.

const torch::Tensor& data,
ImageReadMode mode = IMAGE_READ_MODE_UNCHANGED);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include "readpng_impl.h"
#include "pngcommon.h"
#include "decode_png.h"
#include "common_png.h"

namespace vision {
namespace image {

#if !PNG_FOUND
torch::Tensor decodePNG(const torch::Tensor& data, ImageReadMode mode) {
TORCH_CHECK(false, "decodePNG: torchvision not compiled with libPNG support");
torch::Tensor decode_png(const torch::Tensor& data, ImageReadMode mode) {
TORCH_CHECK(
false, "decode_png: torchvision not compiled with libPNG support");
}
#else

torch::Tensor decodePNG(const torch::Tensor& data, ImageReadMode mode) {
torch::Tensor decode_png(const torch::Tensor& data, ImageReadMode mode) {
// Check that the input tensor dtype is uint8
TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor");
// Check that the input tensor is 1-dimensional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace vision {
namespace image {

C10_EXPORT torch::Tensor decodeJPEG(
C10_EXPORT torch::Tensor decode_png(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again Github fails to figure out which file was moved to what here.

const torch::Tensor& data,
ImageReadMode mode = IMAGE_READ_MODE_UNCHANGED);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "writejpeg_impl.h"
#include "encode_jpeg.h"

#include "jpegcommon.h"
#include "common_jpeg.h"

namespace vision {
namespace image {
Expand All @@ -9,14 +9,14 @@ using namespace detail;

#if !JPEG_FOUND

torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality) {
torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) {
TORCH_CHECK(
false, "encodeJPEG: torchvision not compiled with libjpeg support");
false, "encode_jpeg: torchvision not compiled with libjpeg support");
}

#else

torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality) {
torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) {
// Define compression structures and error handling
struct jpeg_compress_struct cinfo;
struct torch_jpeg_error_mgr jerr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace vision {
namespace image {

C10_EXPORT torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality);
C10_EXPORT torch::Tensor encode_jpeg(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git fails to track the old file.

const torch::Tensor& data,
int64_t quality);

} // namespace image
} // namespace vision
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "writejpeg_impl.h"
#include "encode_jpeg.h"

#include "pngcommon.h"
#include "common_png.h"

namespace vision {
namespace image {

#if !PNG_FOUND

torch::Tensor encodePNG(const torch::Tensor& data, int64_t compression_level) {
TORCH_CHECK(false, "encodePNG: torchvision not compiled with libpng support");
torch::Tensor encode_png(const torch::Tensor& data, int64_t compression_level) {
TORCH_CHECK(
false, "encode_png: torchvision not compiled with libpng support");
}

#else
Expand Down Expand Up @@ -66,7 +67,7 @@ void torch_png_write_data(

} // namespace

torch::Tensor encodePNG(const torch::Tensor& data, int64_t compression_level) {
torch::Tensor encode_png(const torch::Tensor& data, int64_t compression_level) {
// Define compression structures and error handling
png_structp png_write;
png_infop info_ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace vision {
namespace image {

C10_EXPORT torch::Tensor encodePNG(
C10_EXPORT torch::Tensor encode_png(
const torch::Tensor& data,
int64_t compression_level);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "read_write_file_impl.h"
#include "read_write_file.h"

#include <sys/stat.h>

Expand Down
8 changes: 4 additions & 4 deletions torchvision/csrc/io/image/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace vision {
namespace image {

static auto registry = torch::RegisterOperators()
.op("image::decode_png", &decodePNG)
.op("image::encode_png", &encodePNG)
.op("image::decode_jpeg", &decodeJPEG)
.op("image::encode_jpeg", &encodeJPEG)
.op("image::decode_png", &decode_png)
.op("image::encode_png", &encode_png)
.op("image::decode_jpeg", &decode_jpeg)
.op("image::encode_jpeg", &encode_jpeg)
.op("image::read_file", &read_file)
.op("image::write_file", &write_file)
.op("image::decode_image", &decode_image);
Expand Down
12 changes: 6 additions & 6 deletions torchvision/csrc/io/image/image.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "cpu/read_image_impl.h"
#include "cpu/read_write_file_impl.h"
#include "cpu/readjpeg_impl.h"
#include "cpu/readpng_impl.h"
#include "cpu/writejpeg_impl.h"
#include "cpu/writepng_impl.h"
#include "cpu/decode_image.h"
#include "cpu/decode_jpeg.h"
#include "cpu/decode_png.h"
#include "cpu/encode_jpeg.h"
#include "cpu/encode_png.h"
#include "cpu/read_write_file.h"