@@ -215,7 +215,7 @@ ImageBuffer *get_image(unsigned bid) {
215
215
}
216
216
217
217
void scaleImage (ImageBuffer* image, var_num_t scaling) {
218
- if (scaling == 1.0 || scaling <= 0.0 ) {
218
+ if (scaling == 1.0 || scaling <= 0.0 ) {
219
219
return ;
220
220
}
221
221
@@ -226,15 +226,16 @@ void scaleImage(ImageBuffer* image, var_num_t scaling) {
226
226
h = round ((var_num_t )image->_height * scaling);
227
227
228
228
uint8_t * scaledImage = (uint8_t *)malloc (w * h * 4 );
229
- if (!scaledImage) {
229
+ if (!scaledImage) {
230
230
err_throw (ERR_IMAGE_LOAD, " Failed to allocate RAM" );
231
+ return ;
231
232
}
232
233
233
234
uint32_t * image32bit = (uint32_t *)image->_image ;
234
235
uint32_t * scaledImage32bit = (uint32_t *)scaledImage;
235
236
236
- for (yy = 0 ; yy < h; yy++) {
237
- for (xx = 0 ; xx < w; xx++) {
237
+ for (yy = 0 ; yy < h; yy++) {
238
+ for (xx = 0 ; xx < w; xx++) {
238
239
offsetScaledImage = yy * w + xx;
239
240
offsetImage = floor ((var_num_t )yy / scaling) * image->_width + floor ((var_num_t )xx / scaling);
240
241
scaledImage32bit[offsetScaledImage] = image32bit[offsetImage];
@@ -300,14 +301,15 @@ ImageBuffer *load_image(var_t *var) {
300
301
if (var->type == V_MAP) {
301
302
int bid = map_get_int (var, IMG_BID, -1 );
302
303
if (bid != -1 ) {
303
- if (scaling == 1.0 || scaling <= 0.0 ) {
304
+ if (scaling == 1.0 || scaling <= 0.0 ) {
304
305
result = get_image ((unsigned )bid);
305
306
} else {
306
307
ImageBuffer *inputImage = nullptr ;
307
308
inputImage = get_image ((unsigned )bid);
308
309
uint8_t * imageData = (uint8_t *)malloc (inputImage->_width * inputImage->_height * 4 );
309
- if (!imageData) {
310
+ if (!imageData) {
310
311
err_throw (ERR_IMAGE_LOAD, " Failed to allocate RAM" );
312
+ return result;
311
313
}
312
314
result = new ImageBuffer;
313
315
result->_bid = ++nextId;
@@ -325,8 +327,9 @@ ImageBuffer *load_image(var_t *var) {
325
327
int w = ABS (v_ubound (var, 1 ) - v_lbound (var, 1 )) + 1 ;
326
328
int size = w * h * 4 ;
327
329
auto imageData = (uint8_t *)malloc (size);
328
- if (!imageData) {
330
+ if (!imageData) {
329
331
err_throw (ERR_IMAGE_LOAD, " Failed to allocate RAM" );
332
+ return result;
330
333
}
331
334
for (int y = 0 ; y < h; y++) {
332
335
int yoffs = (y * w * 4 );
@@ -391,7 +394,7 @@ ImageBuffer *load_image(dev_file_t *filep) {
391
394
scaling = par_getnum ();
392
395
}
393
396
394
- if (scaling == 1.0 || scaling <= 0.0 ) {
397
+ if (scaling == 1.0 || scaling <= 0.0 ) {
395
398
List_each (ImageBuffer *, it, buffers) {
396
399
ImageBuffer *next = (*it);
397
400
if (next->_filename != nullptr && strcmp (next->_filename , filep->name ) == 0 ) {
@@ -751,6 +754,16 @@ void screen_dump() {
751
754
}
752
755
}
753
756
757
+ /*
758
+ * I = Image(file [,scale])
759
+ * I = Image(image [,scale])
760
+ * I = Image(x1,y1,x2,y2 [,scale])
761
+ * I = Image(pixmap [,scale])
762
+ * I = Image(array [,scale])
763
+ * scale > 1: upscale
764
+ * scale < 1: downscale
765
+ * scale <=0: don't scale
766
+ */
754
767
extern " C" void v_create_image (var_p_t var) {
755
768
var_t arg;
756
769
ImageBuffer *image = nullptr ;
0 commit comments