4 #include <leptonica/allheaders.h>
7 #include "imginterface.h"
10 Image
* img_new(size_t w
, size_t h
) {
12 result
= malloc(sizeof(Image
) + (w
* h
* 4));
13 result
->data
= (char*) result
+ sizeof(Image
);
19 Image
* getWorldImage(void) {
21 struct Pix
* pngfile
= pixRead("world3.png");
26 pixGetDimensions(pngfile
, &w
, &h
, NULL
);
27 pix32
= pixConvertTo32(pngfile
);
28 result
= img_new(w
, h
);
29 memcpy(result
->data
, pix32
->data
, w
* h
* 4);
35 void img_fillcolor(Image
* img
, rgb_t color
) {
36 int* out
= (int*) img
->data
;
38 for(h
= 0; h
< img
->h
; h
++) {
39 for(w
= 0; w
< img
->w
; w
++) {
40 *(out
++) = color
.asInt
;
45 Image
* img_scale(Image
* img
, size_t zoomFactor_w
, size_t zoomFactor_h
) {
46 Image
* result
= img_new(img
->w
* zoomFactor_w
, img
->h
* zoomFactor_h
);
47 int* in
= (int*) img
->data
;
48 int* out
= (int*) result
->data
;
50 for(h
= 0; h
< img
->h
; h
++) {
51 for(w
= 0; w
< img
->w
; w
++) {
52 for(zh
= 0; zh
< zoomFactor_h
; zh
++) {
53 for(zw
= 0; zw
< zoomFactor_w
; zw
++) {
54 *(out
+ (((h
* zoomFactor_h
+ zh
) * result
->w
) + (w
* zoomFactor_w
) + zw
)) = *in
;
63 void img_embed(Image
* dest
, Image
* source
, size_t x
, size_t y
) {
64 assert(source
&& dest
&& x
+ source
->w
< dest
->w
&& y
+ source
->h
< dest
->h
);
66 int* in
= (int*) source
->data
;
68 for(h
= 0; h
< source
->h
; h
++) {
69 out
= ((int*) dest
->data
) + ((h
+ y
) * dest
->w
) + x
;
70 for(w
= 0; w
< source
->w
; w
++) {