-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
139 additions
and
24 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
fairseq2n/src/fairseq2n/data/image/detail/jpeg_decompress_struct.cc
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,26 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates.error_ptr | ||
// All rights reserved. | ||
// | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
#include "fairseq2n/data/image/detail/jpeg_decompress_struct.h" | ||
|
||
#include <jpeglib.h> | ||
|
||
#include "fairseq2n/exception.h" | ||
#include "fairseq2n/detail/exception.h" | ||
|
||
namespace fairseq2n::detail { | ||
|
||
jpeg_decompress::jpeg_decompress() {} | ||
|
||
jpeg_decompress::~jpeg_decompress() { | ||
jpeg_destroy_decompress(&cinfo); | ||
} | ||
|
||
jpeg_decompress_struct& jpeg_decompress::get() { | ||
return cinfo; | ||
} | ||
|
||
} // namespace fairseq2n::detail |
27 changes: 27 additions & 0 deletions
27
fairseq2n/src/fairseq2n/data/image/detail/jpeg_decompress_struct.h
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,27 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
// All rights reserved. | ||
// | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
#pragma once | ||
|
||
#include <jpeglib.h> | ||
#include "fairseq2n/exception.h" | ||
|
||
namespace fairseq2n::detail { | ||
|
||
class jpeg_decompress { | ||
public: | ||
jpeg_decompress(); | ||
~jpeg_decompress(); | ||
|
||
jpeg_decompress_struct& get(); | ||
|
||
private: | ||
jpeg_decompress_struct cinfo; | ||
jpeg_decompress(const jpeg_decompress&); | ||
jpeg_decompress& operator=(const jpeg_decompress&); | ||
}; | ||
|
||
} // namespace fairseq2n::detail |
40 changes: 40 additions & 0 deletions
40
fairseq2n/src/fairseq2n/data/image/detail/png_read_struct.cc
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,40 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
// All rights reserved. | ||
// | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
#include "fairseq2n/data/image/detail/png_read_struct.h" | ||
|
||
#include "fairseq2n/exception.h" | ||
#include "fairseq2n/detail/exception.h" | ||
|
||
namespace fairseq2n::detail { | ||
|
||
png_read::png_read() : png_ptr(nullptr), info_ptr(nullptr) { | ||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); | ||
if (png_ptr == nullptr) { | ||
throw internal_error("Failed to create PNG read struct."); | ||
} | ||
info_ptr = png_create_info_struct(png_ptr); | ||
if (info_ptr == nullptr) { | ||
png_destroy_read_struct(&png_ptr, nullptr, nullptr); | ||
throw internal_error("Failed to create PNG info struct."); | ||
} | ||
} | ||
|
||
png_read::~png_read() { | ||
if (png_ptr) { | ||
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); | ||
} | ||
} | ||
|
||
png_structp png_read::getPngPtr() const { | ||
return png_ptr; | ||
} | ||
|
||
png_infop png_read::getInfoPtr() const { | ||
return info_ptr; | ||
} | ||
|
||
} // namespace fairseq2n::detail |
28 changes: 28 additions & 0 deletions
28
fairseq2n/src/fairseq2n/data/image/detail/png_read_struct.h
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,28 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
// All rights reserved. | ||
// | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
#pragma once | ||
|
||
#include <png.h> | ||
|
||
namespace fairseq2n::detail { | ||
|
||
class png_read{ | ||
public: | ||
png_read(); | ||
~png_read(); | ||
|
||
png_structp getPngPtr() const; | ||
png_infop getInfoPtr() const; | ||
|
||
private: | ||
png_structp png_ptr; | ||
png_infop info_ptr; | ||
png_read(const png_read&); | ||
png_read& operator=(const png_read&); | ||
}; | ||
|
||
} // namespace fairseq2n::detail |
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