Skip to content

Commit

Permalink
feat: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
drxddy committed Feb 4, 2025
1 parent 46b95e7 commit 3bd5982
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
# pHash.c
a perceptual image dct hashing library to compare image similarity

## Usage

```c
#include "pHash.h"
#include <stdio.h>

int main() {
PhashError err;
PhashImage *img = NULL;
uint64_t hash;

// Initialize library
if ((err = phash_initialize()) != PHASH_OK) {
printf("Error: %s\n", phash_error_string(err));
return 1;
}

// Create a simple image (replace with your image loading code)
const int width = 100, height = 100;
unsigned char* data = malloc(width * height * 3);
// Fill image data here...

// Create image object
if ((err = phash_image_create(data, width, height, 3, 1, &img)) != PHASH_OK) {
printf("Error: %s\n", phash_error_string(err));
free(data);
return 1;
}

// Compute hash
if ((err = phash_compute(img, NULL, &hash)) != PHASH_OK) {
printf("Error: %s\n", phash_error_string(err));
} else {
printf("Hash: %016lx\n", hash);
}

// Cleanup
free(data);
phash_image_destroy(img);
phash_terminate();
return 0;
}
```

## Build

```bash
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ int main() {
phash_terminate();

return 0;
}
}

0 comments on commit 3bd5982

Please sign in to comment.