parent
7527276a8e
commit
848b3af260
5 changed files with 200 additions and 1 deletions
@ -0,0 +1,96 @@ |
||||
#include <string.h> |
||||
#include <arpa/inet.h> |
||||
|
||||
#define SHSH(n, v) ((((v) << (n)) & 0xffffffff) | ((v) >> (32 - (n)))) |
||||
|
||||
int |
||||
sha1(unsigned char *data, int size, unsigned char *dst) |
||||
{ |
||||
unsigned int digest[5], word[80], wa, wb, wc, wd, we, t; |
||||
unsigned char buf[64], *d; |
||||
int idx, left, i; |
||||
const unsigned int magic[4] = |
||||
{ |
||||
0x5a827999, |
||||
0x6ed9eba1, |
||||
0x8f1bbcdc, |
||||
0xca62c1d6 |
||||
}; |
||||
|
||||
idx = 0; |
||||
digest[0] = 0x67452301; |
||||
digest[1] = 0xefcdab89; |
||||
digest[2] = 0x98badcfe; |
||||
digest[3] = 0x10325476; |
||||
digest[4] = 0xc3d2e1f0; |
||||
|
||||
memset(buf, 0, sizeof(buf)); |
||||
for (left = size, d = data; left > 0; left--, d++) |
||||
{ |
||||
if ((idx == 0) && (left < 64)) |
||||
{ |
||||
memset(buf, 0, 60); |
||||
buf[60] = (size >> 24) & 0xff; |
||||
buf[61] = (size >> 16) & 0xff; |
||||
buf[62] = (size >> 8) & 0xff; |
||||
buf[63] = (size) & 0xff; |
||||
} |
||||
buf[idx] = *d; |
||||
idx++; |
||||
if ((idx == 64) || (left == 1)) |
||||
{ |
||||
if ((left == 1) && (idx < 64)) buf[idx] = 0x80; |
||||
for (i = 0; i < 16; i++) |
||||
{ |
||||
word[i] = (unsigned int)buf[(i * 4) ] << 24; |
||||
word[i] |= (unsigned int)buf[(i * 4) + 1] << 16; |
||||
word[i] |= (unsigned int)buf[(i * 4) + 2] << 8; |
||||
word[i] |= (unsigned int)buf[(i * 4) + 3]; |
||||
} |
||||
for (i = 16; i < 80; i++) |
||||
word[i] = SHSH(1, |
||||
word[i - 3 ] ^ word[i - 8 ] ^ |
||||
word[i - 14] ^ word[i - 16]); |
||||
wa = digest[0]; |
||||
wb = digest[1]; |
||||
wc = digest[2]; |
||||
wd = digest[3]; |
||||
we = digest[4]; |
||||
for (i = 0; i < 80; i++) |
||||
{ |
||||
if (i < 20) |
||||
t = SHSH(5, wa) + ((wb & wc) | ((~wb) & wd)) + |
||||
we + word[i] + magic[0]; |
||||
else if (i < 40) |
||||
t = SHSH(5, wa) + (wb ^ wc ^ wd) + |
||||
we + word[i] + magic[1]; |
||||
else if (i < 60) |
||||
t = SHSH(5, wa) + ((wb & wc) | (wb & wd) | (wc & wd)) + |
||||
we + word[i] + magic[2]; |
||||
else if (i < 80) |
||||
t = SHSH(5, wa) + (wb ^ wc ^ wd) + |
||||
we + word[i] + magic[3]; |
||||
we = wd; |
||||
wd = wc; |
||||
wc = SHSH(30, wb); |
||||
wb = wa; |
||||
wa = t; |
||||
} |
||||
digest[0] += wa; |
||||
digest[1] += wb; |
||||
digest[2] += wc; |
||||
digest[3] += wd; |
||||
digest[4] += we; |
||||
idx = 0; |
||||
} |
||||
} |
||||
|
||||
t = htonl(digest[0]); digest[0] = t; |
||||
t = htonl(digest[1]); digest[1] = t; |
||||
t = htonl(digest[2]); digest[2] = t; |
||||
t = htonl(digest[3]); digest[3] = t; |
||||
t = htonl(digest[4]); digest[4] = t; |
||||
|
||||
memcpy(dst, digest, 5 * 4); |
||||
return 1; |
||||
} |
@ -0,0 +1 @@ |
||||
int sha1(unsigned char *data, int size, unsigned char *dst); |
@ -0,0 +1,88 @@ |
||||
#include <Elementary.h> |
||||
#include "sha1.h" |
||||
|
||||
static Evas_Object *win = NULL, *subwin = NULL, *image = NULL; |
||||
static Evas_Object *vidimage = NULL; |
||||
static int iw, ih; |
||||
static unsigned char sum[20]; |
||||
static Eet_File *ef; |
||||
|
||||
EAPI_MAIN int |
||||
elm_main(int argc, char **argv) |
||||
{ |
||||
char buf_base[PATH_MAX]; |
||||
char buf_file[PATH_MAX]; |
||||
unsigned int pos, incr; |
||||
|
||||
if (argc < 3) exit(1); |
||||
elm_need_efreet(); |
||||
|
||||
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); |
||||
elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); |
||||
elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); |
||||
elm_app_info_set(elm_main, "rage", "themes/default.edj"); |
||||
|
||||
elm_config_engine_set("buffer"); |
||||
win = elm_win_add(NULL, "Rage", ELM_WIN_BASIC); |
||||
subwin = elm_win_add(win, "inlined", ELM_WIN_INLINED_IMAGE); |
||||
image = elm_win_inlined_image_object_get(subwin); |
||||
|
||||
evas_object_show(subwin); |
||||
evas_object_show(win); |
||||
|
||||
elm_win_norender_push(subwin); |
||||
elm_win_norender_push(win); |
||||
|
||||
vidimage = evas_object_image_filled_add(evas_object_evas_get(subwin)); |
||||
evas_object_show(vidimage); |
||||
|
||||
evas_object_image_file_set(vidimage, argv[1], NULL); |
||||
evas_object_image_size_get(vidimage, &iw, &ih); |
||||
if (!sha1((unsigned char *)argv[1], strlen(argv[1]), sum)) exit(2); |
||||
if (!efreet_cache_home_get()) exit(3); |
||||
snprintf(buf_base, sizeof(buf_base), "%s/rage/thumb/%02x", |
||||
efreet_cache_home_get(), sum[0]); |
||||
snprintf(buf_file, sizeof(buf_base), |
||||
"%s/%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" |
||||
"%02x%02x%02x%02x%02x%02x%02x%02x.eet", |
||||
buf_base, |
||||
sum[1], sum[2], sum[3], |
||||
sum[4], sum[5], sum[6], sum[7], |
||||
sum[8], sum[9], sum[10], sum[11], |
||||
sum[12], sum[13], sum[14], sum[15], |
||||
sum[16], sum[17], sum[18], sum[19]); |
||||
if (!ecore_file_mkpath(buf_base)) exit(4); |
||||
ef = eet_open(buf_file, EET_FILE_MODE_WRITE); |
||||
if (!ef) exit(5); |
||||
pos = 0; |
||||
incr = atoi(argv[2]); |
||||
for (pos = 0; ; pos += incr) |
||||
{ |
||||
int w, h; |
||||
int *pixels; |
||||
char key[128]; |
||||
|
||||
snprintf(key, sizeof(key), "%i", pos); |
||||
pos += incr; |
||||
evas_object_image_file_set(vidimage, argv[1], key); |
||||
evas_object_image_size_get(vidimage, &iw, &ih); |
||||
if ((iw <= 0) || (ih <= 0)) break; |
||||
w = 160; |
||||
h = (ih * 160) / iw; |
||||
if (h < 1) h = 1; |
||||
evas_object_resize(vidimage, w, h); |
||||
evas_object_resize(subwin, w, h); |
||||
elm_win_render(subwin); |
||||
pixels = evas_object_image_data_get(image, EINA_FALSE); |
||||
if (pixels) |
||||
{ |
||||
eet_data_image_write(ef, key, pixels, w, h, |
||||
0, 0, 70, EET_IMAGE_JPEG); |
||||
} |
||||
evas_object_image_data_set(image, pixels); |
||||
} |
||||
eet_close(ef); |
||||
elm_shutdown(); |
||||
return 0; |
||||
} |
||||
ELM_MAIN() |
Loading…
Reference in new issue