tioga 1.6 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Tioga_README +35 -10
  2. data/split/Dvector/dvector.c +264 -22
  3. data/split/Dvector/lib/Dvector_extras.rb +30 -2
  4. data/split/Flate/extconf.rb +1 -1
  5. data/split/Function/function.c +112 -2
  6. data/split/Tioga/figures.c +76 -77
  7. data/split/Tioga/figures.h +375 -490
  8. data/split/Tioga/generic.c +254 -0
  9. data/split/Tioga/generic.h +236 -0
  10. data/split/Tioga/init.c +434 -320
  11. data/split/Tioga/lib/Creating_Paths.rb +11 -1
  12. data/split/Tioga/lib/FigMkr.rb +263 -65
  13. data/split/Tioga/lib/Legends.rb +4 -2
  14. data/split/Tioga/lib/Markers.rb +3 -2
  15. data/split/Tioga/lib/Special_Paths.rb +22 -23
  16. data/split/Tioga/lib/TeX_Text.rb +79 -1
  17. data/split/Tioga/lib/TexPreamble.rb +14 -0
  18. data/split/Tioga/lib/Utils.rb +5 -1
  19. data/split/Tioga/pdfs.h +7 -45
  20. data/split/Tioga/{axes.c → shared/axes.c} +210 -197
  21. data/split/Tioga/{makers.c → shared/makers.c} +442 -211
  22. data/split/Tioga/{pdf_font_dicts.c → shared/pdf_font_dicts.c} +0 -0
  23. data/split/Tioga/shared/pdfcolor.c +628 -0
  24. data/split/Tioga/shared/pdfcoords.c +443 -0
  25. data/split/Tioga/{pdffile.c → shared/pdffile.c} +56 -52
  26. data/split/Tioga/{pdfimage.c → shared/pdfimage.c} +103 -211
  27. data/split/Tioga/shared/pdfpath.c +766 -0
  28. data/split/Tioga/{pdftext.c → shared/pdftext.c} +121 -99
  29. data/split/Tioga/shared/texout.c +524 -0
  30. data/split/Tioga/wrappers.c +489 -0
  31. data/split/Tioga/wrappers.h +259 -0
  32. data/split/extconf.rb +4 -0
  33. data/split/mkmf2.rb +12 -1
  34. data/tests/benchmark_dvector_reads.rb +112 -0
  35. data/tests/tc_Dvector.rb +35 -3
  36. data/tests/tc_Function.rb +32 -0
  37. metadata +65 -52
  38. data/split/Tioga/pdfcolor.c +0 -486
  39. data/split/Tioga/pdfcoords.c +0 -523
  40. data/split/Tioga/pdfpath.c +0 -913
  41. data/split/Tioga/texout.c +0 -380
@@ -99,14 +99,14 @@ static bool Is_monochrome(int obj_num)
99
99
  return false;
100
100
  }
101
101
 
102
- static void Write_Image_From_File(char *filename, int width, int height, char *out_info, int mask_obj_num)
102
+ static void Write_Image_From_File(char *filename, int width, int height, char *out_info, int mask_obj_num, int *ierr)
103
103
  {
104
104
  FILE *jpg = fopen(filename, "r");
105
- if (jpg == NULL) rb_raise(rb_eArgError, "Sorry: cannot open file for showing image (%s)\n", filename);
105
+ if (jpg == NULL) { RAISE_ERROR_s("Sorry: cannot open file for showing image (%s)\n", filename, ierr); return; }
106
106
  unsigned char *buff;
107
107
  int len, rd_len;
108
108
  int buff_len = 256000;
109
- buff = ALLOC_N(unsigned char, buff_len);
109
+ buff = ALLOC_N_unsigned_char(buff_len);
110
110
  len = 0;
111
111
  while ((rd_len = fread(buff, 1, buff_len, jpg)) == buff_len) len += buff_len;
112
112
  len += rd_len;
@@ -129,13 +129,13 @@ static void Write_Image_From_File(char *filename, int width, int height, char *o
129
129
  fclose(jpg);
130
130
  }
131
131
 
132
- void Write_JPG(JPG_Info *xo)
132
+ void Write_JPG(JPG_Info *xo, int *ierr)
133
133
  {
134
134
  Write_Image_From_File(xo->filename, xo->width, xo->height,
135
- "\t/Filter /DCTDecode\n\t/ColorSpace /DeviceRGB\n\t/BitsPerComponent 8\n", xo->mask_obj_num);
135
+ "\t/Filter /DCTDecode\n\t/ColorSpace /DeviceRGB\n\t/BitsPerComponent 8\n", xo->mask_obj_num, ierr);
136
136
  }
