home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / Chip_2002-02_cd1.bin / ctenari / Krutak / univiewi_pdk.exe / cimage.h next >
C/C++ Source or Header  |  2001-12-16  |  15KB  |  272 lines

  1. /*
  2.     UniView 1.73+ Image for plugin SDK
  3.  
  4.     This file is allows you to create UniView plugins supporting Image
  5.     operations. If you want to use it,     you must agree following text
  6.     and you can start programming :-)
  7.  
  8.     Copyright (C)1998-2001 by Andrej Krutak
  9.  
  10.     Permission to use, copy, modify, and distribute this
  11.     software and its documentation for any purpose, without
  12.     fee, and without written agreement is hereby granted,
  13.     provided that the above copyright notice appear in all
  14.     copies and that both copyright notice and this permission
  15.     notice appear in supporting documentation.  This software
  16.     is provided "as is" without express or implied warranty.
  17. */
  18.  
  19. #include <windows.h>
  20.  
  21. #define IMAGE_SIZE_RESAMPLE            0
  22. #define IMAGE_SIZE_CROP                1
  23. //Resize filters
  24. #define IMAGE_SIZE_FILTER_DEFAULT    0
  25.  
  26. //Status of CImage
  27. #define IMAGE_OK    0
  28. #define IMAGE_BAD    1
  29.  
  30. //CImage load errors
  31. #define OPEN_SUCESS            0
  32. #define UNSUP_FORMAT        1
  33. #define CORRUP_IMAGE        2
  34. #define OUT_OF_MEMORY        3
  35. #define UNKNOWN_ERROR        4
  36. #define BAD_HEADER            5
  37. #define FILE_ERROR            6
  38. #define BAD_COLORTABLE        7
  39. #define BAD_VERSION            8
  40. #define INTERNAL_ERROR        9
  41. #define WARNING_CORRUPTED    -1
  42.  
  43. typedef void * CImage;
  44.  
  45. extern "C" {
  46. __declspec (dllexport) CImage* UVImage_create(int xs, int ys, int bpp);
  47. __declspec (dllexport) int UVImage_recreate(CImage *img, int xs, int ys, int bpp);
  48. __declspec (dllexport) int UVImage_getXSize(CImage *img);
  49. __declspec (dllexport) int UVImage_getYSize(CImage *img);
  50. __declspec (dllexport) int UVImage_getBPP(CImage *img);
  51. __declspec (dllexport) int UVImage_destroy(CImage *img);
  52. __declspec (dllexport) CImage *UVImage_getSelection(CImage *img, RECT &rect);
  53. __declspec (dllexport) int UVImage_setRGB(CImage *img, int x, int y, BYTE r, BYTE g, BYTE b);
  54. __declspec (dllexport) int UVImage_setRGB2(CImage *img, int x, int y, COLORREF rgb);
  55. __declspec (dllexport) int UVImage_setR(CImage *img, int x, int y, BYTE r);
  56. __declspec (dllexport) int UVImage_setG(CImage *img, int x, int y, BYTE g);
  57. __declspec (dllexport) int UVImage_setB(CImage *img, int x, int y, BYTE r);
  58. __declspec (dllexport) int UVImage_setGR(CImage *img, int x, int y, BYTE gr);
  59. __declspec (dllexport) int UVImage_getRGB(CImage *img, int x, int y, BYTE &r, BYTE &g, BYTE &b);
  60. __declspec (dllexport) int UVImage_getRGB2(CImage *img, int x, int y, COLORREF &c);
  61. __declspec (dllexport) BYTE UVImage_getR(CImage *img, int x, int y);
  62. __declspec (dllexport) BYTE UVImage_getG(CImage *img, int x, int y);
  63. __declspec (dllexport) BYTE UVImage_getB(CImage *img, int x, int y);
  64. __declspec (dllexport) BYTE UVImage_getL(CImage *img, int x, int y); //Returns L item (lightness) from HLS color model...
  65. __declspec (dllexport) int UVImage_getCol(CImage *img, COLORREF *col, int x); //Functions copying whole column or row (target buffer must be large enought to hold data!)
  66. __declspec (dllexport) int UVImage_getRow(CImage *img, COLORREF *row, int y);
  67. __declspec (dllexport) int UVImage_setPenColor2(CImage *img, COLORREF rgb); //Sets pencolor
  68. __declspec (dllexport) int UVImage_setPenColor(CImage *img, BYTE r, BYTE g, BYTE b);
  69. __declspec (dllexport) int UVImage_getPenColor2(CImage *img, COLORREF &rgb); //Gets pencolor
  70. __declspec (dllexport) int UVImage_getPenColor(CImage *img, BYTE &r, BYTE &g, BYTE &b);
  71. __declspec (dllexport) int UVImage_setLineRGB(CImage *img, int line, BYTE *row, int pixels); //Sets line's RGB-triples bytes
  72. __declspec (dllexport) int UVImage_setLineRGB2(CImage *img, int line, COLORREF *row, int pixels);
  73.  
  74. //-------------Copy functions-------------
  75. //This functions simply copies CImage to target CImage, doesn't perform any special operations even if target CImage is smaller than source (target will be croped)
  76. __declspec (dllexport) int UVImage_copyTo(CImage *img, CImage* timg, int xp=0, int yp=0);
  77. //This functions copies CImage to target CImage, if the target CImage is too small, size of target CImage will be increased
  78. __declspec (dllexport) int UVImage_copyTo_enlargetarget(CImage *img, CImage* timg);
  79. //This function copies selected rectangle of CImage to some position of target CImage
  80. __declspec (dllexport) int UVImage_copyRectTo(CImage *img, int x, int y, int xs, int ys, CImage &timg, int tx, int ty);
  81. //This functions copies CImage to target CImage and changes it's size to target's CImage size (will perform resample size)
  82. __declspec (dllexport) int UVImage_scaleTo2(CImage *img, CImage& timg);
  83. __declspec (dllexport) int UVImage_scaleTo(CImage *img, CImage* timg);
  84.  
  85. //This functions copies CImage to target and changes it's size so it will be copied as 'thumbnail' - will have the same x:y ratio and it will be in maximal target picture size (CImage will be centered in area of target CImage which has imaginary bx*by border)
  86. __declspec (dllexport) int UVImage_thumbnailTo2(CImage *img, CImage& timg, int bx=0, int by=0, int border=1, int useresample=0);
  87. __declspec (dllexport) int UVImage_thumbnailTo(CImage *img, CImage* timg, int bx=0, int by=0, int border=1, int useresample=0);
  88.  
  89. //-------------CImage effects-------------
  90. //This function resizes CImage to selected size
  91. __declspec (dllexport) int UVImage_resize(CImage *img, int newx, int newy, int rtype=0, int rfilter=0);
  92.  
  93. //This function changes color depth of CImage, onebppparam is currently used as parameter for hilbert filter
  94. __declspec (dllexport) int UVImage_quantize(CImage *img, int newcolors, int filter, int onebppparam=1, int xbppparam1=1, int xbppparam2=2);
  95.  
  96. //Creates color table for CImage
  97. __declspec (dllexport) int UVImage_colortable_make(CImage *img);
  98.  
  99. //Returns count of colortable items
  100. __declspec (dllexport) int UVImage_colortable_itemscount(CImage *img);
  101.  
  102. //Frees color table (it's automatically called by destructor, but you should use it explicitly to free memory)
  103. __declspec (dllexport) int UVImage_colortable_free(CImage *img);
  104.  
  105. //These functions are testing, whether colortable is truecolor, greyscale, B/W or colormapped
  106. __declspec (dllexport) int UVImage_colortable_isgreyscale(CImage *img);
  107. __declspec (dllexport) int UVImage_colortable_isblackwhite(CImage *img);
  108. __declspec (dllexport) int UVImage_colortable_istruecolor(CImage *img);
  109. __declspec (dllexport) int UVImage_colortable_iscolormapped(CImage *img);
  110.  
  111. //Returns colortable items (colors array must be large enought to hold data), you can specify maxbpp to limit maximal count of colors returned
  112. __declspec (dllexport) int UVImage_colortable_get(CImage *img, COLORREF colors[], int maxbpp=8);
  113.  
  114. //Returns index of specified color in colortable or -1 if this color doesn't exist in
  115. __declspec (dllexport) int UVImage_colortable_lookupcolor(CImage *img, BYTE r, BYTE g, BYTE b, long *count=NULL);
  116. __declspec (dllexport) int UVImage_colortable_lookupcolo2r(CImage *img, COLORREF c, long *count=NULL);
  117.  
  118. //DANGEROUS: Sets colormap for CImage from COLORREF table with lenght 'len'. Be sure it's the right colortable, otherwise, CImage class will do strange things!
  119. __declspec (dllexport) int UVImage_colortable_set(CImage *img, COLORREF table[], int len);
  120.  
  121. //DANGEROUS: Sets index of specified color and validates other indexes...
  122. __declspec (dllexport) int UVImage_colortable_setcolorindex(CImage *img, BYTE r, BYTE g, BYTE b, int index);
  123. __declspec (dllexport) int UVImage_colortable_setcolorindex2(CImage *img, COLORREF c, int index);
  124.  
  125. //Specific filters for color quantizing. Used by quantize method
  126. __declspec (dllexport) int UVImage_quantize_1bpp_epox1(CImage *img);
  127. __declspec (dllexport) int UVImage_quantize_1bpp_epox2(CImage *img);
  128. __declspec (dllexport) int UVImage_quantize_1bpp_epox3(CImage *img);
  129. __declspec (dllexport) int UVImage_quantize_1bpp_epox4(CImage *img);
  130. __declspec (dllexport) int UVImage_quantize_1bpp_epox5(CImage *img);
  131. __declspec (dllexport) int UVImage_quantize_1bpp_other(CImage *img, int type, int hilbertp=1);
  132. __declspec (dllexport) int UVImage_quantize_xbpp(CImage *img, int newcolors, int filter, int type1=1, int type2=2);
  133.  
  134. //This function erases whole CImage with color specified with 'color' parameter
  135. __declspec (dllexport) int UVImage_clear(CImage *img, COLORREF color);
  136.  
  137. //Fills selection of CImage with current pen color
  138. __declspec (dllexport) int UVImage_fill(CImage *img, COLORREF color);
  139. __declspec (dllexport) int UVImage_fill2(CImage *img);
  140.  
  141. //Draws rect with specified color (uses selection)
  142. __declspec (dllexport) int UVImage_drawRect(CImage *img, COLORREF color);
  143.  
  144. //-------------File manipulating functions-------------
  145. //This function loads specified file if possible (if filters for specified file type are available) - automatically recognizes input format (by RAW, YUV and ICO it uses settings of UniView - use specific functions to control loading parameters (open_raw, open_yuv, open_ico))
  146. __declspec (dllexport) int UVImage_load(CImage *img, char *path, ...);
  147.  
  148. //This function saves specified file if possible (if filters for specified file type are available) - automatically recognizes target format and uses settings of UniView to set files' properties (use specific functions to modify)
  149. __declspec (dllexport) int UVImage_save(CImage *img, char *path, char *extuse=NULL, ...);
  150.  
  151. //-------------Service functions-------------
  152. //Functions to give CImage's internal data (please don't do any sh*t with these pointers)
  153. __declspec (dllexport) BITMAPINFO* UVImage_getbmi(CImage *img);
  154.  
  155. //Selects whole CImage
  156. __declspec (dllexport) int UVImage_clearsel(CImage *img);
  157.  
  158. //Sets description of CImage, string MUST be maximal 256 characters long
  159. __declspec (dllexport) int UVImage_setDescription(CImage *img, char *str);
  160.  
  161. //Gets description of CImage
  162. __declspec (dllexport) int UVImage_getDescription(CImage *img, char *str);
  163.  
  164. //Returns status of CImage - IMAGE_OK if all ok, some other value otherwise
  165. __declspec (dllexport) int UVImage_getStatus(CImage *img);
  166.  
  167. //Sets curent selection of CImage...
  168. __declspec (dllexport) int UVImage_setselection(CImage *img, long x, long y, long xs, long ys);
  169.  
  170. //Retrieves, if CImage's selection is selecting whole CImage
  171. __declspec (dllexport) int UVImage_isSelectedAll(CImage *img);
  172.  
  173. //-------------Available CImage effects-------------
  174. //Makes 3D button in CImage, uses selection
  175. __declspec (dllexport) int UVImage_effect_3dbutton(CImage *img, int butx, int buty, int graybutton);
  176.  
  177. //Dims current selection using strength parameter as intensity
  178. __declspec (dllexport) int UVImage_effect_dim(CImage *img, int strength);
  179.  
  180. //Creates mirror of CImage
  181. __declspec (dllexport) int UVImage_effect_flip(CImage *img);
  182.  
  183. //Creates top-bottom switched CImage
  184. __declspec (dllexport) int UVImage_effect_flop(CImage *img);
  185.  
  186. //Rotates CImage left
  187. __declspec (dllexport) int UVImage_effect_rotateleft(CImage *img);
  188.  
  189. //Rotates CImage right
  190. __declspec (dllexport) int UVImage_effect_rotateright(CImage *img);
  191.  
  192. //Isolates selected color (prm. which) and, optionally shows this channel in color mode
  193. __declspec (dllexport) int UVImage_effect_isolatecolor_rgb(CImage *img, int which, int togray=0);
  194.  
  195. //Isolates selected component of HSV model of CImage
  196. __declspec (dllexport) int UVImage_effect_isolatecolor_hsv(CImage *img, int which);
  197.  
  198. //Converts CImage from RGB to other CImage channel order (each parameter specifies new position of component, zero-based - eg. if newri=2, newgi=1, newbi=0, CImage will be BGR)
  199. __declspec (dllexport) int UVImage_effect_rgbto(CImage *img, int newri, int newgi, int newbi);
  200.  
  201. //Creates negative of CImage
  202. __declspec (dllexport) int UVImage_effect_negative(CImage *img);
  203.  
  204. //Replaces greyscale colors with color
  205. __declspec (dllexport) int UVImage_effect_replacegrey(CImage *img, int tolerance, COLORREF pencolor);
  206.  
  207. //Creates gray CImage using algorithm C=(R+G+B)/3 for each pixel
  208. __declspec (dllexport) int UVImage_effect_makegray_sum(CImage *img);
  209.  
  210. //Creates gray CImage using lightness value of HSV color model (it's faster then HSV isolating, but it's less sophisticated...)
  211. __declspec (dllexport) int UVImage_effect_makegray_light(CImage *img);
  212.  
  213. //Changes color attributes of CImage (first three pars. are changing RGB, next three HSV and last gamma values of pixel)
  214. __declspec (dllexport) int UVImage_effect_enhance_colors(CImage *img, int retr, int retg, int retb, int reth, int rets, int retv, double gamma);
  215.  
  216. //Makes pixelized CImage with boxx*boxy size boxes
  217. __declspec (dllexport) int UVImage_effect_pixelize(CImage *img, int boxx, int boxy);
  218.  
  219. //Exploses CImage using matrixx*matrixy size matrix and seed parameter as strength
  220. __declspec (dllexport) int UVImage_effect_explosion(CImage *img, int matrixx, int matrixy, int seed);
  221.  
  222. //Finds edges in CImage
  223. __declspec (dllexport) int UVImage_effect_findedges(CImage *img);
  224.  
  225. //Makes details more visible by strenght factor
  226. __declspec (dllexport) int UVImage_effect_enhance(CImage *img, int strenght);
  227.  
  228. //Makes CImage like it were slopped by some liquid
  229. __declspec (dllexport) int UVImage_effect_slopedcolors(CImage *img);
  230.  
  231. //Makes 'oilpaint work' from CImage
  232. __declspec (dllexport) int UVImage_effect_oilpaint(CImage *img, int bublesize);
  233.  
  234. //Embosses CImage
  235. __declspec (dllexport) int UVImage_effect_emboss(CImage *img, int azimuth, int elevation, int width);
  236.  
  237. //Noises CImage
  238. __declspec (dllexport) int UVImage_effect_noise(CImage *img, int intensity, int colornoise, int additive, int strenght);
  239.  
  240. //Interlaces CImage
  241. __declspec (dllexport) int UVImage_effect_interlace(CImage *img, int stepx, int stepy, int offsetx, int offsety, int type, COLORREF pencolor);
  242.  
  243. //Shakes CImage
  244. __declspec (dllexport) int UVImage_effect_shake(CImage *img, COLORREF color);
  245.  
  246. //Custom matrix-defined effect
  247. __declspec (dllexport) int UVImage_effect_custom(CImage *img, int vals[49], int div, int bias);
  248.  
  249. //Makes gradient in CImage
  250. __declspec (dllexport) int UVImage_effect_gradient(CImage *img, int type, COLORREF color1=RGB(0, 0, 0), COLORREF color2=RGB(255, 255, 255));
  251.  
  252. //Blurs CImage like it was moved fast
  253. __declspec (dllexport) int UVImage_effect_motionblur(CImage *img, int direction, int step, int stepcount);
  254.  
  255. //Adds CImage to specified position with alpha-specified transparency (0:min-100:max)
  256. __declspec (dllexport) int UVImage_effect_addimage(CImage *img, CImage &tmp, int xs=0, int ys=0, int alpha=100);
  257.  
  258. //Blurs CImage
  259. __declspec (dllexport) int UVImage_effect_blur(CImage *img, int strenght);
  260.  
  261. //Applies decolorify effect to CImage
  262. __declspec (dllexport) int UVImage_effect_decolorify(CImage *img, int maxc);
  263.  
  264. //Applies median filter to CImage
  265. __declspec (dllexport) int UVImage_effect_medianfilter(CImage *img, int radius);
  266.  
  267. //Changes contrast of CImage
  268. __declspec (dllexport) int UVImage_effect_contrast(CImage *img, int strenght);
  269.  
  270. //Applies threshold effect to CImage
  271. __declspec (dllexport) int UVImage_effect_threshold(CImage *img, int value, COLORREF c1, COLORREF c2);
  272. }