-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update test code and perf * update preview image
- Loading branch information
xVan Turing
authored and
xVan Turing
committed
Feb 9, 2019
1 parent
320b4f3
commit 44d5625
Showing
20 changed files
with
201 additions
and
168 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
0. add test | ||
1. add para for subsampling | ||
0. ~~add test~~ | ||
1. ~~add para for subsampling~~ | ||
2. use typescript wrapper | ||
3. add travis-ci | ||
3. ~~add travis-ci~~ | ||
4. remove rgba or not |
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 @@ | ||
./build/compile_commands.json |
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
File renamed without changes
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,23 @@ | ||
|
||
<style> | ||
.color { | ||
width: 100px; | ||
height: 100px; | ||
float: left; | ||
} | ||
img{ | ||
width: 500px; | ||
display: block; | ||
} | ||
</style> | ||
<img src="large.1.jpg"/><div class="color" style="background-color:rgb(75,84,81)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(223,208,201)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(155,152,153)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(174,182,188)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(172,180,177)"> | ||
|
||
</div> |
File renamed without changes
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,23 @@ | ||
|
||
<style> | ||
.color { | ||
width: 100px; | ||
height: 100px; | ||
float: left; | ||
} | ||
img{ | ||
width: 500px; | ||
display: block; | ||
} | ||
</style> | ||
<img src="large.1.png"/><div class="color" style="background-color:rgb(76,84,81)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(223,208,201)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(154,151,151)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(170,175,182)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(177,188,188)"> | ||
|
||
</div> |
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,23 @@ | ||
|
||
<style> | ||
.color { | ||
width: 100px; | ||
height: 100px; | ||
float: left; | ||
} | ||
img{ | ||
width: 500px; | ||
display: block; | ||
} | ||
</style> | ||
<img src="large.1.png"/><div class="color" style="background-color:rgb(76,84,81)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(223,208,201)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(154,151,151)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(170,175,182)"> | ||
|
||
</div> <div class="color" style="background-color:rgb(177,188,188)"> | ||
|
||
</div> |
File renamed without changes
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
File renamed without changes
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
Binary file not shown.
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
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 |
---|---|---|
@@ -1,79 +1,80 @@ | ||
#include <napi.h> | ||
#include "async.h" | ||
#include "colorquant.h" | ||
#include <napi.h> | ||
class PaletteWorker : public Napi::AsyncWorker { | ||
public: | ||
PaletteWorker(Napi::Function &callback, PIX *pix, int max_color) | ||
: Napi::AsyncWorker(callback), | ||
pix(pix), max_color(max_color), | ||
counter(NULL), cmap(NULL) { | ||
} | ||
~PaletteWorker() { | ||
if (counter) { | ||
free(counter); | ||
} | ||
if (cmap) { | ||
if (cmap->array) { | ||
free(cmap->array); | ||
} | ||
free(cmap); | ||
} | ||
if (pix) { | ||
free(pix); | ||
} | ||
} | ||
void Execute() { | ||
counter = (size_t *)malloc(sizeof(size_t) * max_color); | ||
cmap = pix_median_cut_quant(pix, max_color, 5, 0, counter); | ||
} | ||
void OnOK() { | ||
Napi::HandleScope scope(Env()); | ||
PaletteWorker(Napi::Function &callback, PIX *pix, int max_color, | ||
int max_sub) | ||
: Napi::AsyncWorker(callback), pix(pix), max_color(max_color), | ||
counter(NULL), cmap(NULL), max_sub(max_sub) {} | ||
~PaletteWorker() { | ||
if (counter) { | ||
free(counter); | ||
} | ||
if (cmap) { | ||
if (cmap->array) { | ||
free(cmap->array); | ||
} | ||
free(cmap); | ||
} | ||
if (pix) { | ||
free(pix); | ||
} | ||
} | ||
void Execute() { | ||
counter = (size_t *)malloc(sizeof(size_t) * max_color); | ||
cmap = pix_median_cut_quant(pix, max_color, 5, max_sub, counter); | ||
} | ||
void OnOK() { | ||
Napi::HandleScope scope(Env()); | ||
|
||
if (cmap == NULL) { | ||
auto err = Napi::Error::New(Env(), "Buffer corrupted or image too small or too less color"); | ||
Callback().Call({ err.Value(), Env().Undefined() }); | ||
return; | ||
} | ||
if (cmap == NULL) { | ||
auto err = Napi::Error::New( | ||
Env(), "Buffer corrupted or image too small or too less color"); | ||
Callback().Call({err.Value(), Env().Undefined()}); | ||
return; | ||
} | ||
|
||
Napi::Array result = Napi::Array::New(Env()); | ||
RGB_QUAD *quad = (RGB_QUAD *)cmap->array; | ||
for (size_t i = 0; i < cmap->n; i++) { | ||
Napi::Object item = Napi::Object::New(Env()); | ||
item.Set("R", quad[i].red); | ||
item.Set("G", quad[i].green); | ||
item.Set("B", quad[i].blue); | ||
item.Set("count", counter[i]); | ||
result.Set(i, item); | ||
} | ||
Callback().Call({ Env().Undefined(), result }); | ||
} | ||
Napi::Array result = Napi::Array::New(Env()); | ||
RGB_QUAD *quad = (RGB_QUAD *)cmap->array; | ||
for (size_t i = 0; i < cmap->n; i++) { | ||
Napi::Object item = Napi::Object::New(Env()); | ||
item.Set("R", quad[i].red); | ||
item.Set("G", quad[i].green); | ||
item.Set("B", quad[i].blue); | ||
item.Set("count", counter[i]); | ||
result.Set(i, item); | ||
} | ||
Callback().Call({Env().Undefined(), result}); | ||
} | ||
|
||
private: | ||
PIX *pix; | ||
int max_color; | ||
PIXCMAP *cmap; | ||
size_t *counter; | ||
PIX *pix; | ||
int max_color; | ||
PIXCMAP *cmap; | ||
size_t *counter; | ||
int max_sub; | ||
}; | ||
Napi::Value PaletteAsync(const Napi::CallbackInfo &info) { | ||
auto depth = info[2].As<Napi::Number>().Int32Value(); | ||
auto max_color = info[1].As<Napi::Number>().Int32Value(); | ||
auto depth = info[2].As<Napi::Number>().Int32Value(); | ||
auto max_color = info[1].As<Napi::Number>().Int32Value(); | ||
auto max_sub = info[3].As<Napi::Number>().Int32Value(); | ||
|
||
Napi::Function callback; | ||
callback = info[3].As<Napi::Function>(); | ||
Napi::Function callback; | ||
callback = info[4].As<Napi::Function>(); | ||
|
||
PIX *pix = (PIX *)malloc(sizeof(PIX)); | ||
if (depth == 3) { | ||
auto buffer = info[0].As<Napi::Buffer<RGB_QUAD>>(); | ||
pix->n = buffer.Length(); | ||
pix->pixs = buffer.Data(); | ||
} | ||
else if (depth == 4) { | ||
auto buffer = info[0].As<Napi::Buffer<RGBA_QUAD>>(); | ||
pix->n = buffer.Length(); | ||
pix->pixs = buffer.Data(); | ||
} | ||
pix->depth = depth; | ||
PaletteWorker *paletteWorker = new PaletteWorker(callback, pix, max_color); | ||
paletteWorker->Queue(); | ||
return info.Env().Undefined(); | ||
PIX *pix = (PIX *)malloc(sizeof(PIX)); | ||
if (depth == 3) { | ||
auto buffer = info[0].As<Napi::Buffer<RGB_QUAD>>(); | ||
pix->n = buffer.Length(); | ||
pix->pixs = buffer.Data(); | ||
} else if (depth == 4) { | ||
auto buffer = info[0].As<Napi::Buffer<RGBA_QUAD>>(); | ||
pix->n = buffer.Length(); | ||
pix->pixs = buffer.Data(); | ||
} | ||
pix->depth = depth; | ||
PaletteWorker *paletteWorker = new PaletteWorker(callback, pix, max_color, max_sub); | ||
paletteWorker->Queue(); | ||
return info.Env().Undefined(); | ||
} |
Oops, something went wrong.