Skip to content
Open
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
8 changes: 7 additions & 1 deletion Charcoal/Charcoal/Charcoal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Charcoal::Charcoal() {
overlay_->view()->set_view_listener(this);
}


Charcoal::~Charcoal() {
}

Expand Down Expand Up @@ -142,6 +141,12 @@ void Charcoal::grayscaleName(const JSObject& thisObject, const JSArgs& args) { /
}


void Charcoal::contrastValue(const JSObject& thisObject, const JSArgs& args) {
MessageBoxA(NULL, "Please sit tight, contrasting your book.", "Book Contrasting", MB_OK);

}


void Charcoal::OpenFile(const JSObject& thisObject, const JSArgs& args)
{
//dialog box for file select
Expand Down Expand Up @@ -199,6 +204,7 @@ void Charcoal::OnDOMReady(ultralight::View* caller,
global["AddBook"] = BindJSCallback(&Charcoal::OpenFile);
global["nameToGrayscale"] = BindJSCallback(&Charcoal::grayscaleName);
global["deleteBook"] = BindJSCallback(&Charcoal::deleteBooks);
global["contrastValue"] = BindJSCallback(&Charcoal::contrastValue);

auto scoped_context = context;

Expand Down
1 change: 1 addition & 0 deletions Charcoal/Charcoal/Charcoal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Charcoal : public AppListener,
virtual void deleteBooks(const JSObject& thisObject, const JSArgs& args);
virtual JSValue printAllBooks(const JSObject& thisObject, const JSArgs& args);
virtual void grayscaleName(const JSObject& thisObject, const JSArgs& args);
virtual void contrastValue(const JSObject& thisObject, const JSArgs& args);

// This is called when the DOM has loaded in one of its frames.
virtual void OnDOMReady(ultralight::View* caller,
Expand Down
21 changes: 21 additions & 0 deletions Charcoal/Charcoal/Epub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ void Epub::grayscaleEpub(PWSTR path) {
// Grayscale the image
grayscaleImage(image, width, height);

// Contrast the image
int contrast_value = 1;
contrastImage(image, width, height, contrast_value);

std::string base_filename = name.substr(name.find_last_of("/\\") + 1);
if(fileExt == "jpeg" || fileExt == "jpg")
stbi_write_jpg((temp + base_filename).c_str(), width, height, channels, image, 100);
Expand Down Expand Up @@ -163,3 +167,20 @@ void Epub::grayscaleImage(unsigned char* imageData, int width, int height) {
imageData[3 * i + 2] = gray;
}
}

void Epub::contrastImage(unsigned char* imageData, int width, int height, int contrast_value) {
// Convert RGB image to grayscale
for (int i = 0; i < width * height; ++i) {
unsigned char gray_value;
if (imageData[3 * i] * contrast_value > 255) {
gray_value = 255;
}
else {
gray_value = imageData[3 * i] * contrast_value;
}

imageData[3 * i] = gray_value;
imageData[3 * i + 1] = gray_value;
imageData[3 * i + 2] = gray_value;
}
}
1 change: 1 addition & 0 deletions Charcoal/Charcoal/Epub.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class Epub : public Library
void grayscaleEpub(PWSTR Path);
private:
void grayscaleImage(unsigned char* imageData, int width, int height);
void contrastImage(unsigned char* imageData, int width, int height, int contrast_value);
};

Binary file modified Charcoal/x64/Debug/Charcoal.exe
Binary file not shown.
Binary file modified Charcoal/x64/Debug/Charcoal.pdb
Binary file not shown.
7 changes: 7 additions & 0 deletions Charcoal/x64/Debug/assets/books.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ <h3 id="result">BOOKS: </h3>
nameToGrayscale();
}
</script>

<button class="button-28" onclick="contrastbutton()">Contrast</button>
<script>
function contrastbutton() {
contrastValue();
}
</script>

<div id="bs"></div>
<button class="button-28" onclick="rmbooksbutton()">Remove Books</button>
Expand Down