pipi_get_pixels using the tiles system. These functions should disappear one day, because they're going to leak like crazy. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3341 92316355-f0b4-4df1-b90c-862c8a59935fmaster
@@ -49,7 +49,7 @@ int main(int argc, char *argv[]) | |||||
/* Load image, convert it to grayscale, dither it with Floyd-Steinberg */ | /* Load image, convert it to grayscale, dither it with Floyd-Steinberg */ | ||||
img = pipi_load(argv[1]); | img = pipi_load(argv[1]); | ||||
pipi_get_pixels(img, PIPI_PIXELS_Y_F); | |||||
pipi_set_colorspace(img, PIPI_PIXELS_Y_F); | |||||
gauss = pipi_gaussian_blur(img, sigma); | gauss = pipi_gaussian_blur(img, sigma); | ||||
kernel = pipi_load("ediff:fs"); | kernel = pipi_load("ediff:fs"); | ||||
dither = pipi_dither_ediff(img, kernel, PIPI_SCAN_RASTER); | dither = pipi_dither_ediff(img, kernel, PIPI_SCAN_RASTER); | ||||
@@ -111,6 +111,7 @@ int main(int argc, char *argv[]) | |||||
} | } | ||||
pipi_save(dst, argv[2]); | pipi_save(dst, argv[2]); | ||||
pipi_release_pixels(dst, p); | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -90,6 +90,9 @@ namespace Pipi | |||||
[DllImport("libpipi-0.dll", CallingConvention=CallingConvention.Cdecl), | [DllImport("libpipi-0.dll", CallingConvention=CallingConvention.Cdecl), | ||||
SuppressUnmanagedCodeSecurity] | SuppressUnmanagedCodeSecurity] | ||||
private static extern IntPtr pipi_get_pixels(IntPtr img, int type); | private static extern IntPtr pipi_get_pixels(IntPtr img, int type); | ||||
[DllImport("libpipi-0.dll", CallingConvention=CallingConvention.Cdecl), | |||||
SuppressUnmanagedCodeSecurity] | |||||
private static extern void pipi_release_pixels(IntPtr img, IntPtr p); | |||||
public byte[] GetPixels(int w, int h, int x, int y) | public byte[] GetPixels(int w, int h, int x, int y) | ||||
{ | { | ||||
byte[] array = new byte[w * h * 4]; | byte[] array = new byte[w * h * 4]; | ||||
@@ -116,6 +119,8 @@ namespace Pipi | |||||
} | } | ||||
} | } | ||||
pipi_release_pixels(_picture, pixels); | |||||
return array; | return array; | ||||
} | } | ||||
} | } | ||||
@@ -35,6 +35,7 @@ pipi_histogram_t* pipi_new_histogram(void) | |||||
int pipi_get_image_histogram(pipi_image_t *img, pipi_histogram_t*h, int flags) | int pipi_get_image_histogram(pipi_image_t *img, pipi_histogram_t*h, int flags) | ||||
{ | { | ||||
pipi_pixels_t *p; | |||||
uint8_t *data; | uint8_t *data; | ||||
float n; | float n; | ||||
unsigned int max; | unsigned int max; | ||||
@@ -42,7 +43,8 @@ int pipi_get_image_histogram(pipi_image_t *img, pipi_histogram_t*h, int flags) | |||||
if(!h) return -1; | if(!h) return -1; | ||||
data = (uint8_t *)pipi_get_pixels(img, PIPI_PIXELS_RGBA_C)->pixels; | |||||
p = pipi_get_pixels(img, PIPI_PIXELS_RGBA_C); | |||||
data = (uint8_t *)p->pixels; | |||||
memset(h->a, 0, 256*(sizeof(unsigned int))); | memset(h->a, 0, 256*(sizeof(unsigned int))); | ||||
memset(h->r, 0, 256*(sizeof(unsigned int))); | memset(h->r, 0, 256*(sizeof(unsigned int))); | ||||
memset(h->g, 0, 256*(sizeof(unsigned int))); | memset(h->g, 0, 256*(sizeof(unsigned int))); | ||||
@@ -118,6 +120,8 @@ int pipi_get_image_histogram(pipi_image_t *img, pipi_histogram_t*h, int flags) | |||||
h->y[i]*=n; | h->y[i]*=n; | ||||
} | } | ||||
pipi_release_pixels(img, p); | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -41,6 +41,7 @@ double pipi_measure_msd(pipi_image_t *i1, pipi_image_t *i2) | |||||
f1 = i1->last_modified; | f1 = i1->last_modified; | ||||
f2 = i2->last_modified; | f2 = i2->last_modified; | ||||
/* FIXME: this is not right */ | |||||
pipi_get_pixels(i1, PIPI_PIXELS_Y_F); | pipi_get_pixels(i1, PIPI_PIXELS_Y_F); | ||||
pipi_get_pixels(i2, PIPI_PIXELS_Y_F); | pipi_get_pixels(i2, PIPI_PIXELS_Y_F); | ||||
@@ -70,6 +70,8 @@ pipi_image_t *pipi_load_gdi(const char *name) | |||||
/* FIXME: do we need to swap bytes? Apparently Vista doesn't need it, | /* FIXME: do we need to swap bytes? Apparently Vista doesn't need it, | ||||
* but we'd need a more thorough test. */ | * but we'd need a more thorough test. */ | ||||
pipi_release_pixels(img, p); | |||||
img->codec_priv = NULL; | img->codec_priv = NULL; | ||||
img->wrap = 0; | img->wrap = 0; | ||||
@@ -135,6 +137,8 @@ int pipi_save_gdi(pipi_image_t *img, const char *name) | |||||
} | } | ||||
CloseHandle(hfile); | CloseHandle(hfile); | ||||
pipi_release_pixels(img, p); | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -98,7 +98,7 @@ int pipi_save_imlib2(pipi_image_t *img, const char *name) | |||||
img->u8 = 1; | img->u8 = 1; | ||||
} | } | ||||
pipi_get_pixels(img, img->codec_format); | |||||
pipi_set_colorspace(img, img->codec_format); | |||||
imlib_context_set_image(img->codec_priv); | imlib_context_set_image(img->codec_priv); | ||||
imlib_save_image(name); | imlib_save_image(name); | ||||
@@ -205,6 +205,8 @@ end: | |||||
free(line); | free(line); | ||||
fclose(fp); | fclose(fp); | ||||
pipi_release_pixels(img, pixels); | |||||
return 1; | return 1; | ||||
} | } | ||||
@@ -91,7 +91,7 @@ int pipi_save_opencv(pipi_image_t *img, const char *name) | |||||
img->u8 = 1; | img->u8 = 1; | ||||
} | } | ||||
pipi_get_pixels(img, img->codec_format); | |||||
pipi_set_colorspace(img, img->codec_format); | |||||
cvSaveImage(name, img->codec_priv); | cvSaveImage(name, img->codec_priv); | ||||
return 0; | return 0; | ||||
@@ -110,6 +110,8 @@ pipi_image_t *pipi_load_oric(char const *name) | |||||
img->wrap = 0; | img->wrap = 0; | ||||
img->u8 = 1; | img->u8 = 1; | ||||
pipi_release_pixels(img, p); | |||||
return img; | return img; | ||||
} | } | ||||
@@ -139,16 +141,15 @@ int pipi_save_oric(pipi_image_t *img, char const *name) | |||||
fwrite("\x00", 1, 1, fp); | fwrite("\x00", 1, 1, fp); | ||||
if(img->w != WIDTH || img->h != HEIGHT) | if(img->w != WIDTH || img->h != HEIGHT) | ||||
{ | |||||
tmp = pipi_resize(img, WIDTH, HEIGHT); | tmp = pipi_resize(img, WIDTH, HEIGHT); | ||||
p = pipi_get_pixels(tmp, PIPI_PIXELS_RGBA_F); | |||||
} | |||||
else | else | ||||
p = pipi_get_pixels(img, PIPI_PIXELS_RGBA_F); | |||||
tmp = img; | |||||
p = pipi_get_pixels(tmp, PIPI_PIXELS_RGBA_F); | |||||
data = p->pixels; | data = p->pixels; | ||||
screen = malloc(WIDTH * HEIGHT / 6); | screen = malloc(WIDTH * HEIGHT / 6); | ||||
write_screen(data, screen); | write_screen(data, screen); | ||||
if(tmp) | |||||
pipi_release_pixels(tmp, p); | |||||
if(tmp != img) | |||||
pipi_free(tmp); | pipi_free(tmp); | ||||
fwrite(screen, 1, WIDTH * HEIGHT / 6, fp); | fwrite(screen, 1, WIDTH * HEIGHT / 6, fp); | ||||
@@ -95,7 +95,7 @@ int pipi_save_sdl(pipi_image_t *img, const char *name) | |||||
img->u8 = 1; | img->u8 = 1; | ||||
} | } | ||||
pipi_get_pixels(img, img->codec_format); | |||||
pipi_set_colorspace(img, img->codec_format); | |||||
SDL_SaveBMP(img->codec_priv, name); | SDL_SaveBMP(img->codec_priv, name); | ||||
return 0; | return 0; | ||||
@@ -144,6 +144,8 @@ __extern int pipi_save(pipi_image_t *, const char *); | |||||
__extern void pipi_set_gamma(double); | __extern void pipi_set_gamma(double); | ||||
__extern pipi_pixels_t *pipi_get_pixels(pipi_image_t *, pipi_format_t); | __extern pipi_pixels_t *pipi_get_pixels(pipi_image_t *, pipi_format_t); | ||||
__extern void pipi_release_pixels(pipi_image_t *, pipi_pixels_t *); | |||||
__extern void pipi_set_colorspace(pipi_image_t *, pipi_format_t); | |||||
__extern int pipi_get_image_width(pipi_image_t *img); | __extern int pipi_get_image_width(pipi_image_t *img); | ||||
__extern int pipi_get_image_height(pipi_image_t *img); | __extern int pipi_get_image_height(pipi_image_t *img); | ||||
__extern int pipi_get_image_pitch(pipi_image_t *img); | __extern int pipi_get_image_pitch(pipi_image_t *img); | ||||
@@ -250,6 +250,17 @@ pipi_pixels_t *pipi_get_pixels(pipi_image_t *img, pipi_format_t type) | |||||
return &img->p[type]; | return &img->p[type]; | ||||
} | } | ||||
void pipi_release_pixels(pipi_image_t *img, pipi_pixels_t *p) | |||||
{ | |||||
return; | |||||
} | |||||
void pipi_set_colorspace(pipi_image_t *img, pipi_format_t fmt) | |||||
{ | |||||
pipi_pixels_t *p = pipi_get_pixels(img, fmt); | |||||
pipi_release_pixels(img, p); | |||||
} | |||||
void pipi_set_gamma(double g) | void pipi_set_gamma(double g) | ||||
{ | { | ||||
if(g > 0.) | if(g > 0.) | ||||
@@ -107,6 +107,5 @@ pipi_tile_t *pipi_create_tile(pipi_format_t fmt, int plane) | |||||
return ret; | return ret; | ||||
} | } | ||||
#endif /* USE_TILES */ | #endif /* USE_TILES */ | ||||