Adapted to buffer redesign of file_reader
This commit is contained in:
parent
7f10b384f9
commit
c29922ce2a
8 changed files with 17 additions and 17 deletions
|
@ -4,6 +4,7 @@ project(lily_png)
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
add_subdirectory(file_reader)
|
add_subdirectory(file_reader)
|
||||||
|
target_include_directories(file_read INTERFACE "file_reader")
|
||||||
find_package(ZLIB)
|
find_package(ZLIB)
|
||||||
|
|
||||||
add_library(lily_png STATIC src/lily_png.cpp
|
add_library(lily_png STATIC src/lily_png.cpp
|
||||||
|
@ -13,5 +14,5 @@ add_library(lily_png STATIC src/lily_png.cpp
|
||||||
src/utils.h
|
src/utils.h
|
||||||
src/filter.cpp
|
src/filter.cpp
|
||||||
src/filter.h)
|
src/filter.h)
|
||||||
target_link_libraries(lily_png file_read ZLIB::ZLIB)
|
target_link_libraries(lily_png PRIVATE file_read ZLIB::ZLIB)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit f8f0ef364ee87473300ff2f51e192465843e0a8c
|
Subproject commit ec3d79677455c47c31f3244a763d53933da84eb8
|
|
@ -43,7 +43,7 @@ void filter_scanline(unsigned char *scanline, unsigned char *previous_scanline,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void filter(buffer_unsigned &data, buffer_unsigned &dest ,metadata &meta)
|
void filter(buffer<unsigned char> &data, buffer<unsigned char> &dest ,metadata &meta)
|
||||||
{
|
{
|
||||||
unsigned long index = 0;
|
unsigned long index = 0;
|
||||||
unsigned long index_dest = 0;
|
unsigned long index_dest = 0;
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
void filter_scanline(unsigned char *scanline, unsigned char *previous_scanline, unsigned char *dest, metadata &meta, unsigned char filter_type);
|
void filter_scanline(unsigned char *scanline, unsigned char *previous_scanline, unsigned char *dest, metadata &meta, unsigned char filter_type);
|
||||||
void filter(buffer_unsigned &data, buffer_unsigned &dest ,metadata &meta);
|
void filter(buffer<unsigned char> &data, buffer<unsigned char> &dest ,metadata &meta);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
std::vector<color> palette;
|
std::vector<color> palette;
|
||||||
bool palette_found = false;
|
bool palette_found = false;
|
||||||
|
|
||||||
static void read_raw_data(const std::string &file_path, buffer_unsigned &data, metadata &meta)
|
static void read_raw_data(const std::string &file_path, buffer<unsigned char> &data, metadata &meta)
|
||||||
{
|
{
|
||||||
std::println("Zlib version is {}", zlibVersion());
|
std::println("Zlib version is {}", zlibVersion());
|
||||||
unsigned char magic[9] = {137, 80, 78, 71, 13, 10, 26, 10};
|
unsigned char magic[9] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||||
|
@ -15,10 +15,10 @@ static void read_raw_data(const std::string &file_path, buffer_unsigned &data, m
|
||||||
std::println("File is not a png!");
|
std::println("File is not a png!");
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
buffer_unsigned raw_dat{};
|
buffer<unsigned char> raw_dat{};
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
std::tuple<unsigned int, buffer> chunk_header;
|
std::tuple<unsigned int, buffer<char>> chunk_header;
|
||||||
std::get<1>(chunk_header).size = 4;
|
std::get<1>(chunk_header).size = 4;
|
||||||
auto ret = reader.read_from_tuple(chunk_header);
|
auto ret = reader.read_from_tuple(chunk_header);
|
||||||
if (ret.second == READ_FILE_ENDED || ret.second == READ_INCOMPLETE)
|
if (ret.second == READ_FILE_ENDED || ret.second == READ_INCOMPLETE)
|
||||||
|
@ -29,9 +29,9 @@ static void read_raw_data(const std::string &file_path, buffer_unsigned &data, m
|
||||||
unsigned int size = std::get<0>(chunk_header);
|
unsigned int size = std::get<0>(chunk_header);
|
||||||
//std::println("Chunk type {} Size {}", std::get<1>(chunk_header).data, std::get<0>(chunk_header));
|
//std::println("Chunk type {} Size {}", std::get<1>(chunk_header).data, std::get<0>(chunk_header));
|
||||||
|
|
||||||
buffer_unsigned raw_data{};
|
buffer<unsigned char> raw_data{};
|
||||||
raw_data.size = std::get<0>(chunk_header);
|
raw_data.size = std::get<0>(chunk_header);
|
||||||
std::tuple<buffer, unsigned> dat;
|
std::tuple<buffer<char>, unsigned> dat;
|
||||||
std::get<0>(dat).size = std::get<0>(chunk_header);
|
std::get<0>(dat).size = std::get<0>(chunk_header);
|
||||||
ret = reader.read_from_tuple(dat);
|
ret = reader.read_from_tuple(dat);
|
||||||
if (ret.second == READ_FILE_ENDED || ret.second == READ_INCOMPLETE)
|
if (ret.second == READ_FILE_ENDED || ret.second == READ_INCOMPLETE)
|
||||||
|
@ -100,7 +100,7 @@ static void apply_palette_scanline(unsigned char *scanline, unsigned char *dest,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void apply_palette(buffer_unsigned &data, buffer_unsigned &dest, metadata &meta)
|
static void apply_palette(buffer<unsigned char> &data, buffer<unsigned char> &dest, metadata &meta)
|
||||||
{
|
{
|
||||||
unsigned long index = 0;
|
unsigned long index = 0;
|
||||||
unsigned long index_dest = 0;
|
unsigned long index_dest = 0;
|
||||||
|
@ -120,14 +120,14 @@ static void apply_palette(buffer_unsigned &data, buffer_unsigned &dest, metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_png(const std::string &file_path, buffer_unsigned &data)
|
void read_png(const std::string &file_path, buffer<unsigned char> &data)
|
||||||
{
|
{
|
||||||
buffer_unsigned tmp_data{};
|
buffer<unsigned char> tmp_data{};
|
||||||
metadata meta{0};
|
metadata meta{0};
|
||||||
read_raw_data(file_path, tmp_data, meta);
|
read_raw_data(file_path, tmp_data, meta);
|
||||||
if (palette_found == true)
|
if (palette_found == true)
|
||||||
{
|
{
|
||||||
buffer_unsigned dest_palette{};
|
buffer<unsigned char> dest_palette{};
|
||||||
apply_palette(tmp_data, dest_palette, meta);
|
apply_palette(tmp_data, dest_palette, meta);
|
||||||
tmp_data = dest_palette;
|
tmp_data = dest_palette;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "../file_reader/src/file_read.h"
|
#include "../file_reader/src/file_read.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
|
@ -15,4 +14,4 @@ struct color
|
||||||
unsigned char b = 0;
|
unsigned char b = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void read_png(const std::string &file_path, buffer_unsigned &data);
|
void read_png(const std::string &file_path, buffer<unsigned char> &data);
|
|
@ -1,7 +1,7 @@
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
|
||||||
|
|
||||||
metadata parse_metadata(buffer &data)
|
metadata parse_metadata(buffer<char> &data)
|
||||||
{
|
{
|
||||||
std::tuple<unsigned int, unsigned int, char, char, char, char, char> meta;
|
std::tuple<unsigned int, unsigned int, char, char, char, char, char> meta;
|
||||||
constexpr std::size_t size = std::tuple_size_v<decltype(meta)>;
|
constexpr std::size_t size = std::tuple_size_v<decltype(meta)>;
|
||||||
|
|
|
@ -12,4 +12,4 @@ struct metadata
|
||||||
char interface;
|
char interface;
|
||||||
};
|
};
|
||||||
|
|
||||||
metadata parse_metadata(buffer &data);
|
metadata parse_metadata(buffer<char> &data);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue