cctw  0.2.1
Macros | Functions
cctwtcltiff.cpp File Reference
#include <assert.h>
#include <inttypes.h>
#include <iostream>
#include <stdlib.h>
#include <tiffio.h>
#include <tiffio.hxx>
#include <tcl.h>
#include "cctwtcltiff.h"
Include dependency graph for cctwtcltiff.cpp:

Go to the source code of this file.

Macros

#define UNUSED   __attribute__((unused))
 

Functions

static bool tiff_read (char *filename, void **output, uint32 *output_length)
 
int Cctwtcltiff_Read_Cmd (UNUSED ClientData clientData, UNUSED Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 

Macro Definition Documentation

#define UNUSED   __attribute__((unused))

Definition at line 22 of file cctwtcltiff.cpp.

Function Documentation

int Cctwtcltiff_Read_Cmd ( UNUSED ClientData  clientData,
UNUSED Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Definition at line 52 of file cctwtcltiff.cpp.

References tiff_read().

55 {
56  assert(objc == 4);
57 
58  char *filename = Tcl_GetString(objv[1]);
59  Tcl_Obj *pointer = objv[2];
60  Tcl_Obj *length = objv[3];
61 
62  void *output;
63  uint32 bytes;
64  bool rc = tiff_read(filename, &output, &bytes);
65  if (!rc)
66  return TCL_ERROR;
67 
68  Tcl_ObjSetVar2(interp, pointer, NULL, Tcl_NewLongObj((long)output), 0);
69  Tcl_ObjSetVar2(interp, length, NULL, Tcl_NewIntObj((int)bytes), 0);
70 
71  return TCL_OK;
72 }
static bool tiff_read(char *filename, void **output, uint32 *output_length)
Definition: cctwtcltiff.cpp:24
static bool tiff_read ( char *  filename,
void **  output,
uint32 *  output_length 
)
static

Definition at line 24 of file cctwtcltiff.cpp.

Referenced by Cctwtcltiff_Read_Cmd().

26 {
27  TIFF *tif = TIFFOpen(filename, "r");
28  if (tif == NULL)
29  return false;
30 
31  int width, height;
32 
33  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
34  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
35  cout << "wh: " << width << " " << height << endl;
36 
37  int npixels = width * height;
38  int length = npixels * sizeof (uint32);
39  uint32* raster = (uint32*) malloc(length);
40  assert(raster != NULL);
41 
42  int rc = TIFFReadRGBAImage(tif, width, height, raster, 0);
43  assert(rc == 1);
44 
45  TIFFClose(tif);
46 
47  *output = raster;
48  *output_length = length;
49  return true;
50 }