Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/scaling.c
| Show First 20 Lines • Show All 1,544 Lines • ▼ Show 20 Lines | static void scalefast_Z_ImBuf(ImBuf *ibuf, int newx, int newy) | ||||
| if (_newzbuf_float) { | if (_newzbuf_float) { | ||||
| IMB_freezbuffloatImBuf(ibuf); | IMB_freezbuffloatImBuf(ibuf); | ||||
| ibuf->mall |= IB_zbuffloat; | ibuf->mall |= IB_zbuffloat; | ||||
| ibuf->zbuf_float = _newzbuf_float; | ibuf->zbuf_float = _newzbuf_float; | ||||
| } | } | ||||
| } | } | ||||
| struct ImBuf *IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy) | /** | ||||
| * Return true if \a ibuf is modified. | |||||
| */ | |||||
| bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy) | |||||
| { | { | ||||
| if (ibuf == NULL) return (NULL); | if (ibuf == NULL) return false; | ||||
| if (ibuf->rect == NULL && ibuf->rect_float == NULL) return (ibuf); | if (ibuf->rect == NULL && ibuf->rect_float == NULL) return false; | ||||
| if (newx == ibuf->x && newy == ibuf->y) { return ibuf; } | if (newx == ibuf->x && newy == ibuf->y) { | ||||
| return false; | |||||
| } | |||||
| /* scaleup / scaledown functions below change ibuf->x and ibuf->y | /* scaleup / scaledown functions below change ibuf->x and ibuf->y | ||||
| * so we first scale the Z-buffer (if any) */ | * so we first scale the Z-buffer (if any) */ | ||||
| scalefast_Z_ImBuf(ibuf, newx, newy); | scalefast_Z_ImBuf(ibuf, newx, newy); | ||||
| /* try to scale common cases in a fast way */ | /* try to scale common cases in a fast way */ | ||||
| /* disabled, quality loss is unacceptable, see report #18609 (ton) */ | /* disabled, quality loss is unacceptable, see report #18609 (ton) */ | ||||
| if (0 && q_scale_linear_interpolation(ibuf, newx, newy)) { | if (0 && q_scale_linear_interpolation(ibuf, newx, newy)) { | ||||
| return ibuf; | return true; | ||||
| } | } | ||||
| if (newx && (newx < ibuf->x)) scaledownx(ibuf, newx); | if (newx && (newx < ibuf->x)) scaledownx(ibuf, newx); | ||||
| if (newy && (newy < ibuf->y)) scaledowny(ibuf, newy); | if (newy && (newy < ibuf->y)) scaledowny(ibuf, newy); | ||||
| if (newx && (newx > ibuf->x)) scaleupx(ibuf, newx); | if (newx && (newx > ibuf->x)) scaleupx(ibuf, newx); | ||||
| if (newy && (newy > ibuf->y)) scaleupy(ibuf, newy); | if (newy && (newy > ibuf->y)) scaleupy(ibuf, newy); | ||||
| return(ibuf); | return true; | ||||
| } | } | ||||
| struct imbufRGBA { | struct imbufRGBA { | ||||
| float r, g, b, a; | float r, g, b, a; | ||||
| }; | }; | ||||
| struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy) | /** | ||||
| * Return true if \a ibuf is modified. | |||||
| */ | |||||
| bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy) | |||||
| { | { | ||||
| unsigned int *rect, *_newrect, *newrect; | unsigned int *rect, *_newrect, *newrect; | ||||
| struct imbufRGBA *rectf, *_newrectf, *newrectf; | struct imbufRGBA *rectf, *_newrectf, *newrectf; | ||||
| int x, y; | int x, y; | ||||
| bool do_float = false, do_rect = false; | bool do_float = false, do_rect = false; | ||||
| size_t ofsx, ofsy, stepx, stepy; | size_t ofsx, ofsy, stepx, stepy; | ||||
| rect = NULL; _newrect = NULL; newrect = NULL; | rect = NULL; _newrect = NULL; newrect = NULL; | ||||
| rectf = NULL; _newrectf = NULL; newrectf = NULL; | rectf = NULL; _newrectf = NULL; newrectf = NULL; | ||||
| if (ibuf == NULL) return(NULL); | if (ibuf == NULL) return false; | ||||
| if (ibuf->rect) do_rect = true; | if (ibuf->rect) do_rect = true; | ||||
| if (ibuf->rect_float) do_float = true; | if (ibuf->rect_float) do_float = true; | ||||
| if (do_rect == false && do_float == false) return(ibuf); | if (do_rect == false && do_float == false) return false; | ||||
| if (newx == ibuf->x && newy == ibuf->y) return(ibuf); | if (newx == ibuf->x && newy == ibuf->y) return false; | ||||
| if (do_rect) { | if (do_rect) { | ||||
| _newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf"); | _newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf"); | ||||
| if (_newrect == NULL) return(ibuf); | if (_newrect == NULL) return false; | ||||
| newrect = _newrect; | newrect = _newrect; | ||||
| } | } | ||||
| if (do_float) { | if (do_float) { | ||||
| _newrectf = MEM_mallocN(newx * newy * sizeof(float) * 4, "scalefastimbuf f"); | _newrectf = MEM_mallocN(newx * newy * sizeof(float) * 4, "scalefastimbuf f"); | ||||
| if (_newrectf == NULL) { | if (_newrectf == NULL) { | ||||
| if (_newrect) MEM_freeN(_newrect); | if (_newrect) MEM_freeN(_newrect); | ||||
| return(ibuf); | return false; | ||||
| } | } | ||||
| newrectf = _newrectf; | newrectf = _newrectf; | ||||
| } | } | ||||
| stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5; | stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5; | ||||
| stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; | stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; | ||||
| ofsy = 32768; | ofsy = 32768; | ||||
| Show All 19 Lines | for (y = newy; y > 0; y--, ofsy += stepy) { | ||||
| } | } | ||||
| } | } | ||||
| if (do_rect) { | if (do_rect) { | ||||
| imb_freerectImBuf(ibuf); | imb_freerectImBuf(ibuf); | ||||
| ibuf->mall |= IB_rect; | ibuf->mall |= IB_rect; | ||||
| ibuf->rect = _newrect; | ibuf->rect = _newrect; | ||||
| } | } | ||||
| if (do_float) { | if (do_float) { | ||||
| imb_freerectfloatImBuf(ibuf); | imb_freerectfloatImBuf(ibuf); | ||||
| ibuf->mall |= IB_rectfloat; | ibuf->mall |= IB_rectfloat; | ||||
| ibuf->rect_float = (float *)_newrectf; | ibuf->rect_float = (float *)_newrectf; | ||||
| } | } | ||||
| scalefast_Z_ImBuf(ibuf, newx, newy); | scalefast_Z_ImBuf(ibuf, newx, newy); | ||||
| ibuf->x = newx; | ibuf->x = newx; | ||||
| ibuf->y = newy; | ibuf->y = newy; | ||||
| return(ibuf); | return true; | ||||
| } | } | ||||
| /* ******** threaded scaling ******** */ | /* ******** threaded scaling ******** */ | ||||
| typedef struct ScaleTreadInitData { | typedef struct ScaleTreadInitData { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| unsigned int newx; | unsigned int newx; | ||||
| ▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines | |||||