137
137
 
138
- void Write_Sampled(Sampled_Info *xo)
138
+ void Write_Sampled(Sampled_Info *xo, int *ierr)
139
139
  {
140
140
  fprintf(OF, "\n\t/Subtype /Image\n");
141
141
  fprintf(OF, "\t/Filter /FlateDecode\n\t/Interpolate %s\n", (xo->interpolate)? "true":"false");
@@ -176,8 +176,8 @@ void Write_Sampled(Sampled_Info *xo)
176
176
  fprintf(OF, "\t/BitsPerComponent 8\n");
177
177
  }
178
178
  if (xo->mask_obj_num > 0) {
179
- if (xo->image_type == MONO_IMAGE)
180
- rb_raise(rb_eArgError, "Sorry: monochrome images must not have masks");
179
+ if (xo->image_type == MONO_IMAGE) {
180
+ RAISE_ERROR("Sorry: monochrome images must not have masks", ierr); return; }
181
181
  if (!Is_monochrome(xo->mask_obj_num)) fprintf(OF, "\t/SMask %i 0 R\n", xo->mask_obj_num);
182
182
  else fprintf(OF, "\t/Mask %i 0 R\n", xo->mask_obj_num);
183
183
  }
@@ -185,20 +185,21 @@ void Write_Sampled(Sampled_Info *xo)
185
185
  xo->value_mask_min <= 255 && xo->value_mask_max <= 255 && xo->value_mask_min <= xo->value_mask_max)
186
186
  fprintf(OF, "\t/Mask [%i %i]\n", xo->value_mask_min, xo->value_mask_max);
187
187
  new_len = (xo->length * 11)/10 + 100;
188
- buffer = ALLOC_N(unsigned char, new_len);
189
- if (flate_compress(buffer, &new_len, xo->image_data, xo->length) != FLATE_OK) {
188
+ buffer = ALLOC_N_unsigned_char(new_len);
189
+ if (do_flate_compress(buffer, &new_len, xo->image_data, xo->length) != FLATE_OK) {
190
190
  free(buffer);
191
- rb_raise(rb_eArgError, "Error compressing image data");
191
+ RAISE_ERROR("Error compressing image data", ierr);
192
+ return;
192
193
  }
193
194
  fprintf(OF, "\t/Length %li\n", new_len);
194
195
  fprintf(OF, "\t>>\nstream\n");
195
- if (fwrite(buffer, 1, new_len, OF) < new_len)
196
- rb_raise(rb_eArgError, "Error writing image data");
196
+ if (fwrite(buffer, 1, new_len, OF) < new_len) {
197
+ RAISE_ERROR("Error writing image data", ierr); return; }
197
198
  free(buffer);
198
199
  fprintf(OF, "\nendstream\nendobj\n");
199
200
  }
200
201
 
