diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-10-20 20:17:27 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-10-20 20:17:27 +0400 |
commit | 46deddcc62784dab47b1f14dda0d802f5f341b18 (patch) | |
tree | e3542a1b2d10f1c77e4ac5f7078f485d5b4e1006 /intern | |
parent | e5a9e0b12a6d6aa334561edaf8a839f3f1a8d7d4 (diff) |
Image Stamping patch by Diego (and peach request)- stamps image info into metadata and optionally
draws into the
frame.
This patch includes some changes I made...
* use blenders bitmap fonts (rather then own fonts)
* select font size
* user interface layout changes
* Marker as another image stamp option
Also added some new API calls
BMF_GetFontHeight(font);
BMF_DrawStringBuf(...); - so we can draw text into an imbuf's image buffer.
get_frame_marker(frame) - get the last marker from the frame.
IMB_rectfill_area(...) - fill in an image buffer with a rectangle area of color.
TODO - draw stamp info in 3d view, at the moment it just displays in the animation.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/bmfont/BMF_Api.h | 22 | ||||
-rw-r--r-- | intern/bmfont/intern/BMF_Api.cpp | 11 | ||||
-rw-r--r-- | intern/bmfont/intern/BMF_BitmapFont.cpp | 90 | ||||
-rw-r--r-- | intern/bmfont/intern/BMF_BitmapFont.h | 20 |
4 files changed, 143 insertions, 0 deletions
diff --git a/intern/bmfont/BMF_Api.h b/intern/bmfont/BMF_Api.h index 5900ea85ec7..1b4a4ee3129 100644 --- a/intern/bmfont/BMF_Api.h +++ b/intern/bmfont/BMF_Api.h @@ -110,6 +110,11 @@ void BMF_GetStringBoundingBox(BMF_Font* font, char* str, float*llx, float *lly, void BMF_GetFontBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r); /** + * Same as GetFontBoundingBox but only returns the height + */ +int BMF_GetFontHeight(BMF_Font* font); + +/** * Convert the given @a font to a texture, and return the GL texture * ID of the texture. If the texture ID is bound, text can * be drawn using the texture by calling DrawStringTexture. @@ -134,6 +139,23 @@ int BMF_GetFontTexture(BMF_Font* font); */ void BMF_DrawStringTexture(BMF_Font* font, char* string, float x, float y, float z); + /** + * Draw the given @a string at the point @a xpos, @a ypos using + * char and float buffers. + * + * @param string The c-string to draw. + * @param xpos The x coordinate to start drawing at. + * @param ypos The y coordinate to start drawing at. + * @param fgcol The forground color. + * @param bgcol The background color. + * @param buf Unsigned char image buffer, when NULL to not operate on it. + * @param fbuf float image buffer, when NULL to not operate on it. + * @param w image buffer width. + * @param h image buffer height. + */ +void BMF_DrawStringBuf(BMF_Font* font, char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h); + + #ifdef __cplusplus } #endif diff --git a/intern/bmfont/intern/BMF_Api.cpp b/intern/bmfont/intern/BMF_Api.cpp index 176ef452fdc..eaa8ffb939d 100644 --- a/intern/bmfont/intern/BMF_Api.cpp +++ b/intern/bmfont/intern/BMF_Api.cpp @@ -164,6 +164,12 @@ void BMF_GetFontBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_ ((BMF_BitmapFont*)font)->GetFontBoundingBox(*xmin_r, *ymin_r, *xmax_r, *ymax_r); } +int BMF_GetFontHeight(BMF_Font* font) +{ + if (!font) return -1; + return ((BMF_BitmapFont*)font)->GetFontHeight(); +} + int BMF_GetFontTexture(BMF_Font* font) { if (!font) return -1; return ((BMF_BitmapFont*)font)->GetTexture(); @@ -173,3 +179,8 @@ void BMF_DrawStringTexture(BMF_Font* font, char *string, float x, float y, float if (!font) return; ((BMF_BitmapFont*)font)->DrawStringTexture(string, x, y, z); } + +void BMF_DrawStringBuf(BMF_Font* font, char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h) { + if (!font) return; + ((BMF_BitmapFont*)font)->DrawStringBuf(str, posx, posy, col, buf, fbuf, w, h); +} diff --git a/intern/bmfont/intern/BMF_BitmapFont.cpp b/intern/bmfont/intern/BMF_BitmapFont.cpp index 8be4ff19a4f..99ded41007f 100644 --- a/intern/bmfont/intern/BMF_BitmapFont.cpp +++ b/intern/bmfont/intern/BMF_BitmapFont.cpp @@ -35,6 +35,11 @@ * Copyright (C) 2001 NaN Technologies B.V. */ + +#include <stdio.h> + + + #include <string.h> #ifdef HAVE_CONFIG_H @@ -115,6 +120,11 @@ void BMF_BitmapFont::GetFontBoundingBox(int & xMin, int & yMin, int & xMax, int yMax = m_fontData->ymax; } +int BMF_BitmapFont::GetFontHeight( void ) +{ + return m_fontData->ymax - m_fontData->ymin; +} + void BMF_BitmapFont::GetStringBoundingBox(char* str, float*llx, float *lly, float *urx, float *ury) { unsigned char c; @@ -229,3 +239,83 @@ void BMF_BitmapFont::DrawStringTexture(char *str, float x, float y, float z) } glEnd(); } + +#define FTOCHAR(val) val<=0.0f?0: (val>=1.0f?255: (char)(255.0f*val)) + + +void BMF_BitmapFont::DrawStringBuf(char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h) +{ + int x, y; + + if (buf==0 && fbuf==0) + return; + + /*offset for font*/ + posx -= m_fontData->xmin; + posy -= m_fontData->ymin; + + if (buf) { + unsigned char colch[3]; + unsigned char *max, *pixel; + unsigned char c; + + for (x=0; x<3; x++) { + colch[x] = FTOCHAR(col[x]); + } + + max = buf + (4 * (w * h)); + while ((c = (unsigned char) *str++)) { + BMF_CharData & cd = m_fontData->chars[c]; + if (cd.data_offset != -1) { + for (y = 0; y < cd.height; y++) { + unsigned char* chrRow = &m_fontData->bitmap_data[cd.data_offset + ((cd.width+7)/8)*y]; + for (x = cd.xorig; x < cd.width; x++) { + pixel = buf + 4 * (((posy + y) * w) + (posx + x)); + if ((pixel < max) && (pixel > buf)) { + int byteIdx = x/8; + int bitIdx = 7 - (x%8); + + if (chrRow[byteIdx]&(1<<bitIdx)) { + pixel[0] = colch[0]; + pixel[1] = colch[1]; + pixel[2] = colch[2]; + } + } + } + } + } + posx += cd.advance; + } + } + + if (fbuf) { + float *pixel, *max; + unsigned char c; + int x, y; + + max = fbuf + (4 * (w * h)); + + while ((c = (unsigned char) *str++)) { + BMF_CharData & cd = m_fontData->chars[c]; + if (cd.data_offset != -1) { + for (y = 0; y < cd.height; y++) { + unsigned char* chrRow = &m_fontData->bitmap_data[cd.data_offset + ((cd.width+7)/8)*y]; + for (x = cd.xorig; x < cd.width; x++) { + pixel = fbuf + 4 * (((posy + y - cd.yorig) * w) + (posx + x)); + if ((pixel < max) && (pixel > fbuf)) { + int byteIdx = x/8; + int bitIdx = 7 - (x%8); + + if (chrRow[byteIdx]&(1<<bitIdx)) { + pixel[0] = col[0]; + pixel[1] = col[1]; + pixel[2] = col[2]; + } + } + } + } + } + posx += cd.advance; + } + } +} diff --git a/intern/bmfont/intern/BMF_BitmapFont.h b/intern/bmfont/intern/BMF_BitmapFont.h index e8e0abc0561..986de2bb399 100644 --- a/intern/bmfont/intern/BMF_BitmapFont.h +++ b/intern/bmfont/intern/BMF_BitmapFont.h @@ -79,6 +79,11 @@ public: void GetFontBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax); /** + * Return the bounding box height of the font. + */ + int GetFontHeight(void); + + /** * Returns the bounding box of a string of characters. * @param font The font to use. * @param str The string. @@ -113,6 +118,21 @@ public: */ void DrawStringTexture(char* string, float x, float y, float z); + /** + * Draw the given @a string at the point @a xpos, @a ypos using + * char and float buffers. + * + * @param string The c-string to draw. + * @param xpos The x coordinate to start drawing at. + * @param ypos The y coordinate to start drawing at. + * @param col The forground color. + * @param buf Unsigned char image buffer, when NULL to not operate on it. + * @param fbuf float image buffer, when NULL to not operate on it. + * @param w image buffer width. + * @param h image buffer height. + */ + void DrawStringBuf(char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h); + protected: /** Pointer to the font data. */ BMF_FontData* m_fontData; |