diff --git a/Charcoal/Charcoal/Charcoal.cpp b/Charcoal/Charcoal/Charcoal.cpp index f9c7053..4033b74 100644 --- a/Charcoal/Charcoal/Charcoal.cpp +++ b/Charcoal/Charcoal/Charcoal.cpp @@ -99,6 +99,21 @@ void Charcoal::deleteBooks(const JSObject& thisobject, const JSArgs& args) return; } +void Charcoal::grayscaleName(const JSObject& thisobject, const JSArgs& args) { + MessageBoxA(NULL, "Started Grayscaling book", "Started Grayscaling book", MB_OK); + // Get the first argument + JSValueRef arg = args[0]; + JSContextRef ctx = JSGlobalContextCreate(NULL); + // Convert it to a number + int ID = JSValueToNumber(ctx, arg, 0); + + // Call the grayscale method + ebooks.grayscale(ID); + MessageBoxA(NULL, "Finished Grayscaling book", "Finished Grayscaling book", MB_OK); + return; +} + + JSValue Charcoal::printAllBooks(const JSObject& thisObject, const JSArgs& args) { std::string bookList = ebooks.printall(); @@ -149,10 +164,7 @@ JSValueRef OnButtonClick(JSContextRef ctx, JSObjectRef function, return JSValueMakeNull(ctx); } -void Charcoal::grayscaleName(const JSObject& thisObject, const JSArgs& args) { //at the moment just gets metadata, Thomas will puts grayscale hooks here. - //std::string added = ebooks.getStringData(); - //MessageBoxA(NULL, added.c_str(), "Book Data", MB_OK); -} + void Charcoal::OpenFile(const JSObject& thisObject, const JSArgs& args) @@ -210,7 +222,7 @@ void Charcoal::OnDOMReady(ultralight::View* caller, SetJSContext(context->ctx()); JSObject global = JSGlobalObject(); global["AddBook"] = BindJSCallback(&Charcoal::OpenFile); - global["nameToGrayscale"] = BindJSCallback(&Charcoal::grayscaleName); + global["grayscaleName"] = BindJSCallback(&Charcoal::grayscaleName); global["deleteBook"] = BindJSCallback(&Charcoal::deleteBooks); auto scoped_context = context; diff --git a/Charcoal/Charcoal/Epub.cpp b/Charcoal/Charcoal/Epub.cpp index 241deac..3d4ccea 100644 --- a/Charcoal/Charcoal/Epub.cpp +++ b/Charcoal/Charcoal/Epub.cpp @@ -15,10 +15,9 @@ #include #define _CRT_SECURE_NO_WARNINGS #pragma once -book Epub::add(PWSTR path) +book Epub::add(std::string npath) { book curr; - std::string npath = wstrtostr(path); using namespace libzippp; ZipArchive zf(npath); zf.open(ZipArchive::ReadOnly); @@ -98,6 +97,7 @@ book Epub::add(PWSTR path) } meta = meta->NextSiblingElement(); } + collection.push_back(curr); //adding book to the collection } @@ -108,10 +108,9 @@ book Epub::add(PWSTR path) return curr; } -void Epub::grayscaleEpub(PWSTR path) { - std::string npath = wstrtostr(path); +void Epub::grayscaleEpub(std::string path) { using namespace libzippp; - ZipArchive zipArchive(npath); + ZipArchive zipArchive(path); zipArchive.open(ZipArchive::Write); std::vector entries = zipArchive.getEntries(); std::vector::iterator it; @@ -128,9 +127,7 @@ void Epub::grayscaleEpub(PWSTR path) { // Read the image file from the epub archive int width, height, channels; unsigned char* image = stbi_load_from_memory((unsigned char*)entry.readAsBinary(), entry.getSize(), &width, &height, &channels, 0); - - // Grayscale the image - //grayscaleImage(image, width, height); + std::string base_filename = name.substr(name.find_last_of("/\\") + 1); if(fileExt == "jpeg" || fileExt == "jpg") diff --git a/Charcoal/Charcoal/Epub.h b/Charcoal/Charcoal/Epub.h index b64a5c5..fd0e100 100644 --- a/Charcoal/Charcoal/Epub.h +++ b/Charcoal/Charcoal/Epub.h @@ -3,9 +3,8 @@ class Epub : public Library { public: - book add(PWSTR path); - void grayscaleEpub(PWSTR Path); + book add(std::string path); + void grayscaleEpub(std::string path); private: - void grayscaleImage(unsigned char* imageData, int width, int height); }; diff --git a/Charcoal/Charcoal/Library.cpp b/Charcoal/Charcoal/Library.cpp index f5b42e5..431f96f 100644 --- a/Charcoal/Charcoal/Library.cpp +++ b/Charcoal/Charcoal/Library.cpp @@ -83,12 +83,16 @@ std::string Library::getFileExtension(const std::string& filePath) int ID = 0; std::string Library::add(PWSTR path) { - std::string f = getFileExtension(wstrtostr(path)); + std::string npath = wstrtostr(path); + std::string f = getFileExtension(npath); if (f == "epub") { Epub e; - book curr = e.add(path); + + book curr = e.add(npath); curr.ID = ID; + curr.path = npath; + ++ID; collection.push_back(curr); titles.push_back(curr.title); @@ -123,15 +127,46 @@ std::vector Library::getBookTitles() { return titles; } -int Library::remove(int ID) // this actually removes the book from the library. +int Library::remove(int book_ID) // this actually removes the book from the library. { for (int i = 0; i < collection.size(); i++) { - if (collection[i].ID == ID) + if (collection[i].ID == book_ID) { collection.erase(collection.begin() + i); return 1; } } return -1; +} + +int Library::grayscale(int book_ID) +{ + for (int i = 0; i < collection.size(); i++) + { + if (collection[i].ID == book_ID) + { + std::string path = collection[i].path; + std::string f = getFileExtension((path)); + if (f == "epub") + { + Epub e; + e.grayscaleEpub(path); + return 1; + } + else if (f == "AZW3" || f == "azw3") + { + + } + else if (f == "pdf" || f == "PDF") + { + + } + else + { + + } + } + } + return -1; } \ No newline at end of file diff --git a/Charcoal/Charcoal/Library.h b/Charcoal/Charcoal/Library.h index ab96c58..489b4e0 100644 --- a/Charcoal/Charcoal/Library.h +++ b/Charcoal/Charcoal/Library.h @@ -15,7 +15,7 @@ class book { std::string language; std::string description; - PWSTR path; + std::string path; }; @@ -29,10 +29,10 @@ class Library { std::string getFileExtension(const std::string& filePath); int remove(int ID); std::vector getBookTitles(); + int grayscale(int ID); protected: std::vector collection; std::vector titles; - void push(book b); }; diff --git a/Charcoal/x64/Debug/assets/app.html b/Charcoal/x64/Debug/assets/app.html index 74d3972..63ad702 100644 --- a/Charcoal/x64/Debug/assets/app.html +++ b/Charcoal/x64/Debug/assets/app.html @@ -292,7 +292,16 @@