201
- void Create_Transform_from_Points( // transform maps (0,0), (1,0), and (0,1) to the given points
202
+ static void Create_Transform_from_Points( // transform maps (0,0), (1,0), and (0,1) to the given points
202
203
  double llx, double lly, double lrx, double lry, double ulx, double uly,
203
204
  double *a, double *b, double *c, double *d, double *e, double *f)
204
205
  {
@@ -206,25 +207,27 @@ void Create_Transform_from_Points( // transform maps (0,0), (1,0), and (0,1) to
206
207
  *a = lrx; *b = lry; *c = ulx; *d = uly;
207
208
  }
208
209
 
209
- void Get_Image_Dest(FM *p, VALUE image_destination, double *dest)
210
+ static void Get_Image_Dest(FM *p, OBJ_PTR image_destination, double *dest, int *ierr)
210
211
  {
211
- image_destination = rb_Array(image_destination);
212
- if (RARRAY(image_destination)->len != 6)
213
- rb_raise(rb_eArgError, "Sorry: invalid image destination array: must have 6 entries");
212
+ int len = Array_Len(image_destination,ierr);
213
+ if (*ierr != 0) return;
214
+ if (len != 6) {
215
+ RAISE_ERROR("Sorry: invalid image destination array: must have 6 entries", ierr); return; }
214
216
  int i;
215
217
  for (i = 0; i < 6; i++) {
216
- VALUE entry = rb_ary_entry(image_destination, i);
217
- entry = rb_Float(entry);
218
+ OBJ_PTR entry = Array_Entry(image_destination, i, ierr);
219
+ if (*ierr != 0) return;
218
220
  if (i % 2 == 0)
219
- dest[i] = convert_figure_to_output_x(p,NUM2DBL(entry));
221
+ dest[i] = convert_figure_to_output_x(p,Number_to_double(entry, ierr));
220
222
  else
221
- dest[i] = convert_figure_to_output_y(p,NUM2DBL(entry));
223
+ dest[i] = convert_figure_to_output_y(p,Number_to_double(entry, ierr));
224
+ if (*ierr != 0) return;
222
225
  }
223
226
  }
224
227
 
225
228
  static void Show_JPEG(FM *p, char *filename, int width, int height, double *dest, int subtype, int mask_obj_num)
226
229
  {
227
- JPG_Info *xo = ALLOC(JPG_Info);
230
+ JPG_Info *xo = (JPG_Info *)calloc(1,sizeof(JPG_Info));
228
231
  xo->xobj_subtype = subtype;
229
232
  double llx = dest[0], lly = dest[1], lrx = dest[2], lry = dest[3], ulx = dest[4], uly = dest[5];
230
233
  double a, b, c, d, e, f; // the transform to position the image
@@ -232,7 +235,7 @@ static void Show_JPEG(FM *p, char *filename, int width, int height, double *dest
232
235
  xobj_list = (XObject_Info *)xo;
233
236
  xo->xo_num = next_available_xo_number++;
234
237
  xo->obj_num = next_available_object_number++;
235
- xo->filename = ALLOC_N(char, strlen(filename)+1);
238
+ xo->filename = ALLOC_N_char(strlen(filename)+1);
236
239
  strcpy(xo->filename, filename);
237
240
  xo->width = width;
238
241
  xo->height = height;
@@ -245,112 +248,91 @@ static void Show_JPEG(FM *p, char *filename, int width, int height, double *dest
245
248
  update_bbox(p, lrx+ulx-llx, lry+uly-lly);
246
249
  }
247
250
 
248
- void c_show_jpg(FM *p, char *filename, int width, int height, double *dest, int mask_obj_num)
249
- {
250
- Show_JPEG(p, filename, width, height, dest, JPG_SUBTYPE, mask_obj_num);
251
- }
252
-
253
- VALUE FM_private_show_jpg(VALUE fmkr, VALUE filename, VALUE width, VALUE height, VALUE image_destination, VALUE mask_obj_num)
254
- {
251
+ void c_private_show_jpg(OBJ_PTR fmkr, FM *p, char *filename,
252
+ int width, int height, OBJ_PTR image_destination, int mask_obj_num, int *ierr) {
255
253
  double dest[6];
256
- FM *p = Get_FM(fmkr);
257
- if (constructing_path) rb_raise(rb_eArgError, "Sorry: must finish with current path before calling show_jpg");
258
- Get_Image_Dest(p, image_destination, dest);
259
- width = rb_Integer(width);
260
- height = rb_Integer(height);
261
- mask_obj_num = rb_Integer(mask_obj_num);
262
- filename = rb_String(filename);
263
- c_show_jpg(p, RSTRING_PTR(filename), NUM2INT(width), NUM2INT(height), dest, NUM2INT(mask_obj_num));
264
- return fmkr;
254
+ if (constructing_path) {
255
+ RAISE_ERROR("Sorry: must finish with current path before calling show_jpg", ierr); return; }
256
+ Get_Image_Dest(p, image_destination, dest, ierr);
257
+ if (*ierr != 0) return;
258
+ Show_JPEG(p, filename, width, height, dest, JPG_SUBTYPE, mask_obj_num);
265
259
  }
266
260
 
267
- VALUE c_private_create_image_data(FM *p, double **data, long num_cols, long num_rows,
261
+ OBJ_PTR c_private_create_image_data(OBJ_PTR fmkr, FM *p, OBJ_PTR table,
268
262
  int first_row, int last_row, int first_column, int last_column,
269
- double min_value, double max_value, int max_code, int if_below_range, int if_above_range)
263
+ double min_val, double max_val, int max_code, int if_below_range, int if_above_range, int *ierr)
270
264
  {
265
+ long num_cols, num_rows;
266
+ double **data = Table_Data_for_Read(table, &num_cols, &num_rows, ierr);
267
+ if (*ierr != 0) RETURN_NIL;
271
268
  if (first_column < 0) first_column += num_cols;
272
269
  if (first_column < 0 || first_column >= num_cols)
273
- rb_raise(rb_eArgError, "Sorry: invalid first_column specification (%i)", first_column);
270
+ RAISE_ERROR_i("Sorry: invalid first_column specification (%i)", first_column, ierr);
274
271
  if (last_column < 0) last_column += num_cols;
275
272
  if (last_column < 0 || last_column >= num_cols)
276
- rb_raise(rb_eArgError, "Sorry: invalid last_column specification (%i)", last_column);
273
+ RAISE_ERROR_i("Sorry: invalid last_column specification (%i)", last_column, ierr);
277
274
  if (first_row < 0) first_row += num_rows;
278
275
  if (first_row < 0 || first_row >= num_rows)
279
- rb_raise(rb_eArgError, "Sorry: invalid first_row specification (%i)", first_row);
276
+ RAISE_ERROR_i("Sorry: invalid first_row specification (%i)", first_row, ierr);
280
277
  if (last_row < 0) last_row += num_rows;
281
278
  if (last_row < 0 || last_row >= num_rows)
282
- rb_raise(rb_eArgError, "Sorry: invalid last_row specification (%i)", last_row);
283
- if (min_value >= max_value)
284
- rb_raise(rb_eArgError, "Sorry: invalid range specification: min %g max %g", min_value, max_value);
279
+ RAISE_ERROR_i("Sorry: invalid last_row specification (%i)", last_row, ierr);
280
+ if (min_val >= max_val)
281
+ RAISE_ERROR_gg("Sorry: invalid range specification: min %g max %g", min_val, max_val, ierr);
285
282
  if (max_code <= 0 || max_code > 255)
286
- rb_raise(rb_eArgError, "Sorry: invalid max_code specification (%i)", max_code);
283
+ RAISE_ERROR_i("Sorry: invalid max_code specification (%i)", max_code, ierr);
287
284
  if (if_below_range < 0 || if_below_range > 255)
288
- rb_raise(rb_eArgError, "Sorry: invalid if_below_range specification (%i)", if_below_range);
285
+ RAISE_ERROR_i("Sorry: invalid if_below_range specification (%i)", if_below_range, ierr);
289
286
  if (if_above_range < 0 || if_above_range > 255)
290
- rb_raise(rb_eArgError, "Sorry: invalid if_above_range specification (%i)", if_above_range);
287
+ RAISE_ERROR_i("Sorry: invalid if_above_range specification (%i)", if_above_range, ierr);
291
288
  int i, j, k, width = last_column - first_column + 1, height = last_row - first_row + 1;
292
289
  int sz = width * height;
293
- if (sz <= 0) rb_raise(rb_eArgError, "Sorry: invalid data specification: width (%i) height (%i)", width, height);
294
- char *buff = ALLOC_N(char, sz);
290
+ if (sz <= 0) RAISE_ERROR_ii("Sorry: invalid data specification: width (%i) height (%i)", width, height, ierr);
291
+ if (*ierr != 0) RETURN_NIL;
292
+ char *buff = ALLOC_N_char(sz);
295
293
  for (k = 0, i = first_row; i <= last_row; i++) {
296
294
  double *row = data[i];
297
295
  for (j = first_column; j <= last_column; j++) {
298
296
  double val = row[j];
299
- if (val < min_value) buff[k++] = if_below_range;
300
- else if (val > max_value) buff[k++] = if_above_range;
297
+ if (val < min_val) buff[k++] = if_below_range;
298
+ else if (val > max_val) buff[k++] = if_above_range;
301
299
  else {
302
- val = max_code * (val - min_value)/(max_value - min_value);
300
+ val = max_code * (val - min_val)/(max_val - min_val);
303
301
  buff[k++] = ROUND(val);
304
302
  }
305
303
  }
306
304
  }
307
- VALUE result = rb_str_new(buff, sz);
305
+ OBJ_PTR result = String_New(buff, sz);
308
306
  free(buff);
309
307
  return result;
310
308
  }
311
309
 
312
- VALUE FM_private_create_image_data(VALUE fmkr, VALUE data,
313
- VALUE first_row, VALUE last_row, VALUE first_column, VALUE last_column,
314
- VALUE min_value, VALUE max_value, VALUE max_code, VALUE if_below_range, VALUE if_above_range)
315
- {
316
- FM *p = Get_FM(fmkr);
317
- long num_cols, num_rows;
318
- double **ary = Dtable_Ptr(data, &num_cols, &num_rows);
319
- first_row = rb_Integer(first_row);
320
- last_row = rb_Integer(last_row);
321
- first_column = rb_Integer(first_column);
322
- last_column = rb_Integer(last_column);
323
- max_code = rb_Integer(max_code);
324
- if_below_range = rb_Integer(if_below_range);
325
- if_above_range = rb_Integer(if_above_range);
326
- min_value = rb_Float(min_value);
327
- max_value = rb_Float(max_value);
328
- return c_private_create_image_data(p, ary, num_cols, num_rows,
329
- NUM2INT(first_row), NUM2INT(last_row), NUM2INT(first_column), NUM2INT(last_column),
330
- NUM2DBL(min_value), NUM2DBL(max_value), NUM2INT(max_code), NUM2INT(if_below_range), NUM2INT(if_above_range));
331
- }
332
310
 
333
- static VALUE c_private_create_monochrome_image_data(FM *p, double **data, long num_cols, long num_rows,
311
+ OBJ_PTR c_private_create_monochrome_image_data(OBJ_PTR fmkr, FM *p, OBJ_PTR table,
334
312
  int first_row, int last_row, int first_column, int last_column,
335
- double boundary, bool reversed)
313
+ double boundary, bool reversed, int *ierr)
336
314
  {
315
+ long num_cols, num_rows;
316
+ double **data = Table_Data_for_Read(table, &num_cols, &num_rows, ierr);
317
+ if (*ierr != 0) RETURN_NIL;
337
318
  if (first_column < 0) first_column += num_cols;
338
319
  if (first_column < 0 || first_column >= num_cols)
339
- rb_raise(rb_eArgError, "Sorry: invalid first_column specification (%i)", first_column);
320
+ RAISE_ERROR_i("Sorry: invalid first_column specification (%i)", first_column, ierr);
340
321
  if (last_column < 0) last_column += num_cols;
341
322
  if (last_column < 0 || last_column >= num_cols)
342
- rb_raise(rb_eArgError, "Sorry: invalid last_column specification (%i)", last_column);
323
+ RAISE_ERROR_i("Sorry: invalid last_column specification (%i)", last_column, ierr);
343
324
  if (first_row < 0) first_row += num_rows;
344
325
  if (first_row < 0 || first_row >= num_rows)
345
- rb_raise(rb_eArgError, "Sorry: invalid first_row specification (%i)", first_row);
326
+ RAISE_ERROR_i("Sorry: invalid first_row specification (%i)", first_row, ierr);
346
327
  if (last_row < 0) last_row += num_rows;
347
328
  if (last_row < 0 || last_row >= num_rows)
348
- rb_raise(rb_eArgError, "Sorry: invalid last_row specification (%i)", last_row);
329
+ RAISE_ERROR_i("Sorry: invalid last_row specification (%i)", last_row, ierr);
349
330
  int i, j, k, width = last_column - first_column + 1, height = last_row - first_row + 1, bytes_per_row = (width+7)/8;
350
331
  int sz = bytes_per_row * 8 * height;
351
- if (sz <= 0) rb_raise(rb_eArgError, "Sorry: invalid data specification: width (%i) height (%i)", width, height);
332
+ if (sz <= 0) RAISE_ERROR_ii("Sorry: invalid data specification: width (%i) height (%i)", width, height, ierr);
333
+ if (*ierr != 0) RETURN_NIL;
352
334
  // to simplify the process, do it in two stages: first get the values and then pack the bits
353
- char *buff = ALLOC_N(char, sz);
335
+ char *buff = ALLOC_N_char(sz);
354
336
  for (k = 0, i = first_row; i <= last_row; i++) {
355
337
  double *row = data[i];
356
338
  for (j = first_column; j <= last_column; j++) {
@@ -362,7 +344,7 @@ static VALUE c_private_create_monochrome_image_data(FM *p, double **data, long n
362
344
  }
363
345
  }
364
346
  int num_bytes = (sz+7) >> 3;
365
- char *bits = ALLOC_N(char, num_bytes), c = 0;
347
+ char *bits = ALLOC_N_char(num_bytes), c = 0;
366
348
  int num_bits = num_bytes << 3;
367
349
  for (i = 0, k = -1; i < num_bits; i++) {
368
350
  int bit = (i < sz)? buff[i] : 0;
@@ -374,163 +356,73 @@ static VALUE c_private_create_monochrome_image_data(FM *p, double **data, long n
374
356
  }
375
357
  }
376
358
  bits[k] = c;
377
- VALUE result = rb_str_new(bits, num_bytes);
359
+ OBJ_PTR result = String_New(bits, num_bytes);
378
360
  free(bits); free(buff);
379
361
  return result;
380
362
  }
381
363
 
382
- VALUE FM_private_create_monochrome_image_data(VALUE fmkr, VALUE data,
383
- VALUE first_row, VALUE last_row, VALUE first_column, VALUE last_column,
384
- VALUE boundary, VALUE reverse)
385
- {
386
- FM *p = Get_FM(fmkr);
387
- long num_cols, num_rows;
388
- double **ary = Dtable_Ptr(data, &num_cols, &num_rows);
389
- first_row = rb_Integer(first_row);
390
- last_row = rb_Integer(last_row);
391
- first_column = rb_Integer(first_column);
392
- last_column = rb_Integer(last_column);
393
- boundary = rb_Float(boundary);
394
- return c_private_create_monochrome_image_data(p, ary, num_cols, num_rows,
395
- NUM2INT(first_row), NUM2INT(last_row), NUM2INT(first_column), NUM2INT(last_column),
396
- NUM2DBL(boundary), reverse != Qfalse);
397
- }
398
364
 
399
- int c_private_show_image(FM *p, int image_type, double *dest, bool interpolate, bool reversed, int w, int h, unsigned char* data, int len,
400
- int value_mask_min, int value_mask_max, int hival, unsigned char* lookup, int lookup_len, int mask_obj_num)
365
+ OBJ_PTR c_private_show_image(OBJ_PTR fmkr, FM *p, int image_type, double llx, double lly, double lrx, double lry,
366
+ double ulx, double uly, bool interpolate, bool reversed, int w, int h, unsigned char* data, long len,
367
+ OBJ_PTR mask_min, OBJ_PTR mask_max, OBJ_PTR hivalue, OBJ_PTR lookup_data, int mask_obj_num, int *ierr)
401
368
  {
402
- Sampled_Info *xo = ALLOC(Sampled_Info);
369
+ unsigned char *lookup=NULL;
370
+ int value_mask_min = 256, value_mask_max = 256, lookup_len=0, hival=0;
371
+ if (constructing_path) { RAISE_ERROR("Sorry: must finish with current path before calling show_image", ierr); RETURN_NIL; }
372
+ if (image_type == COLORMAP_IMAGE) {
373
+ value_mask_min = Number_to_int(mask_min, ierr);
374
+ value_mask_max = Number_to_int(mask_max, ierr);
375
+ hival = Number_to_int(hivalue, ierr);
376
+ lookup = (unsigned char *)(String_Ptr(lookup_data, ierr));
377
+ lookup_len = String_Len(lookup_data, ierr);
378
+ if (*ierr != 0) RETURN_NIL;
379
+ }
380
+
381
+ llx = convert_figure_to_output_x(p,llx);
382
+ lly = convert_figure_to_output_y(p,lly);
383
+ lrx = convert_figure_to_output_x(p,lrx);
384
+ lry = convert_figure_to_output_y(p,lry);
385
+ ulx = convert_figure_to_output_x(p,ulx);
386
+ uly = convert_figure_to_output_y(p,uly);
387
+
388
+ Sampled_Info *xo = (Sampled_Info *)calloc(1,sizeof(Sampled_Info));
403
389
  xo->xobj_subtype = SAMPLED_SUBTYPE;
404
- double llx = dest[0], lly = dest[1], lrx = dest[2], lry = dest[3], ulx = dest[4], uly = dest[5];
405
390
  double a, b, c, d, e, f; // the transform to position the image
406
391
  int ir, ic, id;
407
392
  xo->next = xobj_list;
408
393
  xobj_list = (XObject_Info *)xo;
409
394
  xo->xo_num = next_available_xo_number++;
410
395
  xo->obj_num = next_available_object_number++;
411
- xo->image_data = ALLOC_N(unsigned char, len);
396
+ xo->image_data = ALLOC_N_unsigned_char(len);
412
397
  xo->length = len;
413
398
  xo->interpolate = interpolate;
414
399
  xo->reversed = reversed;
415
- MEMCPY(xo->image_data, data, unsigned char, len);
400
+ memcpy(xo->image_data, data, len);
416
401
  xo->image_type = image_type;
417
402
  if (image_type != COLORMAP_IMAGE) xo->lookup = NULL;
418
403
  else {
419
- if ((hival+1)*3 > lookup_len)
420
- rb_raise(rb_eArgError, "Sorry: color space hival (%i) is too large for length of lookup table (%i)", hival, lookup_len);
404
+ if ((hival+1)*3 > lookup_len) {
405
+ RAISE_ERROR_ii("Sorry: color space hival (%i) is too large for length of lookup table (%i)", hival, lookup_len, ierr);
406
+ RETURN_NIL;
407
+ }
421
408
  xo->hival = hival;
422
409
  lookup_len = (hival+1) * 3;
423
- xo->lookup = ALLOC_N(unsigned char, lookup_len);
410
+ xo->lookup = ALLOC_N_unsigned_char(lookup_len);
424
411
  xo->lookup_len = lookup_len;
425
- MEMCPY(xo->lookup, lookup, unsigned char, lookup_len);
412
+ memcpy(xo->lookup, lookup, lookup_len);
426
413
  }
427
414
  xo->width = w;
428
- xo->height = h;
429
-
430
- if (0) {
431
- printf("len=%i w=%i h=%i\ndata\n\n", len, w, h);
432
- for (ir=0; ir<h; ir++) {
433
- for (ic=0; ic<w; ic++) {
434
- id = (int)data[ir*h+ic];
435
- printf("%3i ",id);
436
- }
437
- printf("\n");
438
- }
439
-
440
-
441
- printf("\n\nxo->image_data\n");
442
- for (ir=0; ir<h; ir++) {
443
- for (ic=0; ic<w; ic++) {
444
- id = (int)xo->image_data[ir*h+ic];
445
- printf("%3i ",id);
446
- }
447
- printf("\n\n");
448
- }
449
- }
450
-
451
-
415
+ xo->height = h;
452
416
  xo->value_mask_min = value_mask_min;
453
417
  xo->value_mask_max = value_mask_max;
454
418
  xo->mask_obj_num = mask_obj_num;
455
- if (mask_obj_num == -1) return xo->obj_num; // this image is being used as an opacity mask
419
+ if (mask_obj_num == -1) return Integer_New(xo->obj_num); // this image is being used as an opacity mask
456
420
  Create_Transform_from_Points(llx, lly, lrx, lry, ulx, uly, &a, &b, &c, &d, &e, &f);
457
421
  fprintf(TF, "q %0.2f %0.2f %0.2f %0.2f %0.2f %0.2f cm /XObj%i Do Q\n", a, b, c, d, e, f, xo->xo_num);
458
422
  update_bbox(p, llx, lly);
459
423
  update_bbox(p, lrx, lry);
460
424
  update_bbox(p, ulx, uly);
461
425
  update_bbox(p, lrx+ulx-llx, lry+uly-lly);
462
- return xo->obj_num;
463
- }
464
-
465
- static VALUE private_show_image(int image_type, VALUE fmkr, VALUE llx, VALUE lly, VALUE lrx, VALUE lry,
466
- VALUE ulx, VALUE uly, VALUE interpolate, VALUE reversed, VALUE w, VALUE h, VALUE data, VALUE value_mask_min, VALUE value_mask_max,
467
- VALUE hival, VALUE lookup, VALUE mask_obj_num)
468
- {
469
- double dest[6];
470
- unsigned char *lookup_str=NULL;
471
- int mask_min = 256, mask_max = 256, lookup_len=0, hivalue=0;
472
- FM *p = Get_FM(fmkr);
473
- if (constructing_path) rb_raise(rb_eArgError, "Sorry: must finish with current path before calling show_image");
474
- data = rb_String(data);
475
- llx = rb_Float(llx);
476
- lly = rb_Float(lly);
477
- lrx = rb_Float(lrx);
478
- lry = rb_Float(lry);
479
- ulx = rb_Float(ulx);
480
- uly = rb_Float(uly);
481
- w = rb_Integer(w);
482
- h = rb_Integer(h);
483
- mask_obj_num = rb_Integer(mask_obj_num);
484
- if (image_type == COLORMAP_IMAGE) {
485
- value_mask_min = rb_Integer(value_mask_min); mask_min = NUM2INT(value_mask_min);
486
- value_mask_max = rb_Integer(value_mask_max); mask_max = NUM2INT(value_mask_max);
487
- hival = rb_Integer(hival);
488
- hivalue = NUM2INT(hival);
489
- lookup = rb_String(lookup);
490
- lookup_str = (unsigned char *)(RSTRING_PTR(lookup));
491
- lookup_len = RSTRING_LEN(lookup);
492
- }
493
- dest[0] = convert_figure_to_output_x(p,NUM2DBL(llx));
494
- dest[1] = convert_figure_to_output_y(p,NUM2DBL(lly));
495
- dest[2] = convert_figure_to_output_x(p,NUM2DBL(lrx));
496
- dest[3] = convert_figure_to_output_y(p,NUM2DBL(lry));
497
- dest[4] = convert_figure_to_output_x(p,NUM2DBL(ulx));
498
- dest[5] = convert_figure_to_output_y(p,NUM2DBL(uly));
499
- int obj_num = c_private_show_image(p, image_type, dest, (interpolate != Qfalse), (reversed == Qtrue), NUM2INT(w), NUM2INT(h),
500
- (unsigned char *)RSTRING_PTR(data), RSTRING_LEN(data), mask_min, mask_max, hivalue, lookup_str, lookup_len, NUM2INT(mask_obj_num));
501
- return INT2FIX(obj_num);
502
- }
503
-
504
- VALUE FM_private_show_rgb_image(VALUE fmkr, VALUE llx, VALUE lly, VALUE lrx, VALUE lry,
505
- VALUE ulx, VALUE uly, VALUE interpolate, VALUE w, VALUE h, VALUE data, VALUE mask_obj_num)
506
- {
507
- return private_show_image(RGB_IMAGE, fmkr, llx, lly, lrx, lry, ulx, uly, interpolate, Qfalse, w, h, data, Qnil, Qnil, Qnil, Qnil, mask_obj_num);
508
- }
509
-
510
- VALUE FM_private_show_cmyk_image(VALUE fmkr, VALUE llx, VALUE lly, VALUE lrx, VALUE lry,
511
- VALUE ulx, VALUE uly, VALUE interpolate, VALUE w, VALUE h, VALUE data, VALUE mask_obj_num)
512
- {
513
- return private_show_image(CMYK_IMAGE, fmkr, llx, lly, lrx, lry, ulx, uly, interpolate, Qfalse, w, h, data, Qnil, Qnil, Qnil, Qnil, mask_obj_num);
514
- }
515
-
516
- VALUE FM_private_show_grayscale_image(VALUE fmkr, VALUE llx, VALUE lly, VALUE lrx, VALUE lry,
517
- VALUE ulx, VALUE uly, VALUE interpolate, VALUE w, VALUE h, VALUE data, VALUE mask_obj_num)
518
- {
519
- return private_show_image(GRAY_IMAGE, fmkr, llx, lly, lrx, lry, ulx, uly, interpolate, Qfalse, w, h, data, Qnil, Qnil, Qnil, Qnil, mask_obj_num);
520
- }
521
-
522
- VALUE FM_private_show_monochrome_image(VALUE fmkr, VALUE llx, VALUE lly, VALUE lrx, VALUE lry,
523
- VALUE ulx, VALUE uly, VALUE interpolate, VALUE reversed, VALUE w, VALUE h, VALUE data, VALUE mask_obj_num)
524
- {
525
- return private_show_image(MONO_IMAGE, fmkr, llx, lly, lrx, lry, ulx, uly, interpolate, reversed,
526
- w, h, data, Qnil, Qnil, Qnil, Qnil, mask_obj_num);
527
- }
528
-
529
- VALUE FM_private_show_image(VALUE fmkr, VALUE llx, VALUE lly, VALUE lrx, VALUE lry,
530
- VALUE ulx, VALUE uly, VALUE interpolate, VALUE w, VALUE h, VALUE data,
531
- VALUE value_mask_min, VALUE value_mask_max, VALUE hival, VALUE lookup, VALUE mask_obj_num)
532
- {
533
- return private_show_image(COLORMAP_IMAGE, fmkr, llx, lly, lrx, lry, ulx, uly, interpolate, Qfalse, w, h, data,
534
- value_mask_min, value_mask_max, hival, lookup, mask_obj_num);
426
+ return Integer_New(xo->obj_num);
535
427
  }
536
428